Spaces:
Sleeping
Sleeping
Download app.py from AkashKhatri/Chatbot: direct link, hf CLI and curl.
- Browser
- Download file 922 Bytes
-
https://huggingface.co/spaces/AkashKhatri/Chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/AkashKhatri/Chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AkashKhatri/Chatbot/resolve/main/app.py
922 Bytes
| # streamlit_app.py | |
| import streamlit as st | |
| from chatbot import generate_response | |
| st.title("Chatbot with Hugging Face and Streamlit") | |
| user_id = st.text_input("User ID", value="user1") | |
| user_input = st.text_input("Your message:") | |
| if "chat_history" not in st.session_state: | |
| st.session_state.chat_history = {} | |
| if user_id not in st.session_state.chat_history: | |
| st.session_state.chat_history[user_id] = [] | |
| if st.button("Send"): | |
| if user_input: | |
| response, st.session_state.chat_history[user_id] = generate_response( | |
| user_input, st.session_state.chat_history[user_id] | |
| ) | |
| st.session_state.chat_history[user_id].append((user_input, response)) | |
| st.write("## Chat History") | |
| if user_id in st.session_state.chat_history: | |
| for user_message, bot_response in st.session_state.chat_history[user_id]: | |
| st.write(f"**You:** {user_message}") | |
| st.write(f"**Bot:** {bot_response}") | |