import gradio as gr
import random
xray_model = lambda diseases, img: {disease: random.random() for disease in diseases}
ct_model = lambda diseases, img: {disease: 0.1 for disease in diseases}
with gr.Blocks() as demo_1:
disease = gr.CheckboxGroup(
choices=["Covid", "Malaria", "Lung Cancer"], label="Disease to Scan For"
)
with gr.Tabs():
with gr.TabItem("Blocks2"):
with gr.Row():
xray_scan = gr.Image()
xray_results = gr.JSON()
xray_run = gr.Button("Run")
xray_run.click(
xray_model, inputs=[disease, xray_scan], outputs=[xray_results]
)
with gr.Blocks() as demo_2:
with gr.Row():
ct_scan = gr.Image()
ct_results = gr.JSON()
ct_run = gr.Button("Run")
ct_run.click(ct_model, inputs=[disease, ct_scan], outputs=ct_results)
with gr.Blocks() as demo:
gr.Markdown(
"""
# Detect Disease From Scan
With this model you can lorem ipsum
- ipsum 1
- ipsum 2
"""
)
disease = gr.CheckboxGroup(
choices=["Covid", "Malaria", "Lung Cancer"], label="Disease to Scan For"
)
with gr.Tabs():
with gr.TabItem("X-ray"):
demo_1.render()
with gr.TabItem("CT Scan"):
demo_2.render()
overall_probability = gr.Textbox()
if __name__ == "__main__":
print(demo.get_config_file())
demo.launch()
The design of Blocks does not support multiple Blocks defined outside the main Blocks scope. But this is needed for complex Blocks components as it will enable users to package their modules under smaller Blocks
We can potentially support it with a new design,
Usage example: