Spaces:
Sleeping
Sleeping
Update app.py
Browse files48 unmodified lines4950515253544 unmodified lines596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911036 unmodified lines14714814915015115215315415515615715815918 unmodified lines17817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228348 unmodified lines# rag_response, rag_reference, rag_reference_text = query_rag_qa(# rag_index, query, search_level# )return (str(grag_response.response),# grag_reference,4 unmodified lines)# def eval_llm(query, rag_response, grag_response):# """# Evaluate the Graph-RAG and RAG responses using an LLM.# Args:# query (str): The query that was asked.# rag_response (str): The response from the Vanilla-RAG model.# grag_response (str): The response from the Graph-RAG model.# Returns:# str: The evaluation text on various criteria from the LLM.# """# if not query.strip() or not rag_response.strip() or not grag_response.strip():# raise gr.Error("Please ask a query and get responses before evaluating.")# eval_text = evaluate_llm(query, grag_response, rag_response)# return eval_text# def reason_and_plot(query, grag_response, grag_reference):# """# Get the reasoning graph for a query and plot the knowledge graph.# Args:# query (str): The query to ask the Graph-RAG.# grag_response (str): The response from the Graph-RAG model.# grag_reference (str): The reference text from the Graph-RAG model.# Returns:# tuple: The reasoning graph and the HTML to plot the knowledge graph.# """# if not query.strip() or not grag_response.strip() or not grag_reference.strip():# raise gr.Error(# "Please ask a query and get a Graph-RAG response before reasoning."# )# graph_reasoning = reasoning_graph(query, grag_response, grag_reference)# escaped_html = plot_subgraph(grag_reference)# iframe_html = f'<iframe srcdoc="{escaped_html}" width="100%" height="400px" frameborder="0"></iframe>'# return graph_reasoning, iframe_htmldef show_graph():"""Show the latest graph visualization in an iframe.36 unmodified linescoupon = get_coupon(query, grag_response)return coupon# from gradio import ChatMessage# def chat_function(message, history):# history.append(ChatMessage(role="user", content=message))# history.append(ChatMessage(role="assistant", content="Hello, how can I help you?"))# return historywith gr.Blocks() as demo:gr.Markdown("# Comfy Virtual Assistant")chatbot = gr.Chatbot(18 unmodified linesreturn "", chat_historymsg.submit(respond, [msg, chatbot], [msg, chatbot])# with gr.Row():# with gr.Column(scale=4):# query_input = gr.Textbox(label="Input Your Query", lines=3)# # with gr.Column(scale=1):# # search_level = gr.Slider(# # minimum=1, maximum=50, value=3, step=5, label="Search Level"# # )# ask_button = gr.Button("Ask Comfy", variant="primary")# examples = gr.Examples(# examples=[# ["Recommend me an apple phone that has more than 10MP camera."],# ["What is the price of Samsung Galaxy S24 Ultra 12/256Gb Titanium Gray"],# ["I want a phone with 5000 mAH or more battery"],# ],# inputs=[query_input],# )# with gr.Row():# with gr.Column():# gr.Markdown("### Graph-RAG")# grag_output = gr.Textbox(label="Response", lines=5)# grag_reference = gr.Textbox(label="Triplets", lines=3)# with gr.Accordion("Extracted Reference (Raw)", open=False):# grag_reference_text = gr.Textbox(label="Raw Reference", lines=5)# with gr.Column():# gr.Markdown("### Vanilla RAG")# rag_output = gr.Textbox(label="Response", lines=5)# rag_reference = gr.Textbox(label="Extracted Reference", lines=3)# with gr.Accordion("Extracted Reference (Raw)", open=False):# rag_reference_text = gr.Textbox(label="Raw Reference", lines=5)# gr.Markdown("### Coupon")# with gr.Row():# with gr.Column():# coupon = gr.Text(label="Coupon", lines=1)# with gr.Column():# reveal = gr.Button("Reveal Coupon", variant="secondary")# with gr.Row():# gr.Markdown("### Evaluate and Compare")# with gr.Row():# eval_button = gr.Button("Evaluate LLMs", variant="secondary")# grag_performance = gr.Textbox(label="Evaluation", lines=3)# with gr.Row():# gr.Markdown("### Graph Reasoning")# with gr.Row():# reason_button = gr.Button("Get Graph Reasoning", variant="secondary")# with gr.Row():# with gr.Column():# grag_reasoning = gr.Textbox(label="Graph-RAG Reasoning", lines=5)# with gr.Column():# subgraph_plot = gr.HTML()# with gr.Row():# plot_button = gr.Button("Plot Knowledge Graph", variant="secondary")# kg_output = gr.HTML()# ask_button.click(# query_tqa,# inputs=[query_input, search_level],# outputs=[# grag_output,# # grag_reference,# # grag_reference_text,# # rag_output,# # rag_reference,# # rag_reference_text,# ],# )# eval_button.click(# eval_llm,# inputs=[query_input, rag_output, grag_output],# outputs=[grag_performance],# )# reason_button.click(# reason_and_plot,# inputs=[query_input, grag_output, grag_reference],# outputs=[grag_reasoning, subgraph_plot],# )# plot_button.click(# show_graph,# outputs=[kg_output],# )# reveal.click(# reveal_coupon,# inputs=[query_input, grag_output],# outputs=[coupon],# )demo.launch(auth=(os.getenv("ID"), os.getenv("PASS")), share=False)48 unmodified lines495051525354554 unmodified lines60616263646536 unmodified lines10210310410510610710818 unmodified lines12712812913013148 unmodified lines# rag_response, rag_reference, rag_reference_text = query_rag_qa(# rag_index, query, search_level# )print(str(grag_response.response))return (str(grag_response.response),# grag_reference,4 unmodified lines)def show_graph():"""Show the latest graph visualization in an iframe.36 unmodified linescoupon = get_coupon(query, grag_response)return couponwith gr.Blocks() as demo:gr.Markdown("# Comfy Virtual Assistant")chatbot = gr.Chatbot(18 unmodified linesreturn "", chat_historymsg.submit(respond, [msg, chatbot], [msg, chatbot])demo.launch(auth=(os.getenv("ID"), os.getenv("PASS")), share=False)
app.py+3-155