Spaces:
No application file
No application file
Download App.py from mohsin06/Personalchatbot: direct link, hf CLI and curl.
- Browser
- Download file 917 Bytes
-
https://huggingface.co/spaces/mohsin06/Personalchatbot/resolve/main/App.py
- Command line
-
hf download hf://spaces/mohsin06/Personalchatbot/App.py
-
curl -L -o App.py https://huggingface.co/spaces/mohsin06/Personalchatbot/resolve/main/App.py
917 Bytes
| import streamlit as st | |
| from transformers import pipeline | |
| # Load the Hugging Face conversational pipeline | |
| def load_model(): | |
| return pipeline("conversational", model="microsoft/DialoGPT-medium") | |
| # Initialize the bot | |
| chatbot = load_model() | |
| # Streamlit app | |
| st.title("Personal Chatbot") | |
| st.write("Hi! I'm your personal chatbot. Ask me anything!") | |
| # Session state to hold conversation | |
| if "conversation" not in st.session_state: | |
| st.session_state.conversation = None | |
| # User input | |
| user_input = st.text_input("You:", placeholder="Type your message here...") | |
| # Generate and display chatbot response | |
| if st.button("Send") and user_input: | |
| st.session_state.conversation = chatbot(f"User: {user_input}") | |
| for message in st.session_state.conversation.iter_texts(): | |
| if message['author'] == 'bot': | |
| st.text_area("Chatbot:", message['text'], key=f"bot_{user_input}", height=200) | |