Spaces:
Sleeping
Sleeping
Upload src/streamlit_app.py with huggingface_hub
Browse files- src/streamlit_app.py +40 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,41 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
st.title("💬 Simple Chatbot")
|
| 6 |
+
|
| 7 |
+
# Initialize chat history
|
| 8 |
+
if "messages" not in st.session_state:
|
| 9 |
+
st.session_state.messages = []
|
| 10 |
+
|
| 11 |
+
# Display chat messages from history on app rerun
|
| 12 |
+
for message in st.session_state.messages:
|
| 13 |
+
with st.chat_message(message["role"]):
|
| 14 |
+
st.markdown(message["content"])
|
| 15 |
+
|
| 16 |
+
# Accept user input
|
| 17 |
+
if prompt := st.chat_input("Type your message..."):
|
| 18 |
+
# Add user message to chat history
|
| 19 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 20 |
+
# Display user message in chat message container
|
| 21 |
+
with st.chat_message("user"):
|
| 22 |
+
st.markdown(prompt)
|
| 23 |
+
|
| 24 |
+
# Generate a simple response
|
| 25 |
+
responses = [
|
| 26 |
+
"Interesting! Tell me more.",
|
| 27 |
+
"I see. Could you elaborate?",
|
| 28 |
+
"That’s a great point!",
|
| 29 |
+
"Thanks for sharing that with me.",
|
| 30 |
+
"Could you clarify what you mean?",
|
| 31 |
+
]
|
| 32 |
+
response = random.choice(responses)
|
| 33 |
+
|
| 34 |
+
# Simulate a short delay
|
| 35 |
+
time.sleep(0.5)
|
| 36 |
+
|
| 37 |
+
# Display assistant response in chat message container
|
| 38 |
+
with st.chat_message("assistant"):
|
| 39 |
+
st.markdown(response)
|
| 40 |
+
# Add assistant response to chat history
|
| 41 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|