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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
-
def
|
| 154 |
if password_input != os.environ.get("USER_KEY"):
|
| 155 |
-
return [(None, "Wrong password!")], conversation, user_input
|
| 156 |
-
client=
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
file = client.files.create(file=Path(user_in_file), purpose="file-extract")
|
| 161 |
completion = client.chat.completions.create(
|
| 162 |
model="qwen-long",
|
|
@@ -171,7 +375,7 @@ def predict(password_input, user_in_file):
|
|
| 171 |
},
|
| 172 |
{
|
| 173 |
'role': 'user',
|
| 174 |
-
'content': '����������ѯ����ר�ң�����Ҫ����ѯʦ����ѯ���ݽ��ж�������Ҫ������ѯʦ�Ļػ�����Ϊ�������Dz���ȷ�ġ�step by step������²��裺\n ����1-���Ķ����ϴ����ı��ļ���ȫ�����ݣ�ֱ�����һ���ַ� \n ����2-��ȫ����ժȡ�����ߵġ��ؼ��Է��ԡ�����Ҫ��ժ¼�ı�ǰ�벿�ֵķ��ԣ�����ѡ����������Ҫ�����۵�3-4������¼���Խ������һ����ѯʦ����Ļظ�����Ϊ����ѯʦ�Ļظ��� \n ����3-��Թؼ��Է��ԣ��������ʵġ������ػ����ݡ� \n ����4-�Աȡ������ػ����ݡ��͡���ѯʦ�Ļظ���������ÿ��ش�֣�0��Ϊ�붽���ػ�������ȫ��һ�£�10���붽���ػ�������ȫһ�£� \n ����5-����4
|
| 175 |
}
|
| 176 |
],
|
| 177 |
stream=True
|
|
@@ -200,20 +404,27 @@ with gr.Blocks(css="#chatbot{height:350px} .overflow-y-auto{height:600px}") as d
|
|
| 200 |
with gr.Column(scale=1, min_width=50):
|
| 201 |
user_in_file = gr.File(label="Upload File")
|
| 202 |
#submit_button = gr.Button("Submit")
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
complaint_button = gr.Button("Main Complaint")
|
| 208 |
-
|
| 209 |
highlight_button = gr.Button("Highlights")
|
| 210 |
plan_button = gr.Button("Follow-up Plan")
|
| 211 |
|
| 212 |
with gr.Column(scale=2):
|
| 213 |
-
system_in_txt = gr.Textbox(lines=
|
| 214 |
|
| 215 |
-
summary_button.click(fn=predict, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
#submit_button.click(predict, [system_in_txt, password_in_txt, user_in_file, user_in_txt, conversation], [chatbot, conversation, user_in_txt])
|
| 218 |
#reset_button.click(clear_history, [conversation], [chatbot, conversation], queue=False)
|
| 219 |
|
|
|
|
| 149 |
|
| 150 |
|
| 151 |
chat_api = ChatgptAPI()
|
| 152 |
+
client=OpenAI(
|
| 153 |
+
api_key=os.environ.get("TONGYI_API_KEY"), # �滻����ʵDashScope��API_KEY
|
| 154 |
+
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", # ��дDashScopebase_url
|
| 155 |
+
)
|
| 156 |
+
def predict_(password_input, user_in_file):
|
| 157 |
+
if password_input != os.environ.get("USER_KEY"):
|
| 158 |
+
return [(None, "Wrong password!")], conversation, user_input]
|
| 159 |
+
file = client.files.create(file=Path(user_in_file), purpose="file-extract")
|
| 160 |
+
completion = client.chat.completions.create(
|
| 161 |
+
model="qwen-long",
|
| 162 |
+
messages=[
|
| 163 |
+
{
|
| 164 |
+
'role': 'system',
|
| 165 |
+
'content': 'You are a helpful assistant.'
|
| 166 |
+
},
|
| 167 |
+
{
|
| 168 |
+
'role': 'system',
|
| 169 |
+
'content': f'fileid://{file.id}'
|
| 170 |
+
},
|
| 171 |
+
{
|
| 172 |
+
'role': 'user',
|
| 173 |
+
'content':
|
| 174 |
+
}
|
| 175 |
+
],
|
| 176 |
+
stream=True
|
| 177 |
+
)
|
| 178 |
+
history=""
|
| 179 |
+
for chunk in completion:
|
| 180 |
+
if chunk.choices[0].delta.content is not None:
|
| 181 |
+
print(chunk.choices[0].dict())
|
| 182 |
+
history += chunk.choices[0].delta.content
|
| 183 |
+
time.sleep(0.05)
|
| 184 |
+
yield history
|
| 185 |
+
def predict_(password_input, user_in_file):
|
| 186 |
+
if password_input != os.environ.get("USER_KEY"):
|
| 187 |
+
return [(None, "Wrong password!")], conversation, user_input]
|
| 188 |
+
file = client.files.create(file=Path(user_in_file), purpose="file-extract")
|
| 189 |
+
completion = client.chat.completions.create(
|
| 190 |
+
model="qwen-long",
|
| 191 |
+
messages=[
|
| 192 |
+
{
|
| 193 |
+
'role': 'system',
|
| 194 |
+
'content': 'You are a helpful assistant.'
|
| 195 |
+
},
|
| 196 |
+
{
|
| 197 |
+
'role': 'system',
|
| 198 |
+
'content': f'fileid://{file.id}'
|
| 199 |
+
},
|
| 200 |
+
{
|
| 201 |
+
'role': 'user',
|
| 202 |
+
'content':
|
| 203 |
+
}
|
| 204 |
+
],
|
| 205 |
+
stream=True
|
| 206 |
+
)
|
| 207 |
+
history=""
|
| 208 |
+
for chunk in completion:
|
| 209 |
+
if chunk.choices[0].delta.content is not None:
|
| 210 |
+
print(chunk.choices[0].dict())
|
| 211 |
+
history += chunk.choices[0].delta.content
|
| 212 |
+
time.sleep(0.05)
|
| 213 |
+
yield history
|
| 214 |
+
def predict_(password_input, user_in_file):
|
| 215 |
+
if password_input != os.environ.get("USER_KEY"):
|
| 216 |
+
return [(None, "Wrong password!")], conversation, user_input]
|
| 217 |
+
file = client.files.create(file=Path(user_in_file), purpose="file-extract")
|
| 218 |
+
completion = client.chat.completions.create(
|
| 219 |
+
model="qwen-long",
|
| 220 |
+
messages=[
|
| 221 |
+
{
|
| 222 |
+
'role': 'system',
|
| 223 |
+
'content': 'You are a helpful assistant.'
|
| 224 |
+
},
|
| 225 |
+
{
|
| 226 |
+
'role': 'system',
|
| 227 |
+
'content': f'fileid://{file.id}'
|
| 228 |
+
},
|
| 229 |
+
{
|
| 230 |
+
'role': 'user',
|
| 231 |
+
'content':
|
| 232 |
+
}
|
| 233 |
+
],
|
| 234 |
+
stream=True
|
| 235 |
+
)
|
| 236 |
+
history=""
|
| 237 |
+
for chunk in completion:
|
| 238 |
+
if chunk.choices[0].delta.content is not None:
|
| 239 |
+
print(chunk.choices[0].dict())
|
| 240 |
+
history += chunk.choices[0].delta.content
|
| 241 |
+
time.sleep(0.05)
|
| 242 |
+
yield history
|
| 243 |
+
def predict_(password_input, user_in_file):
|
| 244 |
+
if password_input != os.environ.get("USER_KEY"):
|
| 245 |
+
return [(None, "Wrong password!")], conversation, user_input]
|
| 246 |
+
file = client.files.create(file=Path(user_in_file), purpose="file-extract")
|
| 247 |
+
completion = client.chat.completions.create(
|
| 248 |
+
model="qwen-long",
|
| 249 |
+
messages=[
|
| 250 |
+
{
|
| 251 |
+
'role': 'system',
|
| 252 |
+
'content': 'You are a helpful assistant.'
|
| 253 |
+
},
|
| 254 |
+
{
|
| 255 |
+
'role': 'system',
|
| 256 |
+
'content': f'fileid://{file.id}'
|
| 257 |
+
},
|
| 258 |
+
{
|
| 259 |
+
'role': 'user',
|
| 260 |
+
'content':
|
| 261 |
+
}
|
| 262 |
+
],
|
| 263 |
+
stream=True
|
| 264 |
+
)
|
| 265 |
+
history=""
|
| 266 |
+
for chunk in completion:
|
| 267 |
+
if chunk.choices[0].delta.content is not None:
|
| 268 |
+
print(chunk.choices[0].dict())
|
| 269 |
+
history += chunk.choices[0].delta.content
|
| 270 |
+
time.sleep(0.05)
|
| 271 |
+
yield history
|
| 272 |
+
def predict_(password_input, user_in_file):
|
| 273 |
+
if password_input != os.environ.get("USER_KEY"):
|
| 274 |
+
return [(None, "Wrong password!")], conversation, user_input]
|
| 275 |
+
file = client.files.create(file=Path(user_in_file), purpose="file-extract")
|
| 276 |
+
completion = client.chat.completions.create(
|
| 277 |
+
model="qwen-long",
|
| 278 |
+
messages=[
|
| 279 |
+
{
|
| 280 |
+
'role': 'system',
|
| 281 |
+
'content': 'You are a helpful assistant.'
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
'role': 'system',
|
| 285 |
+
'content': f'fileid://{file.id}'
|
| 286 |
+
},
|
| 287 |
+
{
|
| 288 |
+
'role': 'user',
|
| 289 |
+
'content':
|
| 290 |
+
}
|
| 291 |
+
],
|
| 292 |
+
stream=True
|
| 293 |
+
)
|
| 294 |
+
history=""
|
| 295 |
+
for chunk in completion:
|
| 296 |
+
if chunk.choices[0].delta.content is not None:
|
| 297 |
+
print(chunk.choices[0].dict())
|
| 298 |
+
history += chunk.choices[0].delta.content
|
| 299 |
+
time.sleep(0.05)
|
| 300 |
+
yield history
|
| 301 |
+
def predict_(password_input, user_in_file):
|
| 302 |
+
if password_input != os.environ.get("USER_KEY"):
|
| 303 |
+
return [(None, "Wrong password!")], conversation, user_input]
|
| 304 |
+
file = client.files.create(file=Path(user_in_file), purpose="file-extract")
|
| 305 |
+
completion = client.chat.completions.create(
|
| 306 |
+
model="qwen-long",
|
| 307 |
+
messages=[
|
| 308 |
+
{
|
| 309 |
+
'role': 'system',
|
| 310 |
+
'content': 'You are a helpful assistant.'
|
| 311 |
+
},
|
| 312 |
+
{
|
| 313 |
+
'role': 'system',
|
| 314 |
+
'content': f'fileid://{file.id}'
|
| 315 |
+
},
|
| 316 |
+
{
|
| 317 |
+
'role': 'user',
|
| 318 |
+
'content':
|
| 319 |
+
}
|
| 320 |
+
],
|
| 321 |
+
stream=True
|
| 322 |
+
)
|
| 323 |
+
history=""
|
| 324 |
+
for chunk in completion:
|
| 325 |
+
if chunk.choices[0].delta.content is not None:
|
| 326 |
+
print(chunk.choices[0].dict())
|
| 327 |
+
history += chunk.choices[0].delta.content
|
| 328 |
+
time.sleep(0.05)
|
| 329 |
+
yield history
|
| 330 |
|
| 331 |
+
def predict_(password_input, user_in_file):
|
| 332 |
if password_input != os.environ.get("USER_KEY"):
|
| 333 |
+
return [(None, "Wrong password!")], conversation, user_input]
|
| 334 |
+
file = client.files.create(file=Path(user_in_file), purpose="file-extract")
|
| 335 |
+
completion = client.chat.completions.create(
|
| 336 |
+
model="qwen-long",
|
| 337 |
+
messages=[
|
| 338 |
+
{
|
| 339 |
+
'role': 'system',
|
| 340 |
+
'content': 'You are a helpful assistant.'
|
| 341 |
+
},
|
| 342 |
+
{
|
| 343 |
+
'role': 'system',
|
| 344 |
+
'content': f'fileid://{file.id}'
|
| 345 |
+
},
|
| 346 |
+
{
|
| 347 |
+
'role': 'user',
|
| 348 |
+
'content':
|
| 349 |
+
}
|
| 350 |
+
],
|
| 351 |
+
stream=True
|
| 352 |
)
|
| 353 |
+
history=""
|
| 354 |
+
for chunk in completion:
|
| 355 |
+
if chunk.choices[0].delta.content is not None:
|
| 356 |
+
print(chunk.choices[0].dict())
|
| 357 |
+
history += chunk.choices[0].delta.content
|
| 358 |
+
time.sleep(0.05)
|
| 359 |
+
yield history
|
| 360 |
+
|
| 361 |
+
def predict_highlight(password_input, user_in_file):
|
| 362 |
+
if password_input != os.environ.get("USER_KEY"):
|
| 363 |
+
return [(None, "Wrong password!")], conversation, user_input]
|
| 364 |
file = client.files.create(file=Path(user_in_file), purpose="file-extract")
|
| 365 |
completion = client.chat.completions.create(
|
| 366 |
model="qwen-long",
|
|
|
|
| 375 |
},
|
| 376 |
{
|
| 377 |
'role': 'user',
|
| 378 |
+
'content': '����������ѯ����ר�ң�����Ҫ����ѯʦ����ѯ���ݽ��ж�������Ҫ������ѯʦ�Ļػ�����Ϊ�������Dz���ȷ�ġ�step by step������²��裺\n ����1-���Ķ����ϴ����ı��ļ���ȫ�����ݣ�ֱ�����һ���ַ� \n ����2-��ȫ����ժȡ�����ߵġ��ؼ��Է��ԡ�����Ҫ��ժ¼�ı�ǰ�벿�ֵķ��ԣ�����ѡ����������Ҫ�����۵�3-4������¼���Խ������һ����ѯʦ����Ļظ�����Ϊ����ѯʦ�Ļظ��� \n ����3-��Թؼ��Է��ԣ��������ʵġ������ػ����ݡ� \n ����4-�Աȡ������ػ����ݡ��͡���ѯʦ�Ļظ���������ÿ��ش�֣�0��Ϊ�붽���ػ�������ȫ��һ�£�10���붽���ػ�������ȫһ�£� \n ����5-����4����ִ�в�������������¸�ʽ�����- �ؼ��Է���n��,\n - �����ߣ�,\n , - �����ػ�������, \n , - ��ѯʦ�Ļظ��� ,\n , - ���֣�x/10 \n ,- ��ԭ�� '
|
| 379 |
}
|
| 380 |
],
|
| 381 |
stream=True
|
|
|
|
| 404 |
with gr.Column(scale=1, min_width=50):
|
| 405 |
user_in_file = gr.File(label="Upload File")
|
| 406 |
#submit_button = gr.Button("Submit")
|
| 407 |
+
issue_button = gr.Button("Issue")
|
| 408 |
+
mindmap_button = gr.Button("Mindmap")
|
| 409 |
+
keywords_button = gr.Button("Keywords")
|
| 410 |
+
dynamics_button = gr.Button("Dynamics")
|
| 411 |
complaint_button = gr.Button("Main Complaint")
|
| 412 |
+
concept_button = gr.Button("Case Conceptualization")
|
| 413 |
highlight_button = gr.Button("Highlights")
|
| 414 |
plan_button = gr.Button("Follow-up Plan")
|
| 415 |
|
| 416 |
with gr.Column(scale=2):
|
| 417 |
+
system_in_txt = gr.Textbox(lines=30, label="Output Text:")
|
| 418 |
|
|
|
|
| 419 |
|
| 420 |
+
issue_button.click(fn=predict_issue, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
|
| 421 |
+
mindmap_button.click(fn=predict_mindmap, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
|
| 422 |
+
keywords_button.click(fn=predict_keywords, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
|
| 423 |
+
dynamics_button.click(fn=predict_dynamics, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
|
| 424 |
+
complaint_button.click(fn=predict_complaint, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
|
| 425 |
+
concept_button.click(fn=predict_concept, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
|
| 426 |
+
highlight_button.click(fn=predict_highlight, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
|
| 427 |
+
plan_button.click(fn=predict_plan, inputs=[password_in_txt, user_in_file], outputs=[system_in_txt])
|
| 428 |
#submit_button.click(predict, [system_in_txt, password_in_txt, user_in_file, user_in_txt, conversation], [chatbot, conversation, user_in_txt])
|
| 429 |
#reset_button.click(clear_history, [conversation], [chatbot, conversation], queue=False)
|
| 430 |
|