import streamlit as st from transformers import pipeline # Load the Hugging Face conversational pipeline @st.cache_resource 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)