gradio

Форк
0
/
overwrite_xray_config.py 
100 строк · 2.8 Кб
1
import gradio as gr
2
import random
3
import json
4
import os
5

6
def fake_func():
7
    return "Hello There"
8

9
def xray_model(diseases, img):
10
    return {disease: random.random() for disease in diseases}
11

12
def ct_model(diseases, img):
13
    return {disease: 0.1 for disease in diseases}
14

15
with gr.Blocks() as demo:
16
    gr.Markdown(
17
        """
18
    # Detect Disease From Scan
19
    With this model you can lorem ipsum
20
    - ipsum 1
21
    - ipsum 2
22
    """
23
    )
24
    disease = gr.CheckboxGroup(
25
        choices=[["Covid", "Covid"], ["Malaria", "Malaria"], ["Lung Cancer", "Lung Cancer"]], label="Disease to Scan For"
26
    )
27

28
    with gr.Tabs():
29
        with gr.TabItem("X-ray"):
30
            with gr.Row():
31
                xray_scan = gr.Image()
32
                xray_results = gr.JSON()
33
            xray_run = gr.Button("Run")
34
            xray_run.click(
35
                xray_model, inputs=[disease, xray_scan], outputs=xray_results
36
            )
37

38
        with gr.TabItem("CT Scan"):
39
            with gr.Row():
40
                ct_scan = gr.Image()
41
                ct_results = gr.JSON()
42
            ct_run = gr.Button("Run")
43
            ct_run.click(
44
                ct_model, inputs=[disease, ct_scan], outputs=ct_results
45
            )
46
    textbox = gr.Textbox()
47

48

49
gr.context.Context.id = 100
50

51
with gr.Blocks() as demo2:
52
    gr.Markdown(
53
        """
54
    # Detect Disease From Scan
55
    With this model you can lorem ipsum
56
    - ipsum 1
57
    - ipsum 2
58
    """
59
    )
60
    disease = gr.CheckboxGroup(
61
        choices=[["Covid", "Covid"], ["Malaria", "Malaria"], ["Lung Cancer", "Lung Cancer"]], label="Disease to Scan For"
62
    )
63

64
    with gr.Tabs():
65
        with gr.TabItem("X-ray"):
66
            with gr.Row():
67
                xray_scan = gr.Image()
68
                xray_results = gr.JSON()
69
            xray_run = gr.Button("Run")
70
            xray_run.click(
71
                xray_model, inputs=[disease, xray_scan], outputs=xray_results
72
            )
73

74
        with gr.TabItem("CT Scan"):
75
            with gr.Row():
76
                ct_scan = gr.Image()
77
                ct_results = gr.JSON()
78
            ct_run = gr.Button("Run")
79
            ct_run.click(
80
                ct_model, inputs=[disease, ct_scan], outputs=ct_results
81
            )
82
    textbox = gr.Textbox()
83

84
with gr.Blocks() as demo3:
85
    demo.render()
86
    t = gr.Textbox()
87
    demo3.load(fake_func, [], [t])
88

89
config = demo.get_config_file()
90
config2 = demo2.get_config_file()
91
config3 = demo3.get_config_file()
92

93
json_file_path = "../test/test_files/xray_config.json"
94
json_file_path2 = "../test/test_files/xray_config_diff_ids.json"
95
json_file_path3 = "../test/test_files/xray_config_wrong.json"
96

97
for c, j in zip([config, config2, config3], [json_file_path, json_file_path2, json_file_path3]):
98
    assert os.path.exists(j), f"{j} does not exist"
99
    with open(j, "w") as fp:
100
        json.dump(c, fp, indent=2)
101

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.