Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import gradio as gr
|
|
4 |
from gradio_client import Client, file
|
5 |
import time
|
6 |
import json
|
7 |
-
|
8 |
|
9 |
MODEL_NAME = "QWEN"
|
10 |
client_chat = os.environ.get("CHAT_URL")
|
@@ -55,9 +55,10 @@ def process_text(text_input, unit):
|
|
55 |
response = job.result()
|
56 |
print(response)
|
57 |
result = response[1][0][1]
|
58 |
-
return
|
59 |
|
60 |
def process_image(image_input, unit):
|
|
|
61 |
if image_input is not None:
|
62 |
image = str(image_input)
|
63 |
print(image)
|
@@ -82,22 +83,24 @@ def process_image(image_input, unit):
|
|
82 |
|
83 |
print(res0)
|
84 |
json_path = res0
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
return "等待分析..."
|
87 |
|
88 |
-
def
|
89 |
-
|
90 |
-
job = client.submit(
|
91 |
-
json_path,
|
92 |
-
fn_index=1
|
93 |
-
)
|
94 |
-
response = job.result(timeout=60)
|
95 |
-
with open(response, 'r') as f:
|
96 |
-
data = json.load(f)
|
97 |
-
print(data)
|
98 |
-
result = data[-1][1]
|
99 |
-
else:
|
100 |
-
return
|
101 |
|
102 |
|
103 |
def main(text_input="", image_input=None, unit=""):
|
@@ -115,13 +118,14 @@ with gr.Blocks(css=css, title="家庭医生AI助手") as iface:
|
|
115 |
"整形美容科", "营养科", "生殖中心", "麻醉医学科", "医学影像科", \
|
116 |
"骨科", "肿瘤科", "急诊科", "检验科"])
|
117 |
with gr.Row():
|
118 |
-
output_box = gr.Markdown(value=result, every=10, label="分析")
|
|
|
119 |
with gr.Row():
|
120 |
image_input = gr.Image(type="filepath", label="上传图片") # Create an image upload button
|
121 |
text_input = gr.Textbox(label="输入") # Create a text input box
|
122 |
with gr.Row():
|
123 |
submit_btn = gr.Button("🚀 确认") # Create a submit button
|
124 |
-
clear_btn = gr.ClearButton([image_input,text_input], value="🗑️ 清空") # Create a clear button
|
125 |
|
126 |
|
127 |
# Set up the event listeners
|
|
|
4 |
from gradio_client import Client, file
|
5 |
import time
|
6 |
import json
|
7 |
+
import threading
|
8 |
|
9 |
MODEL_NAME = "QWEN"
|
10 |
client_chat = os.environ.get("CHAT_URL")
|
|
|
55 |
response = job.result()
|
56 |
print(response)
|
57 |
result = response[1][0][1]
|
58 |
+
return result
|
59 |
|
60 |
def process_image(image_input, unit):
|
61 |
+
global result, json_path
|
62 |
if image_input is not None:
|
63 |
image = str(image_input)
|
64 |
print(image)
|
|
|
83 |
|
84 |
print(res0)
|
85 |
json_path = res0
|
86 |
+
|
87 |
+
def update():
|
88 |
+
job = client.submit(
|
89 |
+
json_path,
|
90 |
+
fn_index=1
|
91 |
+
)
|
92 |
+
response = job.result(timeout=60)
|
93 |
+
with open(response, 'r') as f:
|
94 |
+
data = json.load(f)
|
95 |
+
print(data)
|
96 |
+
result = data[-1][1]
|
97 |
+
|
98 |
+
threading.Thread(target=update).start()
|
99 |
+
|
100 |
return "等待分析..."
|
101 |
|
102 |
+
def fetch_result():
|
103 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
|
106 |
def main(text_input="", image_input=None, unit=""):
|
|
|
118 |
"整形美容科", "营养科", "生殖中心", "麻醉医学科", "医学影像科", \
|
119 |
"骨科", "肿瘤科", "急诊科", "检验科"])
|
120 |
with gr.Row():
|
121 |
+
output_box = gr.Markdown(value=result, every=10, label="分析", fn=fetch_result)
|
122 |
+
output_box.change(update)
|
123 |
with gr.Row():
|
124 |
image_input = gr.Image(type="filepath", label="上传图片") # Create an image upload button
|
125 |
text_input = gr.Textbox(label="输入") # Create a text input box
|
126 |
with gr.Row():
|
127 |
submit_btn = gr.Button("🚀 确认") # Create a submit button
|
128 |
+
clear_btn = gr.ClearButton([output_box, image_input, text_input], value="🗑️ 清空") # Create a clear button
|
129 |
|
130 |
|
131 |
# Set up the event listeners
|