Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from pipeline_ark import chat_gradio | |
| import json | |
| with open("characters.json", 'r', encoding='utf-8') as file: | |
| characters = json.load(file) | |
| character_list = [] | |
| for c in characters: | |
| character_list.append(c['name']) | |
| def chat_inter(message, chat_history, user_name, user_gender, bot_name, old, character, ask_image=False): | |
| for c in characters: | |
| if character == c['name']: | |
| traits = c['traits'] | |
| system_prompt = c['system_prompt'] | |
| if ask_image: | |
| pass | |
| reply = chat_gradio(user_name, user_gender, bot_name, old, traits, system_prompt, message, chat_history) | |
| return reply | |
| with gr.Blocks() as demo: | |
| with gr.Column(): | |
| user_name = gr.Text(label="Your name", value="Phu") | |
| user_gender = gr.Text(label="Your gender", value="man") | |
| bot_name = gr.Text(label="Bot's name", value="Ly") | |
| bot_old = gr.Number(label="Bot's old", value=23) | |
| bot_character = gr.Dropdown(choices=character_list, label="Bot's character") | |
| with gr.Column(): | |
| # history_state = gr.State([]) # khởi tạo list rỗng cho session | |
| gr.ChatInterface( | |
| fn=chat_inter, | |
| additional_inputs=[user_name, user_gender, bot_name, bot_old, bot_character], | |
| type="messages", | |
| autofocus=False, | |
| ) | |
| demo.launch(server_port=1234, server_name="192.168.5.155", share=True) |