Update app.py
Browse files
app.py
CHANGED
@@ -229,7 +229,7 @@ def Web_Search(history):
|
|
229 |
source_knowledge = ""
|
230 |
|
231 |
augmented_prompt = f"""
|
232 |
-
|
233 |
Query: {message}
|
234 |
Search Content:
|
235 |
{source_knowledge}
|
@@ -257,27 +257,40 @@ def Chart_Generator(history):
|
|
257 |
]
|
258 |
|
259 |
message = history[-1][0]
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
messages.append(prompt)
|
269 |
-
|
270 |
response = chat_model.invoke(messages)
|
271 |
messages.append(AIMessage(content=response.content))
|
272 |
-
|
273 |
if len(messages) >= 8:
|
274 |
messages = messages[-8:]
|
275 |
|
276 |
-
combined_content
|
277 |
-
|
278 |
-
response_text = "Can't generate this image. Please provide valid chart details."
|
279 |
-
combined_content = response_text
|
280 |
-
|
281 |
history[-1][1] = ""
|
282 |
for character in combined_content:
|
283 |
history[-1][1] += character
|
@@ -313,7 +326,7 @@ def Link_Scratch(history):
|
|
313 |
response_message = "The provided link is empty or does not contain any meaningful words."
|
314 |
else:
|
315 |
augmented_prompt = f"""
|
316 |
-
|
317 |
Query: {user_message}
|
318 |
Link Content:
|
319 |
{content_data}
|
@@ -372,7 +385,7 @@ def File_Interact(history,filepath):
|
|
372 |
response_message = "The file is empty or does not contain any meaningful words."
|
373 |
else:
|
374 |
augmented_prompt = f"""
|
375 |
-
|
376 |
Query: {user_message}
|
377 |
File Content:
|
378 |
{content_data}
|
@@ -444,7 +457,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
444 |
)
|
445 |
|
446 |
with gr.Row():
|
447 |
-
msg = gr.Textbox(show_label=False, placeholder="
|
448 |
submit = gr.Button("➡️Send", scale=1)
|
449 |
|
450 |
clear = gr.ClearButton([msg, chatbot])
|
|
|
229 |
source_knowledge = ""
|
230 |
|
231 |
augmented_prompt = f"""
|
232 |
+
You are an AI designed to help understand and extract information from provided Search Content. Based on the user's Query, you may need to summarize the text, answer specific questions, or provide guidance if the answer isn't available.
|
233 |
Query: {message}
|
234 |
Search Content:
|
235 |
{source_knowledge}
|
|
|
257 |
]
|
258 |
|
259 |
message = history[-1][0]
|
260 |
+
if '#chart' in message:
|
261 |
+
message = user_input.split('#chart', 1)[1].strip()
|
262 |
+
chart_url = f"https://quickchart.io/natural/{message}"
|
263 |
+
response = requests.get(chart_url)
|
264 |
+
|
265 |
+
if response.status_code == 200:
|
266 |
+
image_html = f'<img src="{chart_url}" alt="Generated Chart" style="display: block; margin: auto; max-width: 100%; max-height: 100%;">'
|
267 |
+
message_with_description = f"Describe and analyse the content of this chart: {chart_url}"
|
268 |
+
|
269 |
+
prompt = HumanMessage(content=message_with_description)
|
270 |
+
messages.append(prompt)
|
271 |
+
|
272 |
+
response = chat_model.invoke(messages)
|
273 |
+
messages.append(AIMessage(content=response.content))
|
274 |
+
|
275 |
+
if len(messages) >= 8:
|
276 |
+
messages = messages[-8:]
|
277 |
+
|
278 |
+
combined_content = f'{image_html}<br>{response.content}'
|
279 |
+
else:
|
280 |
+
response_text = "Can't generate this image. Please provide valid chart details."
|
281 |
+
combined_content = response_text
|
282 |
+
else:
|
283 |
+
prompt = HumanMessage(content=message)
|
284 |
messages.append(prompt)
|
285 |
+
|
286 |
response = chat_model.invoke(messages)
|
287 |
messages.append(AIMessage(content=response.content))
|
288 |
+
|
289 |
if len(messages) >= 8:
|
290 |
messages = messages[-8:]
|
291 |
|
292 |
+
combined_content=response.content
|
293 |
+
|
|
|
|
|
|
|
294 |
history[-1][1] = ""
|
295 |
for character in combined_content:
|
296 |
history[-1][1] += character
|
|
|
326 |
response_message = "The provided link is empty or does not contain any meaningful words."
|
327 |
else:
|
328 |
augmented_prompt = f"""
|
329 |
+
You are an AI designed to help understand and extract information from provided Link Content. Based on the user's Query, you may need to summarize the text, answer specific questions, or provide guidance if the answer isn't available.
|
330 |
Query: {user_message}
|
331 |
Link Content:
|
332 |
{content_data}
|
|
|
385 |
response_message = "The file is empty or does not contain any meaningful words."
|
386 |
else:
|
387 |
augmented_prompt = f"""
|
388 |
+
You are an AI designed to help understand and extract information from provided File Content. Based on the user's Query, you may need to summarize the text, answer specific questions, or provide guidance if the answer isn't available.
|
389 |
Query: {user_message}
|
390 |
File Content:
|
391 |
{content_data}
|
|
|
457 |
)
|
458 |
|
459 |
with gr.Row():
|
460 |
+
msg = gr.Textbox(show_label=False, placeholder="To generate chart: #chart [your message]. To discuss the chart: type your message.", scale=10, container=False)
|
461 |
submit = gr.Button("➡️Send", scale=1)
|
462 |
|
463 |
clear = gr.ClearButton([msg, chatbot])
|