Update app.py
Browse files
app.py
CHANGED
|
@@ -206,8 +206,10 @@ AIMessage(content="I'm great thank you. How can I help you?")]
|
|
| 206 |
def Chat_Message(history, messages1):
|
| 207 |
|
| 208 |
message=HumanMessage(content=history[-1][0])
|
|
|
|
|
|
|
|
|
|
| 209 |
messages1.append(message)
|
| 210 |
-
|
| 211 |
if len(messages1) >= 8:
|
| 212 |
messages1 = messages1[-8:]
|
| 213 |
|
|
@@ -218,8 +220,7 @@ def Chat_Message(history, messages1):
|
|
| 218 |
start_index = error_message.find("Input validation error:")
|
| 219 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 220 |
if start_index != -1 and end_index != -1:
|
| 221 |
-
|
| 222 |
-
raise gr.Error(error_message[start_index:end_index+ len("and 4096 `max_new_tokens`")].strip()) from e
|
| 223 |
else:
|
| 224 |
raise gr.Error("Error occurred during response") from e
|
| 225 |
|
|
@@ -234,6 +235,8 @@ def Chat_Message(history, messages1):
|
|
| 234 |
def Internet_Search(history, messages2):
|
| 235 |
|
| 236 |
message=history[-1][0]
|
|
|
|
|
|
|
| 237 |
|
| 238 |
similar_docs = db.similarity_search(message, k=3)
|
| 239 |
|
|
@@ -250,7 +253,7 @@ def Internet_Search(history, messages2):
|
|
| 250 |
|
| 251 |
#If the query is not related to specific Search Content, engage in general conversation or provide relevant information from other sources.
|
| 252 |
"""
|
| 253 |
-
|
| 254 |
msg=HumanMessage(content=augmented_prompt)
|
| 255 |
messages2.append(msg)
|
| 256 |
|
|
@@ -264,8 +267,7 @@ def Internet_Search(history, messages2):
|
|
| 264 |
start_index = error_message.find("Input validation error:")
|
| 265 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 266 |
if start_index != -1 and end_index != -1:
|
| 267 |
-
|
| 268 |
-
raise gr.Error(error_message[start_index:end_index+ len("and 4096 `max_new_tokens`")].strip()) from e
|
| 269 |
else:
|
| 270 |
raise gr.Error("Error occurred during response") from e
|
| 271 |
|
|
@@ -280,6 +282,9 @@ def Internet_Search(history, messages2):
|
|
| 280 |
def Chart_Generator(history, messages3):
|
| 281 |
|
| 282 |
message = history[-1][0]
|
|
|
|
|
|
|
|
|
|
| 283 |
if '#chart' in message:
|
| 284 |
message = message.split('#chart', 1)[1].strip()
|
| 285 |
chart_url = f"https://quickchart.io/natural/{message}"
|
|
@@ -302,8 +307,7 @@ def Chart_Generator(history, messages3):
|
|
| 302 |
start_index = error_message.find("Input validation error:")
|
| 303 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 304 |
if start_index != -1 and end_index != -1:
|
| 305 |
-
|
| 306 |
-
raise gr.Error(error_message[start_index:end_index+ len("and 4096 `max_new_tokens`")].strip()) from e
|
| 307 |
else:
|
| 308 |
raise gr.Error("Error occurred during response") from e
|
| 309 |
|
|
@@ -327,8 +331,7 @@ def Chart_Generator(history, messages3):
|
|
| 327 |
start_index = error_message.find("Input validation error:")
|
| 328 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 329 |
if start_index != -1 and end_index != -1:
|
| 330 |
-
|
| 331 |
-
raise gr.Error(error_message[start_index:end_index+ len("and 4096 `max_new_tokens`")].strip()) from e
|
| 332 |
else:
|
| 333 |
raise gr.Error("Error occurred during response") from e
|
| 334 |
|
|
@@ -345,6 +348,8 @@ def Chart_Generator(history, messages3):
|
|
| 345 |
def Link_Scratch(history, messages4):
|
| 346 |
|
| 347 |
combined_message = history[-1][0]
|
|
|
|
|
|
|
| 348 |
|
| 349 |
link = ""
|
| 350 |
user_message = ""
|
|
@@ -386,8 +391,7 @@ def Link_Scratch(history, messages4):
|
|
| 386 |
start_index = error_message.find("Input validation error:")
|
| 387 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 388 |
if start_index != -1 and end_index != -1:
|
| 389 |
-
|
| 390 |
-
raise gr.Error(error_message[start_index:end_index+ len("and 4096 `max_new_tokens`")].strip()) from e
|
| 391 |
else:
|
| 392 |
raise gr.Error("Error occurred during response") from e
|
| 393 |
|
|
@@ -418,6 +422,8 @@ def display_file_name(file):
|
|
| 418 |
def File_Interact(history, filepath, messages5):
|
| 419 |
|
| 420 |
combined_message = history[-1][0]
|
|
|
|
|
|
|
| 421 |
|
| 422 |
link = ""
|
| 423 |
user_message = ""
|
|
@@ -455,8 +461,7 @@ def File_Interact(history, filepath, messages5):
|
|
| 455 |
start_index = error_message.find("Input validation error:")
|
| 456 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 457 |
if start_index != -1 and end_index != -1:
|
| 458 |
-
|
| 459 |
-
raise gr.Error(error_message[start_index:end_index+ len("and 4096 `max_new_tokens`")].strip()) from e
|
| 460 |
else:
|
| 461 |
raise gr.Error("Error occurred during response") from e
|
| 462 |
|
|
@@ -473,6 +478,8 @@ def File_Interact(history, filepath, messages5):
|
|
| 473 |
def Explore_WebSite(history, messages6):
|
| 474 |
|
| 475 |
message=history[-1][0]
|
|
|
|
|
|
|
| 476 |
|
| 477 |
links = [
|
| 478 |
'https://huggingface.co/mou3az'
|
|
@@ -504,8 +511,7 @@ def Explore_WebSite(history, messages6):
|
|
| 504 |
start_index = error_message.find("Input validation error:")
|
| 505 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 506 |
if start_index != -1 and end_index != -1:
|
| 507 |
-
|
| 508 |
-
raise gr.Error(error_message[start_index:end_index+ len("and 4096 `max_new_tokens`")].strip()) from e
|
| 509 |
else:
|
| 510 |
raise gr.Error("Error occurred during response") from e
|
| 511 |
|
|
|
|
| 206 |
def Chat_Message(history, messages1):
|
| 207 |
|
| 208 |
message=HumanMessage(content=history[-1][0])
|
| 209 |
+
if isinstance(messages1[-1], HumanMessage):
|
| 210 |
+
messages1=messages1[:-2]
|
| 211 |
+
|
| 212 |
messages1.append(message)
|
|
|
|
| 213 |
if len(messages1) >= 8:
|
| 214 |
messages1 = messages1[-8:]
|
| 215 |
|
|
|
|
| 220 |
start_index = error_message.find("Input validation error:")
|
| 221 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 222 |
if start_index != -1 and end_index != -1:
|
| 223 |
+
raise gr.Error(error_message[start_index:end_index].strip()) from e
|
|
|
|
| 224 |
else:
|
| 225 |
raise gr.Error("Error occurred during response") from e
|
| 226 |
|
|
|
|
| 235 |
def Internet_Search(history, messages2):
|
| 236 |
|
| 237 |
message=history[-1][0]
|
| 238 |
+
if isinstance(messages2[-1], HumanMessage):
|
| 239 |
+
messages2=messages2[:-2]
|
| 240 |
|
| 241 |
similar_docs = db.similarity_search(message, k=3)
|
| 242 |
|
|
|
|
| 253 |
|
| 254 |
#If the query is not related to specific Search Content, engage in general conversation or provide relevant information from other sources.
|
| 255 |
"""
|
| 256 |
+
|
| 257 |
msg=HumanMessage(content=augmented_prompt)
|
| 258 |
messages2.append(msg)
|
| 259 |
|
|
|
|
| 267 |
start_index = error_message.find("Input validation error:")
|
| 268 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 269 |
if start_index != -1 and end_index != -1:
|
| 270 |
+
raise gr.Error(error_message[start_index:end_index ].strip()) from e
|
|
|
|
| 271 |
else:
|
| 272 |
raise gr.Error("Error occurred during response") from e
|
| 273 |
|
|
|
|
| 282 |
def Chart_Generator(history, messages3):
|
| 283 |
|
| 284 |
message = history[-1][0]
|
| 285 |
+
if isinstance(messages3[-1], HumanMessage):
|
| 286 |
+
messages3=messages3[:-2]
|
| 287 |
+
|
| 288 |
if '#chart' in message:
|
| 289 |
message = message.split('#chart', 1)[1].strip()
|
| 290 |
chart_url = f"https://quickchart.io/natural/{message}"
|
|
|
|
| 307 |
start_index = error_message.find("Input validation error:")
|
| 308 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 309 |
if start_index != -1 and end_index != -1:
|
| 310 |
+
raise gr.Error(error_message[start_index:end_index ].strip()) from e
|
|
|
|
| 311 |
else:
|
| 312 |
raise gr.Error("Error occurred during response") from e
|
| 313 |
|
|
|
|
| 331 |
start_index = error_message.find("Input validation error:")
|
| 332 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 333 |
if start_index != -1 and end_index != -1:
|
| 334 |
+
raise gr.Error(error_message[start_index:end_index ].strip()) from e
|
|
|
|
| 335 |
else:
|
| 336 |
raise gr.Error("Error occurred during response") from e
|
| 337 |
|
|
|
|
| 348 |
def Link_Scratch(history, messages4):
|
| 349 |
|
| 350 |
combined_message = history[-1][0]
|
| 351 |
+
if isinstance(messages4[-1], HumanMessage):
|
| 352 |
+
messages4=messages4[:-2]
|
| 353 |
|
| 354 |
link = ""
|
| 355 |
user_message = ""
|
|
|
|
| 391 |
start_index = error_message.find("Input validation error:")
|
| 392 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 393 |
if start_index != -1 and end_index != -1:
|
| 394 |
+
raise gr.Error(error_message[start_index:end_index ].strip()) from e
|
|
|
|
| 395 |
else:
|
| 396 |
raise gr.Error("Error occurred during response") from e
|
| 397 |
|
|
|
|
| 422 |
def File_Interact(history, filepath, messages5):
|
| 423 |
|
| 424 |
combined_message = history[-1][0]
|
| 425 |
+
if isinstance(messages5[-1], HumanMessage):
|
| 426 |
+
messages5=messages5[:-2]
|
| 427 |
|
| 428 |
link = ""
|
| 429 |
user_message = ""
|
|
|
|
| 461 |
start_index = error_message.find("Input validation error:")
|
| 462 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 463 |
if start_index != -1 and end_index != -1:
|
| 464 |
+
raise gr.Error(error_message[start_index:end_index ].strip()) from e
|
|
|
|
| 465 |
else:
|
| 466 |
raise gr.Error("Error occurred during response") from e
|
| 467 |
|
|
|
|
| 478 |
def Explore_WebSite(history, messages6):
|
| 479 |
|
| 480 |
message=history[-1][0]
|
| 481 |
+
if isinstance(messages6[-1], HumanMessage):
|
| 482 |
+
messages6=messages6[:-2]
|
| 483 |
|
| 484 |
links = [
|
| 485 |
'https://huggingface.co/mou3az'
|
|
|
|
| 511 |
start_index = error_message.find("Input validation error:")
|
| 512 |
end_index = error_message.find("and 4096 `max_new_tokens`")
|
| 513 |
if start_index != -1 and end_index != -1:
|
| 514 |
+
raise gr.Error(error_message[start_index:end_index ].strip()) from e
|
|
|
|
| 515 |
else:
|
| 516 |
raise gr.Error("Error occurred during response") from e
|
| 517 |
|