samradh commited on
Commit
68f0ceb
1 Parent(s): e83f3c4

Upload 2 files

Browse files
Files changed (2) hide show
  1. main.py +82 -0
  2. requirements.txt +0 -0
main.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from streamlit_server_state import server_state, server_state_lock
2
+ import streamlit as st
3
+
4
+ if "messages" not in server_state:
5
+ server_state["messages"] = []
6
+
7
+ if "NORMAL_PASSWORD_STR" not in server_state:
8
+ server_state["NORMAL_PASSWORD_STR"] = "123"
9
+
10
+ if "ADMIN_PASSWORD_STR" not in server_state:
11
+ server_state["ADMIN_PASSWORD_STR"] = "991152"
12
+
13
+ if "LAST_IMAGE" not in server_state:
14
+ server_state["LAST_IMAGE"] = None
15
+
16
+ def adminView():
17
+ st.write(f"Current Password: {server_state['NORMAL_PASSWORD_STR']}")
18
+ new_password = st.sidebar.text_input("New Password")
19
+ confirm_password = st.sidebar.text_input("Confirm Password")
20
+ change_btn = st.sidebar.button("Change")
21
+
22
+ if change_btn:
23
+ if new_password == confirm_password:
24
+ server_state["NORMAL_PASSWORD_STR"] = new_password
25
+ st.success("Password Changed")
26
+ else:
27
+ st.error("Passwords Don't Match")
28
+
29
+ def displayMessages():
30
+ st.markdown("---")
31
+ st.header("Messages")
32
+ col1, col2 = st.columns(2)
33
+ message_str = ""
34
+
35
+ if len(server_state["messages"]) > 0:
36
+ for message in reversed(server_state["messages"]):
37
+ message_str += f"{message['MESSAGE']} by {message['NAME']}\n"
38
+
39
+ col1.text_area("Chats", message_str, height=200)
40
+
41
+ if server_state["LAST_IMAGE"] is not None:
42
+ col2.image(server_state["LAST_IMAGE"]["IMAGE"], f"by - {server_state['LAST_IMAGE']['NAME']}")
43
+
44
+ def normalView():
45
+ name = st.sidebar.text_input("Name")
46
+ clear_chats = st.sidebar.button("Clear Chats")
47
+
48
+ col1, col2 = st.columns(2)
49
+ message = col1.text_area("Message",height=240)
50
+ send_btn = col1.button("Send")
51
+
52
+ camera_input = col2.camera_input("Take Pick")
53
+ send_image_btn = col2.button("Send Image")
54
+
55
+ if send_btn:
56
+ if message != "":
57
+ with server_state_lock["messages"]:
58
+ server_state["messages"] = server_state["messages"] + [{"NAME": name, "MESSAGE": message}]
59
+
60
+
61
+ if send_image_btn:
62
+ if camera_input is not None:
63
+ with server_state_lock["LAST_IMAGE"]:
64
+ server_state["LAST_IMAGE"] = {"NAME": name, "IMAGE":camera_input}
65
+
66
+
67
+ if clear_chats:
68
+ with server_state_lock["messages"]:
69
+ server_state["messages"] = []
70
+ with server_state_lock["LAST_IMAGE"]:
71
+ server_state["LAST_IMAGE"] = None
72
+
73
+ displayMessages()
74
+
75
+
76
+ #
77
+ password_input = st.sidebar.text_input("Password")
78
+
79
+ if password_input == server_state["NORMAL_PASSWORD_STR"]:
80
+ normalView()
81
+ elif password_input == server_state["ADMIN_PASSWORD_STR"]:
82
+ adminView()
requirements.txt ADDED
Binary file (1.71 kB). View file