Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import datetime
|
3 |
+
|
4 |
+
def save_message(name, message):
|
5 |
+
now = datetime.datetime.now()
|
6 |
+
timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
|
7 |
+
with open("chat.txt", "a") as f:
|
8 |
+
f.write(f"{timestamp} - {name}: {message}\n")
|
9 |
+
|
10 |
+
def main():
|
11 |
+
st.title("Streamlit Chat")
|
12 |
+
|
13 |
+
name = st.text_input("Name")
|
14 |
+
message = st.text_input("Message")
|
15 |
+
if st.button("Submit"):
|
16 |
+
save_message(name, message)
|
17 |
+
st.text("Message sent!")
|
18 |
+
|
19 |
+
st.text("Chat history:")
|
20 |
+
with open("chat.txt", "r") as f:
|
21 |
+
chat_history = f.read()
|
22 |
+
st.text(chat_history)
|
23 |
+
|
24 |
+
countdown = st.empty()
|
25 |
+
t = 60
|
26 |
+
while t:
|
27 |
+
mins, secs = divmod(t, 60)
|
28 |
+
countdown.text(f"Time remaining: {mins:02d}:{secs:02d}")
|
29 |
+
time.sleep(1)
|
30 |
+
t -= 1
|
31 |
+
if t == 0:
|
32 |
+
countdown.text("Time's up!")
|
33 |
+
with open("chat.txt", "r") as f:
|
34 |
+
chat_history = f.read()
|
35 |
+
st.text(chat_history)
|
36 |
+
t = 60
|
37 |
+
|
38 |
+
main()
|