Spaces:
Sleeping
Sleeping
Update app.py
Browse files56 unmodified lines57585960616218 unmodified lines8182838485868788894 unmodified lines94959697989910010110210310410556 unmodified lines# 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])4 unmodified linesreturn "", 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)56 unmodified lines5758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810918 unmodified lines1281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711724 unmodified lines17717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128256 unmodified lines# 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 coupon# Implementing Gradio 5 features and building a ChatInterface UI yourselfPLACEHOLDER = """<div style="padding: 20px; text-align: center; display: flex; flex-direction: column; align-items: center;"><img src="https://ysharma-dummy-chat-app.hf.space/file=/tmp/gradio/c21ff9c8e7ecb2f7d957a72f2ef03c610ac7bbc4/Meta_lockup_positive%20primary_RGB_small.jpg" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; margin-bottom: 10px;"><h1 style="font-size: 28px; margin: 0;">Meta llama3.2</h1><p style="font-size: 18px; margin: 5px 0 0; opacity: 0.65;"><a href="https://huggingface.co/blog/llama32" target="_blank" style="color: inherit; text-decoration: none;">Learn more about Llama 3.2</a></p></div>"""with gr.Blocks() as demo:gr.Markdown("# Comfy Virtual Assistant")chatbot = gr.Chatbot(label="Comfy Virtual Assistant",type="messages",scale=1,suggestions = [{"text": "How much iphone cost?"},{"text": "What phone options do i have ?"}],placeholder = PLACEHOLDER,)msg = gr.Textbox(label="Input Your Query")clear = gr.ClearButton([msg, chatbot])4 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)
app.py+181-4