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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -30
app.py CHANGED
@@ -3,43 +3,32 @@ from datetime import datetime
3
  from gradio.components import *
4
  from gradio.inputs import *
5
 
6
- # Define chatrooms and versions
7
- CHATROOMS = {}
8
- VERSIONS = {
9
- "app.py, version 1.0": "app.py",
10
- "app_2.py, version 1.1": "app_2.py"
11
- }
12
 
13
- def chatroom(username, message, send_message, chatroom_name, image=None):
14
- if chatroom_name not in CHATROOMS:
15
- CHATROOMS[chatroom_name] = []
16
  if send_message:
17
  now = datetime.now()
18
  timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
19
- CHATROOMS[chatroom_name].append((username, message, timestamp, image))
20
- message_history = "<br>".join([f"{msg[2]} {msg[0]}: {msg[1]}" + (f"<br><img src='{msg[3]}' width='200'>" if msg[3] else "") for msg in CHATROOMS[chatroom_name]])
 
 
 
 
 
21
  return message_history, ""
22
 
23
- # Define inputs and outputs
24
- inputs = [
25
- Textbox("Username"),
26
- Textbox("Message"),
27
- Checkbox("Send"),
28
- Textbox(label="Chatroom Name"),
29
- Image(type="numpy", label="Image (optional)", optional=True),
30
- choose("Version", choices=list(VERSIONS.keys()))
31
- ]
32
- outputs = ["html", "text"]
33
-
34
- # Define interface
35
- iface = gr.Interface(fn=chatroom,
36
- inputs=inputs,
37
- outputs=outputs,
38
  layout="vertical",
39
  title="Public Chatroom",
40
- description="Type your username and message, and click Send to send to the chatroom.")
41
 
42
- # Define file paths
43
- version = iface.inputs[-1].value
44
- iface.share(file_name=VERSIONS[version])
45
  iface.launch()
 
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()