Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
from IPython.display import Image, display
|
4 |
from langchain.embeddings import SentenceTransformerEmbeddings
|
5 |
from langchain.vectorstores import FAISS
|
6 |
from langchain_community.chat_models.huggingface import ChatHuggingFace
|
@@ -32,17 +31,21 @@ messages = [
|
|
32 |
]
|
33 |
|
34 |
def handle_message(message: str, mode: str):
|
|
|
35 |
|
36 |
if not message.strip():
|
37 |
-
return "Enter a valid message."
|
|
|
38 |
if mode == "Chat-Message":
|
39 |
-
|
40 |
elif mode == "Web-Search":
|
41 |
-
|
42 |
elif mode == "Chart-Generator":
|
43 |
-
|
44 |
else:
|
45 |
-
|
|
|
|
|
46 |
|
47 |
def chat_message(message: str):
|
48 |
global messages
|
@@ -106,16 +109,14 @@ def chart_generator(message: str):
|
|
106 |
if len(messages) >= 6:
|
107 |
messages = messages[-6:]
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
return f"IT-Assistant: {response.content}"
|
112 |
else:
|
113 |
-
return f"Can't generate this image. Please provide valid chart details."
|
114 |
|
115 |
demo = gr.Interface(
|
116 |
fn=handle_message,
|
117 |
inputs=["text", gr.Radio(["Chat-Message", "Web-Search", "Chart-Generator"], label="mode", info="Choose a mode and enter your message, then click submit to interact.")],
|
118 |
-
outputs="
|
119 |
title="IT Assistant")
|
120 |
|
121 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
from langchain.embeddings import SentenceTransformerEmbeddings
|
4 |
from langchain.vectorstores import FAISS
|
5 |
from langchain_community.chat_models.huggingface import ChatHuggingFace
|
|
|
31 |
]
|
32 |
|
33 |
def handle_message(message: str, mode: str):
|
34 |
+
result_text, result_image = "", None
|
35 |
|
36 |
if not message.strip():
|
37 |
+
return "Enter a valid message.", None
|
38 |
+
|
39 |
if mode == "Chat-Message":
|
40 |
+
result_text = chat_message(message)
|
41 |
elif mode == "Web-Search":
|
42 |
+
result_text = web_search(message)
|
43 |
elif mode == "Chart-Generator":
|
44 |
+
result_text, result_image = chart_generator(message)
|
45 |
else:
|
46 |
+
result_text = "Select a valid mode."
|
47 |
+
|
48 |
+
return result_text, result_image
|
49 |
|
50 |
def chat_message(message: str):
|
51 |
global messages
|
|
|
109 |
if len(messages) >= 6:
|
110 |
messages = messages[-6:]
|
111 |
|
112 |
+
return f"IT-Assistant: {response.content}", chart_url
|
|
|
|
|
113 |
else:
|
114 |
+
return f"Can't generate this image. Please provide valid chart details.", None
|
115 |
|
116 |
demo = gr.Interface(
|
117 |
fn=handle_message,
|
118 |
inputs=["text", gr.Radio(["Chat-Message", "Web-Search", "Chart-Generator"], label="mode", info="Choose a mode and enter your message, then click submit to interact.")],
|
119 |
+
outputs=[gr.outputs.Textbox(label="Response"), gr.outputs.Image(label="Chart", type="auto")],
|
120 |
title="IT Assistant")
|
121 |
|
122 |
demo.launch()
|