arjunguha commited on
Commit
0592bff
1 Parent(s): 2a77a2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -25,7 +25,7 @@ def join_chat(chat_id, username):
25
  return f"Welcome {username}! You have joined the chat."
26
 
27
  # Handle sending and receiving messages
28
- def chat_interface(chat_id, username, message):
29
  if chat_id not in conversations:
30
  return "Invalid chat ID. Please start a new chat."
31
  if username not in usernames.get(chat_id, []):
@@ -49,7 +49,7 @@ def main():
49
  existing_chat_button = gr.Button("Enter Conversation ID for Existing Chat")
50
 
51
  # Chat interface components, initially hidden
52
- with gr.Column(visible=False) as chat_interface:
53
  chat_id_display = gr.Markdown("Chat ID: ")
54
  chat_id = gr.Textbox(label="Chat ID", placeholder="Enter Chat ID to join or create a new one.")
55
  username = gr.Textbox(label="Username", placeholder="Enter your username.")
@@ -64,19 +64,19 @@ def main():
64
  conversation_id = new_chat()
65
  return gr.update(visible=True), gr.update(value=f"Chat ID: {conversation_id}"), conversation_id
66
 
67
- new_chat_button.click(fn=handle_new_chat, outputs=[chat_interface, chat_id_display, chat_id])
68
 
69
  # Existing Chat button logic
70
  def handle_existing_chat():
71
  return gr.update(visible=True)
72
 
73
- existing_chat_button.click(fn=handle_existing_chat, outputs=chat_interface)
74
 
75
  # Join Chat button logic
76
  join_button.click(fn=join_chat, inputs=[chat_id, username], outputs=join_output)
77
 
78
  # Send Message button logic
79
- send_button.click(fn=chat_interface, inputs=[chat_id, username, message], outputs=chat_output)
80
 
81
  demo.launch()
82
 
 
25
  return f"Welcome {username}! You have joined the chat."
26
 
27
  # Handle sending and receiving messages
28
+ def chat_message_interface(chat_id, username, message):
29
  if chat_id not in conversations:
30
  return "Invalid chat ID. Please start a new chat."
31
  if username not in usernames.get(chat_id, []):
 
49
  existing_chat_button = gr.Button("Enter Conversation ID for Existing Chat")
50
 
51
  # Chat interface components, initially hidden
52
+ with gr.Column(visible=False) as chat_interface_column:
53
  chat_id_display = gr.Markdown("Chat ID: ")
54
  chat_id = gr.Textbox(label="Chat ID", placeholder="Enter Chat ID to join or create a new one.")
55
  username = gr.Textbox(label="Username", placeholder="Enter your username.")
 
64
  conversation_id = new_chat()
65
  return gr.update(visible=True), gr.update(value=f"Chat ID: {conversation_id}"), conversation_id
66
 
67
+ new_chat_button.click(fn=handle_new_chat, outputs=[chat_interface_column, chat_id_display, chat_id])
68
 
69
  # Existing Chat button logic
70
  def handle_existing_chat():
71
  return gr.update(visible=True)
72
 
73
+ existing_chat_button.click(fn=handle_existing_chat, outputs=chat_interface_column)
74
 
75
  # Join Chat button logic
76
  join_button.click(fn=join_chat, inputs=[chat_id, username], outputs=join_output)
77
 
78
  # Send Message button logic
79
+ send_button.click(fn=chat_message_interface, inputs=[chat_id, username, message], outputs=chat_output)
80
 
81
  demo.launch()
82