Update app.py
Browse files
app.py
CHANGED
@@ -40,6 +40,7 @@ footer {
|
|
40 |
|
41 |
LICENSE = '当前采用 ' + MODEL_NAME + ' 模型,请主动移除个人信息,注意隐私保护🔔'
|
42 |
json_path = ""
|
|
|
43 |
|
44 |
local_data = threading.local()
|
45 |
def init_data():
|
@@ -50,7 +51,7 @@ def init_data():
|
|
50 |
def process_text(text_input, unit):
|
51 |
init_data()
|
52 |
client = Client(client_chat)
|
53 |
-
print(client.view_api())
|
54 |
job = client.submit(
|
55 |
query=str(text_input),
|
56 |
history=None,
|
@@ -58,21 +59,21 @@ def process_text(text_input, unit):
|
|
58 |
api_name="/model_chat"
|
59 |
)
|
60 |
response = job.result()
|
61 |
-
|
|
|
62 |
return local_data.results
|
63 |
|
64 |
|
65 |
|
66 |
def process_image(image_input, unit):
|
67 |
init_data()
|
68 |
-
response = ""
|
69 |
if image_input is not None:
|
70 |
image = str(image_input)
|
71 |
print(image)
|
72 |
#with open(image_input, "rb") as f:
|
73 |
# base64_image = base64.b64encode(f.read()).decode("utf-8")
|
74 |
client = Client(client_vl)
|
75 |
-
print(client.view_api())
|
76 |
prompt = f" You are a experienced {unit} doctor AI assistant." + SYS_PROMPT + "Help me understand what is in this picture and analysis."
|
77 |
|
78 |
res5 = client.predict(
|
@@ -99,29 +100,32 @@ def process_image(image_input, unit):
|
|
99 |
response = job.result()
|
100 |
with open(response, 'r') as f:
|
101 |
data = json.load(f)
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
|
108 |
|
109 |
def fetch_result():
|
110 |
init_data()
|
111 |
-
|
|
|
|
|
112 |
|
113 |
def reset_result():
|
114 |
init_data()
|
115 |
print(local_data.results)
|
116 |
-
|
|
|
|
|
117 |
|
118 |
def main(text_input="", image_input=None, unit=""):
|
119 |
-
init_data()
|
120 |
reset_result()
|
121 |
if text_input and image_input is None:
|
122 |
-
process_text(text_input, unit)
|
123 |
elif image_input is not None:
|
124 |
-
process_image(image_input, unit)
|
125 |
|
126 |
with gr.Blocks(css=css, title="家庭医生AI助手", theme="soft") as iface:
|
127 |
with gr.Accordion(""):
|
|
|
40 |
|
41 |
LICENSE = '当前采用 ' + MODEL_NAME + ' 模型,请主动移除个人信息,注意隐私保护🔔'
|
42 |
json_path = ""
|
43 |
+
temp = ""
|
44 |
|
45 |
local_data = threading.local()
|
46 |
def init_data():
|
|
|
51 |
def process_text(text_input, unit):
|
52 |
init_data()
|
53 |
client = Client(client_chat)
|
54 |
+
# print(client.view_api())
|
55 |
job = client.submit(
|
56 |
query=str(text_input),
|
57 |
history=None,
|
|
|
59 |
api_name="/model_chat"
|
60 |
)
|
61 |
response = job.result()
|
62 |
+
temp = response[1][0][1]
|
63 |
+
local_data.results = temp
|
64 |
return local_data.results
|
65 |
|
66 |
|
67 |
|
68 |
def process_image(image_input, unit):
|
69 |
init_data()
|
|
|
70 |
if image_input is not None:
|
71 |
image = str(image_input)
|
72 |
print(image)
|
73 |
#with open(image_input, "rb") as f:
|
74 |
# base64_image = base64.b64encode(f.read()).decode("utf-8")
|
75 |
client = Client(client_vl)
|
76 |
+
# print(client.view_api())
|
77 |
prompt = f" You are a experienced {unit} doctor AI assistant." + SYS_PROMPT + "Help me understand what is in this picture and analysis."
|
78 |
|
79 |
res5 = client.predict(
|
|
|
100 |
response = job.result()
|
101 |
with open(response, 'r') as f:
|
102 |
data = json.load(f)
|
103 |
+
temp = data[-1][1]
|
104 |
+
|
105 |
+
t = threading.Thread(target=update)
|
106 |
+
t.start()
|
107 |
+
return local_data.results = "正在分析....."
|
108 |
|
109 |
|
110 |
def fetch_result():
|
111 |
init_data()
|
112 |
+
if local_data.results:
|
113 |
+
local_data.results = temp
|
114 |
+
return local_data.results
|
115 |
|
116 |
def reset_result():
|
117 |
init_data()
|
118 |
print(local_data.results)
|
119 |
+
temp = ""
|
120 |
+
json_path = ""
|
121 |
+
local_data.results = ""
|
122 |
|
123 |
def main(text_input="", image_input=None, unit=""):
|
|
|
124 |
reset_result()
|
125 |
if text_input and image_input is None:
|
126 |
+
return process_text(text_input, unit)
|
127 |
elif image_input is not None:
|
128 |
+
return process_image(image_input, unit)
|
129 |
|
130 |
with gr.Blocks(css=css, title="家庭医生AI助手", theme="soft") as iface:
|
131 |
with gr.Accordion(""):
|