Spaces:
Sleeping
Sleeping
File size: 2,909 Bytes
1c744f3 0a50190 04345b7 0a50190 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | import streamlit as st
from datetime import datetime
# App title
st.title("Chat and Call Application")
# Sidebar for navigation
menu = ["Home", "Add Contact", "Chat", "Call"]
choice = st.sidebar.selectbox("Menu", menu)
# Global variables (for simulation)
if 'contacts' not in st.session_state:
st.session_state['contacts'] = {}
if 'chat_history' not in st.session_state:
st.session_state['chat_history'] = {}
# Home page
if choice == "Home":
st.header("Welcome to the Chat and Call App")
st.write("Use the sidebar to navigate between features.")
# Add Contact page
elif choice == "Add Contact":
st.header("Add a New Contact")
with st.form("add_contact_form"):
name = st.text_input("Contact Name")
phone = st.text_input("Phone Number")
submit = st.form_submit_button("Add Contact")
if submit:
if name and phone:
st.session_state['contacts'][name] = phone
st.success(f"Contact {name} added successfully!")
else:
st.error("Please provide both name and phone number.")
# Chat page
elif choice == "Chat":
st.header("Chat with Your Contacts")
if not st.session_state['contacts']:
st.warning("No contacts available. Please add contacts first.")
else:
contact = st.selectbox("Select a Contact", list(st.session_state['contacts'].keys()))
if contact:
st.write(f"Chatting with: {contact}")
chat_key = contact
# Display chat history
if chat_key not in st.session_state['chat_history']:
st.session_state['chat_history'][chat_key] = []
chat_history = st.session_state['chat_history'][chat_key]
for message in chat_history:
st.write(message)
# Input for sending a message
with st.form("send_message_form"):
message = st.text_input("Enter your message")
send = st.form_submit_button("Send")
if send:
if message:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
chat_history.append(f"You ({timestamp}): {message}")
st.session_state['chat_history'][chat_key] = chat_history
st.experimental_rerun()
else:
st.error("Message cannot be empty.")
# Call page
elif choice == "Call":
st.header("Make a Call")
if not st.session_state['contacts']:
st.warning("No contacts available. Please add contacts first.")
else:
contact = st.selectbox("Select a Contact to Call", list(st.session_state['contacts'].keys()))
if contact:
st.write(f"Calling {contact}...")
st.button("End Call", on_click=lambda: st.success(f"Call with {contact} ended."))
|