Spaces:
No application file
No application file
| import gradio as gr | |
| from utils.api.GPT import generate_answers_openai, Session | |
| import numpy as np | |
| import os | |
| import time | |
| with gr.Blocks() as demo: | |
| chatbot = gr.Chatbot() | |
| df = gr.DataFrame(headers=["Item", "translation (Chinese)", "Price"], | |
| datatype=["str", "str", "number"],) | |
| msg = gr.Textbox(lines=1, label="input",placeholder="Enter your message") | |
| def respond(history, customer_input): | |
| session = Session("") | |
| session.from_conversation_pair(history) | |
| print("(Q:) ", customer_input) | |
| response = generate_answers_openai(customer_input, session) | |
| print("(A:) ", response) | |
| return session.to_conversation_pair(),None | |
| msg.submit(respond, [chatbot,msg], [chatbot,df]) | |
| with gr.Column(): | |
| clear = gr.Button("Clear") | |
| btn = gr.Button("导出", type="button", label="导出") | |
| outputs = gr.JSON() | |
| def export(): | |
| stats_history = {} | |
| for i,item in enumerate(chatbot.value): | |
| user,assistant = item | |
| stats_history[str(i)] = { | |
| "user": user, | |
| "assistant": assistant | |
| } | |
| chatbot.value = [] | |
| return [], stats_history | |
| btn.click(export, None, [ chatbot, outputs, df, msg]) | |
| if __name__ == '__main__': | |
| demo.launch(show_error=True) | |