Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,11 +11,14 @@ enable_btn = gr.Button.update(interactive=True)
|
|
11 |
with open('chatbot_urls.json', 'r') as file:
|
12 |
chatbots = json.load(file)
|
13 |
def clear_chat(state):
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
19 |
|
20 |
|
21 |
|
@@ -79,15 +82,16 @@ def get_bot_response(url, prompt,state,bot_index):
|
|
79 |
return response.json()['output'].split('### Instruction')[0]
|
80 |
|
81 |
def chat_with_bots(user_input, state):
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
85 |
|
86 |
-
|
87 |
-
state.update({'last_bots': [bot_names[0], bot_names[1]]})
|
88 |
|
89 |
-
bot1_response = get_bot_response(bot1_url, user_input,state,0)
|
90 |
-
bot2_response = get_bot_response(bot2_url, user_input,state,1)
|
91 |
|
92 |
return bot1_response, bot2_response
|
93 |
|
@@ -202,4 +206,4 @@ with gr.Blocks() as demo:
|
|
202 |
|
203 |
# Launch the Gradio interface
|
204 |
if __name__ == "__main__":
|
205 |
-
demo.launch(
|
|
|
11 |
with open('chatbot_urls.json', 'r') as file:
|
12 |
chatbots = json.load(file)
|
13 |
def clear_chat(state):
|
14 |
+
# Reset state including the chatbot order
|
15 |
+
state = {} if state is not None else state
|
16 |
+
# Shuffle and reinitialize chatbots in the state
|
17 |
+
bot_names = list(chatbots.keys())
|
18 |
+
random.shuffle(bot_names)
|
19 |
+
state['last_bots'] = [bot_names[0], bot_names[1]]
|
20 |
+
# Reset other components
|
21 |
+
return state, None, None, gr.Button.update(interactive=False), gr.Button.update(interactive=False), gr.Textbox.update(interactive=False), gr.Button.update(interactive=False)
|
22 |
|
23 |
|
24 |
|
|
|
82 |
return response.json()['output'].split('### Instruction')[0]
|
83 |
|
84 |
def chat_with_bots(user_input, state):
|
85 |
+
# Use existing bot order from state if available, otherwise shuffle and initialize
|
86 |
+
if 'last_bots' not in state or not state['last_bots']:
|
87 |
+
bot_names = list(chatbots.keys())
|
88 |
+
random.shuffle(bot_names)
|
89 |
+
state['last_bots'] = [bot_names[0], bot_names[1]]
|
90 |
|
91 |
+
bot1_url, bot2_url = chatbots[state['last_bots'][0]], chatbots[state['last_bots'][1]]
|
|
|
92 |
|
93 |
+
bot1_response = get_bot_response(bot1_url, user_input, state, 0)
|
94 |
+
bot2_response = get_bot_response(bot2_url, user_input, state, 1)
|
95 |
|
96 |
return bot1_response, bot2_response
|
97 |
|
|
|
206 |
|
207 |
# Launch the Gradio interface
|
208 |
if __name__ == "__main__":
|
209 |
+
demo.launch()
|