Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -64,14 +64,6 @@ def chat_with_bots(user_input):
|
|
64 |
|
65 |
return bot1_response, bot2_response
|
66 |
|
67 |
-
def user_ask(state, chatbot, textbox):
|
68 |
-
user_input = textbox.value
|
69 |
-
bot1_response, bot2_response = chat_with_bots(user_input)
|
70 |
-
chatbot.append("User: " + user_input)
|
71 |
-
chatbot.append("Bot 1: " + bot1_response['output'])
|
72 |
-
chatbot.append("Bot 2: " + bot2_response['output'])
|
73 |
-
state['last_bots'] = [bot1_response['model_name'], bot2_response['model_name']]
|
74 |
-
return state, chatbot, ""
|
75 |
|
76 |
def update_ratings(state, winner_index):
|
77 |
elo_ratings = get_user_elo_ratings()
|
@@ -92,6 +84,20 @@ def vote_down_model(state, chatbot):
|
|
92 |
update_message = update_ratings(state, 1)
|
93 |
chatbot.append(update_message)
|
94 |
return chatbot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
with gr.Blocks() as demo:
|
97 |
state = gr.State({})
|
@@ -104,19 +110,21 @@ with gr.Blocks() as demo:
|
|
104 |
tie_btn = gr.Button(value="π€ Tie", interactive=False)
|
105 |
clear_btn = gr.Button(value="ποΈ Clear", interactive=False)
|
106 |
with gr.Column():
|
107 |
-
|
|
|
108 |
with gr.Row():
|
109 |
with gr.Column(scale=8):
|
110 |
textbox = gr.Textbox(placeholder="Enter text and press ENTER")
|
111 |
with gr.Column(scale=1, min_width=60):
|
112 |
submit_btn = gr.Button(value="Submit")
|
113 |
|
114 |
-
textbox.submit(user_ask, [state,
|
115 |
-
submit_btn.click(user_ask, [state,
|
116 |
-
upvote_btn.click(vote_up_model, [state,
|
117 |
-
downvote_btn.click(vote_down_model, [state,
|
118 |
-
clear_btn.click(lambda _:
|
119 |
-
|
120 |
|
|
|
|
|
121 |
demo.queue()
|
122 |
demo.launch(share=True, server_name='0.0.0.0', server_port=7860)
|
|
|
64 |
|
65 |
return bot1_response, bot2_response
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
def update_ratings(state, winner_index):
|
69 |
elo_ratings = get_user_elo_ratings()
|
|
|
84 |
update_message = update_ratings(state, 1)
|
85 |
chatbot.append(update_message)
|
86 |
return chatbot
|
87 |
+
def user_ask(state, chatbot1, chatbot2, textbox):
|
88 |
+
user_input = textbox.value
|
89 |
+
bot1_response, bot2_response = chat_with_bots(user_input)
|
90 |
+
|
91 |
+
chatbot1.append("User: " + user_input)
|
92 |
+
chatbot1.append("Bot 1: " + bot1_response['output'])
|
93 |
+
|
94 |
+
chatbot2.append("User: " + user_input)
|
95 |
+
chatbot2.append("Bot 2: " + bot2_response['output'])
|
96 |
+
|
97 |
+
state['last_bots'] = [bot1_response['model_name'], bot2_response['model_name']]
|
98 |
+
return state, chatbot1, chatbot2, ""
|
99 |
+
|
100 |
+
# ... [Rest of your existing functions] ...
|
101 |
|
102 |
with gr.Blocks() as demo:
|
103 |
state = gr.State({})
|
|
|
110 |
tie_btn = gr.Button(value="π€ Tie", interactive=False)
|
111 |
clear_btn = gr.Button(value="ποΈ Clear", interactive=False)
|
112 |
with gr.Column():
|
113 |
+
chatbot1 = gr.Chatbot(label='ChatBot 1')
|
114 |
+
chatbot2 = gr.Chatbot(label='ChatBot 2')
|
115 |
with gr.Row():
|
116 |
with gr.Column(scale=8):
|
117 |
textbox = gr.Textbox(placeholder="Enter text and press ENTER")
|
118 |
with gr.Column(scale=1, min_width=60):
|
119 |
submit_btn = gr.Button(value="Submit")
|
120 |
|
121 |
+
textbox.submit(user_ask, [state, chatbot1, chatbot2, textbox], [state, chatbot1, chatbot2, textbox])
|
122 |
+
submit_btn.click(user_ask, [state, chatbot1, chatbot2, textbox], [state, chatbot1, chatbot2, textbox])
|
123 |
+
upvote_btn.click(vote_up_model, [state, chatbot1], [chatbot1])
|
124 |
+
downvote_btn.click(vote_down_model, [state, chatbot1], [chatbot1])
|
125 |
+
clear_btn.click(lambda _: (chatbot1.clear(), chatbot2.clear()), inputs=[], outputs=[chatbot1, chatbot2])
|
|
|
126 |
|
127 |
+
demo.queue()
|
128 |
+
demo.launch(share=True, server_name='0.0.0.0', server_port=7860)
|
129 |
demo.queue()
|
130 |
demo.launch(share=True, server_name='0.0.0.0', server_port=7860)
|