MuhammadHananKhan123 commited on
Commit
1c744f3
·
verified ·
1 Parent(s): 3857c2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py CHANGED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import time
3
+
4
+ # App layout
5
+ st.set_page_config(page_title="Chat App", layout="wide")
6
+ st.title("Chat App")
7
+ st.markdown("This is a simple chat application similar to WhatsApp.")
8
+
9
+ # Initialize session state to store chat messages
10
+ if "messages" not in st.session_state:
11
+ st.session_state.messages = []
12
+
13
+ # Function to display chat messages
14
+ def display_messages():
15
+ for message in st.session_state.messages:
16
+ if message["user"] == "You":
17
+ st.markdown(f"**You:** {message['text']}")
18
+ else:
19
+ st.markdown(f"**Friend:** {message['text']}")
20
+
21
+ # Input area
22
+ with st.form(key="chat_form"):
23
+ user_input = st.text_input("Enter your message:", "")
24
+ submitted = st.form_submit_button("Send")
25
+
26
+ # Handle message submission
27
+ if submitted and user_input.strip():
28
+ # Append user message
29
+ st.session_state.messages.append({"user": "You", "text": user_input})
30
+
31
+ # Simulate a friend response after a short delay
32
+ time.sleep(1)
33
+ friend_response = f"I received: {user_input}"
34
+ st.session_state.messages.append({"user": "Friend", "text": friend_response})
35
+
36
+ # Display chat messages
37
+ display_messages()