Update app.py
Browse files
app.py
CHANGED
@@ -40,12 +40,13 @@ footer {
|
|
40 |
|
41 |
LICENSE = '当前采用 ' + MODEL_NAME + ' 模型,请主动移除个人信息,注意隐私保护🔔'
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
46 |
|
47 |
def process_text(text_input, unit):
|
48 |
-
|
49 |
client = Client(client_chat)
|
50 |
print(client.view_api())
|
51 |
job = client.submit(
|
@@ -56,11 +57,11 @@ def process_text(text_input, unit):
|
|
56 |
)
|
57 |
response = job.result()
|
58 |
print(response)
|
59 |
-
|
60 |
|
61 |
|
62 |
def process_image(image_input, unit):
|
63 |
-
|
64 |
if image_input is not None:
|
65 |
image = str(image_input)
|
66 |
print(image)
|
@@ -84,37 +85,39 @@ def process_image(image_input, unit):
|
|
84 |
)
|
85 |
|
86 |
print(res0)
|
87 |
-
json_path = res0
|
88 |
|
89 |
def update():
|
90 |
-
|
91 |
job = client.submit(
|
92 |
-
json_path,
|
93 |
fn_index=1
|
94 |
)
|
95 |
response = job.result()
|
96 |
with open(response, 'r') as f:
|
97 |
data = json.load(f)
|
98 |
print(data)
|
99 |
-
|
100 |
-
|
101 |
threading.Thread(target=update).start()
|
102 |
|
103 |
|
104 |
def fetch_result():
|
105 |
-
|
|
|
106 |
|
107 |
def reset_result():
|
108 |
-
|
|
|
109 |
|
110 |
def main(text_input="", image_input=None, unit=""):
|
111 |
-
|
112 |
reset_result()
|
113 |
if text_input and image_input is None:
|
114 |
process_text(text_input, unit)
|
115 |
elif image_input is not None:
|
116 |
process_image(image_input, unit)
|
117 |
-
return result
|
118 |
|
119 |
with gr.Blocks(css=css, title="家庭医生AI助手", theme="soft") as iface:
|
120 |
with gr.Accordion(""):
|
@@ -126,7 +129,7 @@ with gr.Blocks(css=css, title="家庭医生AI助手", theme="soft") as iface:
|
|
126 |
"骨科", "肿瘤科", "急诊科", "检验科"])
|
127 |
|
128 |
with gr.Row():
|
129 |
-
output_box = gr.Markdown(value=result, every=10, label="分析")
|
130 |
with gr.Row():
|
131 |
image_input = gr.Image(type="filepath", label="上传图片") # Create an image upload button
|
132 |
text_input = gr.Textbox(label="输入") # Create a text input box
|
@@ -139,7 +142,6 @@ with gr.Blocks(css=css, title="家庭医生AI助手", theme="soft") as iface:
|
|
139 |
# Set up the event listeners
|
140 |
submit_btn.click(main, inputs=[text_input, image_input, unit], outputs=output_box)
|
141 |
fresh_btn.click(fn=fetch_result, outputs=output_box)
|
142 |
-
clear_btn.click(fn=reset_result)
|
143 |
|
144 |
|
145 |
gr.Markdown(LICENSE)
|
|
|
40 |
|
41 |
LICENSE = '当前采用 ' + MODEL_NAME + ' 模型,请主动移除个人信息,注意隐私保护🔔'
|
42 |
|
43 |
+
local_data = threading.local()
|
44 |
+
def init_data():
|
45 |
+
local_data.results = ""
|
46 |
+
local_data.json_path = ""
|
47 |
|
48 |
def process_text(text_input, unit):
|
49 |
+
init_data()
|
50 |
client = Client(client_chat)
|
51 |
print(client.view_api())
|
52 |
job = client.submit(
|
|
|
57 |
)
|
58 |
response = job.result()
|
59 |
print(response)
|
60 |
+
local_data.results = response[1][0][1]
|
61 |
|
62 |
|
63 |
def process_image(image_input, unit):
|
64 |
+
init_data()
|
65 |
if image_input is not None:
|
66 |
image = str(image_input)
|
67 |
print(image)
|
|
|
85 |
)
|
86 |
|
87 |
print(res0)
|
88 |
+
local_data.json_path = res0
|
89 |
|
90 |
def update():
|
91 |
+
init_data()
|
92 |
job = client.submit(
|
93 |
+
local_data.json_path,
|
94 |
fn_index=1
|
95 |
)
|
96 |
response = job.result()
|
97 |
with open(response, 'r') as f:
|
98 |
data = json.load(f)
|
99 |
print(data)
|
100 |
+
local_data.results = data[-1][1]
|
101 |
+
local_data.results = "正在分析....."
|
102 |
threading.Thread(target=update).start()
|
103 |
|
104 |
|
105 |
def fetch_result():
|
106 |
+
init_data()
|
107 |
+
return local_data.result
|
108 |
|
109 |
def reset_result():
|
110 |
+
init_data()
|
111 |
+
local_data.result = 0
|
112 |
|
113 |
def main(text_input="", image_input=None, unit=""):
|
114 |
+
init_data()
|
115 |
reset_result()
|
116 |
if text_input and image_input is None:
|
117 |
process_text(text_input, unit)
|
118 |
elif image_input is not None:
|
119 |
process_image(image_input, unit)
|
120 |
+
return local_data.result
|
121 |
|
122 |
with gr.Blocks(css=css, title="家庭医生AI助手", theme="soft") as iface:
|
123 |
with gr.Accordion(""):
|
|
|
129 |
"骨科", "肿瘤科", "急诊科", "检验科"])
|
130 |
|
131 |
with gr.Row():
|
132 |
+
output_box = gr.Markdown(value=local_data.result, every=10, label="分析")
|
133 |
with gr.Row():
|
134 |
image_input = gr.Image(type="filepath", label="上传图片") # Create an image upload button
|
135 |
text_input = gr.Textbox(label="输入") # Create a text input box
|
|
|
142 |
# Set up the event listeners
|
143 |
submit_btn.click(main, inputs=[text_input, image_input, unit], outputs=output_box)
|
144 |
fresh_btn.click(fn=fetch_result, outputs=output_box)
|
|
|
145 |
|
146 |
|
147 |
gr.Markdown(LICENSE)
|