Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,6 +49,7 @@ def query_tqa(query, search_level):
|
|
49 |
# rag_response, rag_reference, rag_reference_text = query_rag_qa(
|
50 |
# rag_index, query, search_level
|
51 |
# )
|
|
|
52 |
return (
|
53 |
str(grag_response.response),
|
54 |
# grag_reference,
|
@@ -59,52 +60,6 @@ def query_tqa(query, search_level):
|
|
59 |
)
|
60 |
|
61 |
|
62 |
-
# def eval_llm(query, rag_response, grag_response):
|
63 |
-
# """
|
64 |
-
# Evaluate the Graph-RAG and RAG responses using an LLM.
|
65 |
-
|
66 |
-
# Args:
|
67 |
-
# query (str): The query that was asked.
|
68 |
-
# rag_response (str): The response from the Vanilla-RAG model.
|
69 |
-
# grag_response (str): The response from the Graph-RAG model.
|
70 |
-
|
71 |
-
# Returns:
|
72 |
-
# str: The evaluation text on various criteria from the LLM.
|
73 |
-
# """
|
74 |
-
|
75 |
-
# if not query.strip() or not rag_response.strip() or not grag_response.strip():
|
76 |
-
# raise gr.Error("Please ask a query and get responses before evaluating.")
|
77 |
-
|
78 |
-
# eval_text = evaluate_llm(query, grag_response, rag_response)
|
79 |
-
# return eval_text
|
80 |
-
|
81 |
-
|
82 |
-
# def reason_and_plot(query, grag_response, grag_reference):
|
83 |
-
# """
|
84 |
-
# Get the reasoning graph for a query and plot the knowledge graph.
|
85 |
-
|
86 |
-
# Args:
|
87 |
-
# query (str): The query to ask the Graph-RAG.
|
88 |
-
# grag_response (str): The response from the Graph-RAG model.
|
89 |
-
# grag_reference (str): The reference text from the Graph-RAG model.
|
90 |
-
|
91 |
-
# Returns:
|
92 |
-
# tuple: The reasoning graph and the HTML to plot the knowledge graph.
|
93 |
-
# """
|
94 |
-
|
95 |
-
# if not query.strip() or not grag_response.strip() or not grag_reference.strip():
|
96 |
-
# raise gr.Error(
|
97 |
-
# "Please ask a query and get a Graph-RAG response before reasoning."
|
98 |
-
# )
|
99 |
-
|
100 |
-
# graph_reasoning = reasoning_graph(query, grag_response, grag_reference)
|
101 |
-
# escaped_html = plot_subgraph(grag_reference)
|
102 |
-
|
103 |
-
# iframe_html = f'<iframe srcdoc="{escaped_html}" width="100%" height="400px" frameborder="0"></iframe>'
|
104 |
-
|
105 |
-
# return graph_reasoning, iframe_html
|
106 |
-
|
107 |
-
|
108 |
def show_graph():
|
109 |
"""
|
110 |
Show the latest graph visualization in an iframe.
|
@@ -147,13 +102,7 @@ def reveal_coupon(query, grag_response):
|
|
147 |
coupon = get_coupon(query, grag_response)
|
148 |
return coupon
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
# def chat_function(message, history):
|
153 |
-
# history.append(ChatMessage(role="user", content=message))
|
154 |
-
# history.append(ChatMessage(role="assistant", content="Hello, how can I help you?"))
|
155 |
-
# return history
|
156 |
-
|
157 |
with gr.Blocks() as demo:
|
158 |
gr.Markdown("# Comfy Virtual Assistant")
|
159 |
chatbot = gr.Chatbot(
|
@@ -178,106 +127,5 @@ with gr.Blocks() as demo:
|
|
178 |
return "", chat_history
|
179 |
|
180 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
181 |
-
|
182 |
-
# with gr.Row():
|
183 |
-
# with gr.Column(scale=4):
|
184 |
-
# query_input = gr.Textbox(label="Input Your Query", lines=3)
|
185 |
-
# # with gr.Column(scale=1):
|
186 |
-
# # search_level = gr.Slider(
|
187 |
-
# # minimum=1, maximum=50, value=3, step=5, label="Search Level"
|
188 |
-
# # )
|
189 |
-
# ask_button = gr.Button("Ask Comfy", variant="primary")
|
190 |
-
|
191 |
-
# examples = gr.Examples(
|
192 |
-
# examples=[
|
193 |
-
# ["Recommend me an apple phone that has more than 10MP camera."],
|
194 |
-
# ["What is the price of Samsung Galaxy S24 Ultra 12/256Gb Titanium Gray"],
|
195 |
-
# ["I want a phone with 5000 mAH or more battery"],
|
196 |
-
# ],
|
197 |
-
# inputs=[query_input],
|
198 |
-
# )
|
199 |
-
|
200 |
-
# with gr.Row():
|
201 |
-
# with gr.Column():
|
202 |
-
# gr.Markdown("### Graph-RAG")
|
203 |
-
# grag_output = gr.Textbox(label="Response", lines=5)
|
204 |
-
# grag_reference = gr.Textbox(label="Triplets", lines=3)
|
205 |
-
# with gr.Accordion("Extracted Reference (Raw)", open=False):
|
206 |
-
# grag_reference_text = gr.Textbox(label="Raw Reference", lines=5)
|
207 |
-
|
208 |
-
# with gr.Column():
|
209 |
-
# gr.Markdown("### Vanilla RAG")
|
210 |
-
# rag_output = gr.Textbox(label="Response", lines=5)
|
211 |
-
# rag_reference = gr.Textbox(label="Extracted Reference", lines=3)
|
212 |
-
# with gr.Accordion("Extracted Reference (Raw)", open=False):
|
213 |
-
# rag_reference_text = gr.Textbox(label="Raw Reference", lines=5)
|
214 |
-
|
215 |
-
# gr.Markdown("### Coupon")
|
216 |
-
# with gr.Row():
|
217 |
-
# with gr.Column():
|
218 |
-
# coupon = gr.Text(label="Coupon", lines=1)
|
219 |
-
# with gr.Column():
|
220 |
-
# reveal = gr.Button("Reveal Coupon", variant="secondary")
|
221 |
-
|
222 |
-
# with gr.Row():
|
223 |
-
# gr.Markdown("### Evaluate and Compare")
|
224 |
-
|
225 |
-
# with gr.Row():
|
226 |
-
# eval_button = gr.Button("Evaluate LLMs", variant="secondary")
|
227 |
-
|
228 |
-
# grag_performance = gr.Textbox(label="Evaluation", lines=3)
|
229 |
-
|
230 |
-
# with gr.Row():
|
231 |
-
# gr.Markdown("### Graph Reasoning")
|
232 |
-
|
233 |
-
# with gr.Row():
|
234 |
-
# reason_button = gr.Button("Get Graph Reasoning", variant="secondary")
|
235 |
-
|
236 |
-
# with gr.Row():
|
237 |
-
# with gr.Column():
|
238 |
-
# grag_reasoning = gr.Textbox(label="Graph-RAG Reasoning", lines=5)
|
239 |
-
# with gr.Column():
|
240 |
-
# subgraph_plot = gr.HTML()
|
241 |
-
|
242 |
-
# with gr.Row():
|
243 |
-
# plot_button = gr.Button("Plot Knowledge Graph", variant="secondary")
|
244 |
-
|
245 |
-
# kg_output = gr.HTML()
|
246 |
-
|
247 |
-
# ask_button.click(
|
248 |
-
# query_tqa,
|
249 |
-
# inputs=[query_input, search_level],
|
250 |
-
# outputs=[
|
251 |
-
# grag_output,
|
252 |
-
# # grag_reference,
|
253 |
-
# # grag_reference_text,
|
254 |
-
# # rag_output,
|
255 |
-
# # rag_reference,
|
256 |
-
# # rag_reference_text,
|
257 |
-
# ],
|
258 |
-
# )
|
259 |
-
|
260 |
-
# eval_button.click(
|
261 |
-
# eval_llm,
|
262 |
-
# inputs=[query_input, rag_output, grag_output],
|
263 |
-
# outputs=[grag_performance],
|
264 |
-
# )
|
265 |
-
|
266 |
-
# reason_button.click(
|
267 |
-
# reason_and_plot,
|
268 |
-
# inputs=[query_input, grag_output, grag_reference],
|
269 |
-
# outputs=[grag_reasoning, subgraph_plot],
|
270 |
-
# )
|
271 |
-
|
272 |
-
# plot_button.click(
|
273 |
-
# show_graph,
|
274 |
-
# outputs=[kg_output],
|
275 |
-
# )
|
276 |
-
|
277 |
-
# reveal.click(
|
278 |
-
# reveal_coupon,
|
279 |
-
# inputs=[query_input, grag_output],
|
280 |
-
# outputs=[coupon],
|
281 |
-
# )
|
282 |
-
|
283 |
demo.launch(auth=(os.getenv("ID"), os.getenv("PASS")), share=False)
|
|
|
49 |
# rag_response, rag_reference, rag_reference_text = query_rag_qa(
|
50 |
# rag_index, query, search_level
|
51 |
# )
|
52 |
+
print(str(grag_response.response))
|
53 |
return (
|
54 |
str(grag_response.response),
|
55 |
# grag_reference,
|
|
|
60 |
)
|
61 |
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
def show_graph():
|
64 |
"""
|
65 |
Show the latest graph visualization in an iframe.
|
|
|
102 |
coupon = get_coupon(query, grag_response)
|
103 |
return coupon
|
104 |
|
105 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
with gr.Blocks() as demo:
|
107 |
gr.Markdown("# Comfy Virtual Assistant")
|
108 |
chatbot = gr.Chatbot(
|
|
|
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)
|