Spaces:
Sleeping
Sleeping
chat interface
Browse files7 unmodified lines891011121330 unmodified lines444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710818 unmodified lines1271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512527 unmodified linesfrom embed_handler import query_rag_qafrom evaluate import evaluate_llm, reasoning_graph, get_couponimport base64load_dotenv()30 unmodified linesgrag_response, grag_reference, grag_reference_text = query_graph_qa(graph_rag_index, query, search_level)rag_response, rag_reference, rag_reference_text = query_rag_qa(rag_index, query, search_level)return (grag_response,grag_reference,grag_reference_text,rag_response,rag_reference,rag_reference_text,)# 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.18 unmodified linesreturn f"Error: {str(e)}"def reveal_coupon(query, grag_response):"""Get the coupon from the query and response.Args:query (str): Query asked to Graph-RAG.grag_response (str): Response from the Graph-RAG model.Returns:str: Coupon with reasoning."""if not query.strip() or not grag_response.strip():raise gr.Error("Please ask a query and get a response before revealing the coupon.")coupon = get_coupon(query, grag_response)return couponwith gr.Blocks() as demo:gr.Markdown("# Comfy Virtual Assistant")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)7 unmodified lines89101112131430 unmodified lines45464748495051525354555657585960616218 unmodified lines818283848586878889909192939495969798991001011021031041057 unmodified linesfrom embed_handler import query_rag_qafrom evaluate import evaluate_llm, reasoning_graph, get_couponimport base64import timeload_dotenv()30 unmodified linesgrag_response, grag_reference, grag_reference_text = query_graph_qa(graph_rag_index, query, search_level)# rag_response, rag_reference, rag_reference_text = query_rag_qa(# rag_index, query, search_level# )return (grag_response,# grag_reference,# grag_reference_text,# rag_response,# rag_reference,# rag_reference_text,)def show_graph():"""Show the latest graph visualization in an iframe.18 unmodified linesreturn f"Error: {str(e)}"with gr.Blocks() as demo:gr.Markdown("# Comfy Virtual Assistant")chatbot = gr.Chatbot()msg = gr.Textbox(label="Input Your Query")clear = gr.ClearButton([msg, chatbot])def respond(message, chat_history):bot_message = query_tqa(message, 2)chat_history.append((message, bot_message))time.sleep(1)return "", chat_historymsg.submit(respond, [msg, chatbot], [msg, chatbot])with gr.Row():plot_button = gr.Button("Plot Knowledge Graph", variant="secondary")kg_output = gr.HTML()demo.launch(auth=(os.getenv("ID"), os.getenv("PASS")), share=False)
app.py+19-166