bedrock123 commited on
Commit
1c71aa2
·
1 Parent(s): 715494c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -17
app.py CHANGED
@@ -1,34 +1,26 @@
1
  import gradio as gr
2
  from datetime import datetime
3
- from gradio.components import *
4
- from gradio.inputs import *
5
 
6
  chatrooms = {}
7
 
8
- def chatroom(username, message, image, send_message, chatroom_name):
9
  if chatroom_name not in chatrooms:
10
  chatrooms[chatroom_name] = []
11
  if send_message:
12
  now = datetime.now()
13
  timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
14
- chatrooms[chatroom_name].append((username, message, image, timestamp))
15
- message_history = ""
16
- for msg in chatrooms[chatroom_name]:
17
- if msg[1]:
18
- message_history += f"{msg[3]} {msg[0]}: {msg[1]}<br>"
19
- if msg[2]:
20
- message_history += f"{msg[3]} {msg[0]}: <img src='data:image/png;base64,{msg[2]}' /><br>"
21
  return message_history, ""
22
 
23
  iface = gr.Interface(fn=chatroom,
24
- inputs=[Textbox("Username"),
25
- Textbox("Message"),
26
- Image(shape=(224, 224), image_mode="RGB", source="upload", label="Image"),
27
- Checkbox("Send"),
28
- Textbox(label="Chatroom Name")],
29
  outputs=["html", "text"],
30
  layout="vertical",
31
  title="Public Chatroom",
32
- description="Type your username, message, and/or upload an image, and click Send to send to the chatroom.")
33
 
34
- iface.launch()
 
1
  import gradio as gr
2
  from datetime import datetime
 
 
3
 
4
  chatrooms = {}
5
 
6
+ def chatroom(username, message, send_message, chatroom_name):
7
  if chatroom_name not in chatrooms:
8
  chatrooms[chatroom_name] = []
9
  if send_message:
10
  now = datetime.now()
11
  timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
12
+ chatrooms[chatroom_name].append((username, message, timestamp))
13
+ message_history = "<br>".join([f"{msg[2]} {msg[0]}: {msg[1]}" for msg in chatrooms[chatroom_name]])
 
 
 
 
 
14
  return message_history, ""
15
 
16
  iface = gr.Interface(fn=chatroom,
17
+ inputs=[gr.inputs.Textbox("Username"),
18
+ gr.inputs.Textbox("Message"),
19
+ gr.inputs.Checkbox("Send"),
20
+ gr.inputs.Textbox(label="Chatroom Name")],
 
21
  outputs=["html", "text"],
22
  layout="vertical",
23
  title="Public Chatroom",
24
+ description="Type your username and message, and click Send to send to the chatroom.")
25
 
26
+ iface.launch(share=True)