mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-13 11:57:29 +08:00
blocks-tests
- implement a simple test to check blocks config generation
This commit is contained in:
parent
1a500bff43
commit
dcc9ba87c9
@ -43,4 +43,4 @@ with xray_blocks:
|
||||
overall_probability = gr.components.Textbox()
|
||||
|
||||
print(xray_blocks.get_config_file())
|
||||
xray_blocks.launch()
|
||||
#xray_blocks.launch()
|
||||
|
47
test/test_blocks.py
Normal file
47
test/test_blocks.py
Normal file
@ -0,0 +1,47 @@
|
||||
from .test_data.blocks_configs import XRAY_CONFIG
|
||||
import gradio as gr
|
||||
import random
|
||||
|
||||
|
||||
class TestBlocks:
|
||||
def test_xray(self):
|
||||
xray_model = lambda diseases, img: {disease: random.random() for disease in diseases}
|
||||
ct_model = lambda diseases, img: {disease: 0.1 for disease in diseases}
|
||||
|
||||
xray_blocks = gr.Blocks()
|
||||
|
||||
with xray_blocks:
|
||||
gr.components.Markdown(
|
||||
"""
|
||||
# Detect Disease From Scan
|
||||
With this model you can lorem ipsum
|
||||
- ipsum 1
|
||||
- ipsum 2
|
||||
"""
|
||||
)
|
||||
disease = gr.components.CheckboxGroup(
|
||||
choices=["Covid", "Malaria", "Lung Cancer"], label="Disease to Scan For"
|
||||
)
|
||||
|
||||
with gr.Tabs():
|
||||
with gr.TabItem("X-ray"):
|
||||
with gr.Row():
|
||||
xray_scan = gr.components.Image()
|
||||
xray_results = gr.components.JSON()
|
||||
xray_run = gr.Button(
|
||||
"Run", css={"background-color": "red", "--hover-color": "orange"}
|
||||
)
|
||||
xray_run.click(
|
||||
xray_model, inputs=[disease, xray_scan], outputs=xray_results
|
||||
)
|
||||
|
||||
with gr.TabItem("CT Scan"):
|
||||
with gr.Row():
|
||||
ct_scan = gr.components.Image()
|
||||
ct_results = gr.components.JSON()
|
||||
ct_run = gr.Button("Run")
|
||||
ct_run.click(ct_model, inputs=[disease, ct_scan], outputs=ct_results)
|
||||
|
||||
overall_probability = gr.components.Textbox()
|
||||
|
||||
assert XRAY_CONFIG == xray_blocks.get_config_file()
|
2
test/test_data/blocks_configs.py
Normal file
2
test/test_data/blocks_configs.py
Normal file
@ -0,0 +1,2 @@
|
||||
XRAY_CONFIG = {'mode': 'blocks', 'components': [{'id': 1, 'type': 'markdown', 'props': {'default_value': '<pre><code># Detect Disease From Scan\nWith this model you can lorem ipsum\n- ipsum 1\n- ipsum 2\n</code></pre>\n', 'name': 'markdown', 'label': None, 'css': {}}}, {'id': 2, 'type': 'checkboxgroup', 'props': {'choices': ['Covid', 'Malaria', 'Lung Cancer'], 'default_value': [], 'name': 'checkboxgroup', 'label': 'Disease to Scan For', 'css': {}}}, {'id': 3, 'type': 'tabs', 'props': {'css': {}}}, {'id': 4, 'type': 'tabitem', 'props': {'label': 'X-ray', 'css': {}}}, {'id': 5, 'type': 'tabitem', 'props': {'label': 'X-ray', 'css': {}}}, {'id': 6, 'type': 'row', 'props': {'type': 'row', 'css': {}}}, {'id': 7, 'type': 'image', 'props': {'image_mode': 'RGB', 'shape': None, 'source': 'upload', 'tool': 'editor', 'default_value': None, 'name': 'image', 'label': None, 'css': {}}}, {'id': 8, 'type': 'json', 'props': {'default_value': '""', 'name': 'json', 'label': None, 'css': {}}}, {'id': 9, 'type': 'button', 'props': {'default_value': 'Run', 'name': 'button', 'label': None, 'css': {'background-color': 'red', '--hover-color': 'orange'}}}, {'id': 10, 'type': 'tabitem', 'props': {'label': 'CT Scan', 'css': {}}}, {'id': 11, 'type': 'tabitem', 'props': {'label': 'CT Scan', 'css': {}}}, {'id': 12, 'type': 'row', 'props': {'type': 'row', 'css': {}}}, {'id': 13, 'type': 'image', 'props': {'image_mode': 'RGB', 'shape': None, 'source': 'upload', 'tool': 'editor', 'default_value': None, 'name': 'image', 'label': None, 'css': {}}}, {'id': 14, 'type': 'json', 'props': {'default_value': '""', 'name': 'json', 'label': None, 'css': {}}}, {'id': 15, 'type': 'button', 'props': {'default_value': 'Run', 'name': 'button', 'label': None, 'css': {}}}, {'id': 16, 'type': 'textbox', 'props': {'lines': 1, 'placeholder': None, 'default_value': '', 'name': 'textbox', 'label': None, 'css': {}}}], 'theme': 'default', 'layout': {'id': 0, 'children': [{'id': 1}, {'id': 2}, {'id': 3, 'children': [{'id': 5, 'children': [{'id': 6, 'children': [{'id': 7}, {'id': 8}]}, {'id': 9}]}, {'id': 5, 'children': [{'id': 6, 'children': [{'id': 7}, {'id': 8}]}, {'id': 9}]}, {'id': 11, 'children': [{'id': 12, 'children': [{'id': 13}, {'id': 14}]}, {'id': 15}]}, {'id': 11, 'children': [{'id': 12, 'children': [{'id': 13}, {'id': 14}]}, {'id': 15}]}]}, {'id': 16}]}, 'dependencies': [{'targets': [9], 'trigger': 'click', 'inputs': [2, 7], 'outputs': [8]}, {'targets': [15], 'trigger': 'click', 'inputs': [2, 13], 'outputs': [14]}]}
|
||||
|
Loading…
x
Reference in New Issue
Block a user