Student3331 commited on
Commit
9f2d6d4
·
verified ·
1 Parent(s): ea011a8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ # Predefined set of questions and responses
4
+ responses = {
5
+ 'hello': "Hi there! How can I assist you today?",
6
+ 'hi': "Hello! How can I help you today?",
7
+ 'how are you': "I'm doing great, thank you for asking! How about you?",
8
+ 'what is your name': "I’m Chatbot, your friendly virtual assistant!",
9
+ 'tell me the weather today': "I don’t have access to live data, but I suggest checking your local weather service for accurate updates!",
10
+ 'what time is it': "Sorry, I can't tell the time, but you can check your device's clock.",
11
+ 'bye': "Goodbye! Have a wonderful day!",
12
+ 'thanks': "You're welcome! If you need anything else, feel free to ask.",
13
+ 'how old are you': "I'm ageless! I was created to assist you whenever you need.",
14
+ 'what can you do': "I can help with simple questions like greetings, weather, and more. Try asking me something!",
15
+ }
16
+
17
+ # Function to handle user input and provide chatbot responses
18
+ def get_response(user_input):
19
+ user_input = user_input.lower()
20
+ return responses.get(user_input, "Sorry, I didn't understand that. Can you ask something else?")
21
+
22
+ # Streamlit UI setup
23
+ st.title("Chat with Chatbot!")
24
+ st.markdown("Ask me anything, and I'll do my best to answer.")
25
+
26
+ # Create a chat interface
27
+ if 'history' not in st.session_state:
28
+ st.session_state['history'] = []
29
+
30
+ # Collect user input
31
+ user_input = st.text_input("You: ")
32
+
33
+ # Process user input and generate response
34
+ if user_input:
35
+ # Add user message to history
36
+ st.session_state['history'].append(f"You: {user_input}")
37
+
38
+ # Get the bot's response based on input
39
+ bot_response = get_response(user_input)
40
+
41
+ # Add bot's response to history
42
+ st.session_state['history'].append(f"Chatbot: {bot_response}")
43
+
44
+ # Display the chat history
45
+ for message in st.session_state['history']:
46
+ st.write(message)
47
+