Update app.py
Browse files
app.py
CHANGED
@@ -39,8 +39,7 @@ footer {
|
|
39 |
|
40 |
|
41 |
LICENSE = '当前采用 ' + MODEL_NAME + ' 模型,请主动移除个人信息,注意隐私保护🔔'
|
42 |
-
|
43 |
-
temp = ""
|
44 |
|
45 |
local_data = threading.local()
|
46 |
def init_data():
|
@@ -50,7 +49,6 @@ def init_data():
|
|
50 |
|
51 |
def process_text(text_input, unit):
|
52 |
init_data()
|
53 |
-
global temp
|
54 |
client = Client(client_chat)
|
55 |
# print(client.view_api())
|
56 |
job = client.submit(
|
@@ -60,13 +58,21 @@ def process_text(text_input, unit):
|
|
60 |
api_name="/model_chat"
|
61 |
)
|
62 |
response = job.result()
|
63 |
-
|
64 |
-
local_data.results = temp
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
-
|
68 |
|
69 |
-
def process_image(image_input, unit):
|
70 |
init_data()
|
71 |
if image_input is not None:
|
72 |
image = str(image_input)
|
@@ -91,48 +97,30 @@ def process_image(image_input, unit):
|
|
91 |
)
|
92 |
|
93 |
print(res0)
|
94 |
-
|
95 |
-
|
96 |
-
def update():
|
97 |
-
global temp
|
98 |
-
job = client.submit(
|
99 |
-
json_path,
|
100 |
-
fn_index=1
|
101 |
-
)
|
102 |
-
response = job.result()
|
103 |
-
with open(response, 'r') as f:
|
104 |
-
data = json.load(f)
|
105 |
-
temp = data[-1][1]
|
106 |
-
|
107 |
-
t = threading.Thread(target=update)
|
108 |
t.start()
|
109 |
local_data.results = "正在分析....."
|
110 |
|
111 |
-
|
112 |
def fetch_result():
|
113 |
init_data()
|
114 |
-
global temp
|
115 |
-
print(f'temp:{temp}')
|
116 |
-
print(f'local_data.results: {local_data.results}')
|
117 |
-
if local_data.results != temp :
|
118 |
-
local_data.results = temp
|
119 |
return local_data.results
|
120 |
|
121 |
def reset_result():
|
122 |
init_data()
|
123 |
print(local_data.results)
|
124 |
-
temp = ""
|
125 |
-
json_path = ""
|
126 |
local_data.results = ""
|
127 |
|
128 |
def main(text_input="", image_input=None, unit=""):
|
129 |
init_data()
|
130 |
reset_result()
|
|
|
131 |
if text_input and image_input is None:
|
132 |
process_text(text_input, unit)
|
133 |
elif image_input is not None:
|
134 |
-
process_image(image_input, unit)
|
135 |
return local_data.results
|
|
|
|
|
136 |
with gr.Blocks(css=css, title="家庭医生AI助手", theme="soft") as iface:
|
137 |
with gr.Accordion(""):
|
138 |
gr.Markdown(DESCRIPTION)
|
|
|
39 |
|
40 |
|
41 |
LICENSE = '当前采用 ' + MODEL_NAME + ' 模型,请主动移除个人信息,注意隐私保护🔔'
|
42 |
+
|
|
|
43 |
|
44 |
local_data = threading.local()
|
45 |
def init_data():
|
|
|
49 |
|
50 |
def process_text(text_input, unit):
|
51 |
init_data()
|
|
|
52 |
client = Client(client_chat)
|
53 |
# print(client.view_api())
|
54 |
job = client.submit(
|
|
|
58 |
api_name="/model_chat"
|
59 |
)
|
60 |
response = job.result()
|
61 |
+
local_data.results = response[1][0][1]
|
|
|
62 |
|
63 |
+
def update(json_path: str):
|
64 |
+
init_data()
|
65 |
+
job = client.submit(
|
66 |
+
json_path,
|
67 |
+
fn_index=1
|
68 |
+
)
|
69 |
+
response = job.result()
|
70 |
+
with open(response, 'r') as f:
|
71 |
+
data = json.load(f)
|
72 |
+
local_data.results = data[-1][1]
|
73 |
|
|
|
74 |
|
75 |
+
def process_image(image_input, unit, temp):
|
76 |
init_data()
|
77 |
if image_input is not None:
|
78 |
image = str(image_input)
|
|
|
97 |
)
|
98 |
|
99 |
print(res0)
|
100 |
+
t = threading.Thread(target=update, args=(res0))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
t.start()
|
102 |
local_data.results = "正在分析....."
|
103 |
|
|
|
104 |
def fetch_result():
|
105 |
init_data()
|
|
|
|
|
|
|
|
|
|
|
106 |
return local_data.results
|
107 |
|
108 |
def reset_result():
|
109 |
init_data()
|
110 |
print(local_data.results)
|
|
|
|
|
111 |
local_data.results = ""
|
112 |
|
113 |
def main(text_input="", image_input=None, unit=""):
|
114 |
init_data()
|
115 |
reset_result()
|
116 |
+
temp = ""
|
117 |
if text_input and image_input is None:
|
118 |
process_text(text_input, unit)
|
119 |
elif image_input is not None:
|
120 |
+
process_image(image_input, unit, temp)
|
121 |
return local_data.results
|
122 |
+
|
123 |
+
|
124 |
with gr.Blocks(css=css, title="家庭医生AI助手", theme="soft") as iface:
|
125 |
with gr.Accordion(""):
|
126 |
gr.Markdown(DESCRIPTION)
|