orrinin commited on
Commit
7b2162d
·
verified ·
1 Parent(s): d5c34d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -41,6 +41,7 @@ LICENSE = '采用 ' + MODEL_NAME + ' 模型'
41
 
42
 
43
  result = "等待分析..."
 
44
 
45
  def process_text(text_input, unit):
46
  client = Client(client_chat)
@@ -80,19 +81,12 @@ def process_image(image_input, unit):
80
  )
81
 
82
  print(res0)
 
83
 
84
- job = client.submit(
85
- res0,
86
- fn_index=1
87
- )
88
- if job.done():
89
- response = job.result(timeout=60)
90
- with open(response, 'r') as f:
91
- data = json.load(f)
92
- print(data)
93
- result = data[-1][1]
94
  return "等待分析..."
95
-
 
 
96
 
97
  def main(text_input="", image_input=None, unit=""):
98
  if text_input and image_input is None:
@@ -110,6 +104,8 @@ with gr.Blocks(css=css, title="家庭医生AI助手") as iface:
110
  "骨科", "肿瘤科", "急诊科", "检验科"])
111
  with gr.Row():
112
  output_box = gr.Markdown(value=result, every=10, label="分析")
 
 
113
  with gr.Row():
114
  image_input = gr.Image(type="filepath", label="上传图片") # Create an image upload button
115
  text_input = gr.Textbox(label="输入") # Create a text input box
@@ -117,8 +113,22 @@ with gr.Blocks(css=css, title="家庭医生AI助手") as iface:
117
  submit_btn = gr.Button("🚀 确认") # Create a submit button
118
  clear_btn = gr.ClearButton([output_box,image_input,text_input], value="🗑️ 清空") # Create a clear button
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  # Set up the event listeners
121
- submit_btn.click(main, inputs=[text_input, image_input, unit], outputs=output_box)
122
  gr.Markdown(LICENSE)
123
 
124
  #gr.close_all()
 
41
 
42
 
43
  result = "等待分析..."
44
+ json_path = ""
45
 
46
  def process_text(text_input, unit):
47
  client = Client(client_chat)
 
81
  )
82
 
83
  print(res0)
84
+ json_path = res0
85
 
 
 
 
 
 
 
 
 
 
 
86
  return "等待分析..."
87
+
88
+
89
+
90
 
91
  def main(text_input="", image_input=None, unit=""):
92
  if text_input and image_input is None:
 
104
  "骨科", "肿瘤科", "急诊科", "检验科"])
105
  with gr.Row():
106
  output_box = gr.Markdown(value=result, every=10, label="分析")
107
+ if json_path != 0:
108
+ update(json_path)
109
  with gr.Row():
110
  image_input = gr.Image(type="filepath", label="上传图片") # Create an image upload button
111
  text_input = gr.Textbox(label="输入") # Create a text input box
 
113
  submit_btn = gr.Button("🚀 确认") # Create a submit button
114
  clear_btn = gr.ClearButton([output_box,image_input,text_input], value="🗑️ 清空") # Create a clear button
115
 
116
+ def update(json_path: str):
117
+ if json_path:
118
+ job = client.submit(
119
+ json_path,
120
+ fn_index=1
121
+ )
122
+ if job.done():
123
+ response = job.result(timeout=60)
124
+ with open(response, 'r') as f:
125
+ data = json.load(f)
126
+ print(data)
127
+ result = data[-1][1]
128
+ else:
129
+ return
130
  # Set up the event listeners
131
+ submit_btn.click(main, inputs=[text_input, image_input, unit], outputs=output_box).success(update(json_path))
132
  gr.Markdown(LICENSE)
133
 
134
  #gr.close_all()