Spaces:
Sleeping
Sleeping
Update app.py
Browse files50 unmodified lines5152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013150 unmodified lines# )print(str(grag_response.response))return (str(grag_response.response),# grag_reference,# grag_reference_text,# rag_response,# rag_reference,# rag_reference_text,)def show_graph():"""Show the latest graph visualization in an iframe.Returns:str: The HTML content to display the graph visualization in an iframe."""graph_vis_dir = os.getenv("GRAPH_VIS", "graph_vis")try:latest_graph = get_latest_html_file(graph_vis_dir)if latest_graph:with open(latest_graph, "r", encoding="utf-8") as f:html_content = f.read()encoded_html = base64.b64encode(html_content.encode()).decode()iframe_html = f'<iframe src="data:text/html;base64,{encoded_html}" width="100%" height="1000px" frameborder="0"></iframe>'return iframe_htmlelse:return "No graph visualization found."except Exception as e:return 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")chatbot = gr.Chatbot(label="Comfy Virtual Assistant",type="messages",scale=1,# suggestions = [# {"text": "How much iphone cost?"},# {"text": "What phone options do i have ?"}# ],)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))chat_history.append(ChatMessage(role="user", content=message))chat_history.append(ChatMessage(role="assistant", content=bot_message))time.sleep(1)return "", chat_historymsg.submit(respond, [msg, chatbot], [msg, chatbot])demo.launch(auth=(os.getenv("ID"), os.getenv("PASS")), share=False)50 unmodified lines5152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011150 unmodified lines# )print(str(grag_response.response))return (str(grag_response.response))# 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 ?"}# # ],# )# 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))# chat_history.append(ChatMessage(role="user", content=message))# chat_history.append(ChatMessage(role="assistant", content=bot_message))# time.sleep(1)# return "", chat_history# msg.submit(respond, [msg, chatbot], [msg, chatbot])def chatbot_response(message: str, history: List[Tuple[str, str]]) -> str:# Use the query_tqa function to get the responsesearch_level = 2 # You can adjust this or make it configurableresponse = query_tqa(message, search_level)return response# Create the Gradio interfacewith gr.Blocks() as demo:chatbot = gr.Chatbot()msg = gr.Textbox()clear = gr.Button("Clear")def user(user_message, history):return "", history + [[user_message, None]]def bot(history):bot_message = chatbot_response(history[-1][0], history)history[-1][1] = bot_messagereturn historymsg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(bot, chatbot, chatbot)clear.click(lambda: None, None, chatbot, queue=False)demo.launch(auth=(os.getenv("ID"), os.getenv("PASS")), share=False)
app.py+46-66