Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -51,81 +51,61 @@ def query_tqa(query, search_level):
|
|
51 |
# )
|
52 |
print(str(grag_response.response))
|
53 |
return (
|
54 |
-
str(grag_response.response)
|
55 |
-
# grag_reference,
|
56 |
-
# grag_reference_text,
|
57 |
-
# rag_response,
|
58 |
-
# rag_reference,
|
59 |
-
# rag_reference_text,
|
60 |
)
|
61 |
|
62 |
|
63 |
-
def show_graph():
|
64 |
-
"""
|
65 |
-
Show the latest graph visualization in an iframe.
|
66 |
-
|
67 |
-
Returns:
|
68 |
-
str: The HTML content to display the graph visualization in an iframe.
|
69 |
-
"""
|
70 |
-
|
71 |
-
graph_vis_dir = os.getenv("GRAPH_VIS", "graph_vis")
|
72 |
-
try:
|
73 |
-
latest_graph = get_latest_html_file(graph_vis_dir)
|
74 |
-
if latest_graph:
|
75 |
-
with open(latest_graph, "r", encoding="utf-8") as f:
|
76 |
-
html_content = f.read()
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
98 |
|
99 |
-
|
100 |
-
|
101 |
|
102 |
-
|
103 |
-
|
|
|
|
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
gr.Markdown("# Comfy Virtual Assistant")
|
108 |
-
chatbot = gr.Chatbot(
|
109 |
-
label="Comfy Virtual Assistant",
|
110 |
-
type="messages",
|
111 |
-
scale=1,
|
112 |
-
# suggestions = [
|
113 |
-
# {"text": "How much iphone cost?"},
|
114 |
-
# {"text": "What phone options do i have ?"}
|
115 |
-
# ],
|
116 |
-
|
117 |
)
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
def respond(message, chat_history):
|
122 |
-
bot_message = query_tqa(message, 2)
|
123 |
-
# chat_history.append((message, bot_message))
|
124 |
-
chat_history.append(ChatMessage(role="user", content=message))
|
125 |
-
chat_history.append(ChatMessage(role="assistant", content=bot_message))
|
126 |
-
time.sleep(1)
|
127 |
-
return "", chat_history
|
128 |
|
129 |
-
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
130 |
-
|
131 |
demo.launch(auth=(os.getenv("ID"), os.getenv("PASS")), share=False)
|
|
|
51 |
# )
|
52 |
print(str(grag_response.response))
|
53 |
return (
|
54 |
+
str(grag_response.response)
|
|
|
|
|
|
|
|
|
|
|
55 |
)
|
56 |
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
|
60 |
+
# with gr.Blocks() as demo:
|
61 |
+
# gr.Markdown("# Comfy Virtual Assistant")
|
62 |
+
# chatbot = gr.Chatbot(
|
63 |
+
# label="Comfy Virtual Assistant",
|
64 |
+
# type="messages",
|
65 |
+
# scale=1,
|
66 |
+
# # suggestions = [
|
67 |
+
# # {"text": "How much iphone cost?"},
|
68 |
+
# # {"text": "What phone options do i have ?"}
|
69 |
+
# # ],
|
70 |
+
|
71 |
+
# )
|
72 |
+
# msg = gr.Textbox(label="Input Your Query")
|
73 |
+
# clear = gr.ClearButton([msg, chatbot])
|
74 |
+
|
75 |
+
# def respond(message, chat_history):
|
76 |
+
# bot_message = query_tqa(message, 2)
|
77 |
+
# # chat_history.append((message, bot_message))
|
78 |
+
# chat_history.append(ChatMessage(role="user", content=message))
|
79 |
+
# chat_history.append(ChatMessage(role="assistant", content=bot_message))
|
80 |
+
# time.sleep(1)
|
81 |
+
# return "", chat_history
|
82 |
+
|
83 |
+
# msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
84 |
|
85 |
+
def chatbot_response(message: str, history: List[Tuple[str, str]]) -> str:
|
86 |
+
# Use the query_tqa function to get the response
|
87 |
+
search_level = 2 # You can adjust this or make it configurable
|
88 |
+
response = query_tqa(message, search_level)
|
89 |
+
return response
|
90 |
|
91 |
+
# Create the Gradio interface
|
92 |
+
with gr.Blocks() as demo:
|
93 |
+
chatbot = gr.Chatbot()
|
94 |
+
msg = gr.Textbox()
|
95 |
+
clear = gr.Button("Clear")
|
96 |
|
97 |
+
def user(user_message, history):
|
98 |
+
return "", history + [[user_message, None]]
|
99 |
|
100 |
+
def bot(history):
|
101 |
+
bot_message = chatbot_response(history[-1][0], history)
|
102 |
+
history[-1][1] = bot_message
|
103 |
+
return history
|
104 |
|
105 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
106 |
+
bot, chatbot, chatbot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
)
|
108 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
109 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
|
|
|
|
111 |
demo.launch(auth=(os.getenv("ID"), os.getenv("PASS")), share=False)
|