Spaces:
Runtime error
Runtime error
File size: 931 Bytes
e192eff 3668ad1 e192eff 3668ad1 2b1f45e e192eff 3668ad1 e192eff 3668ad1 e192eff 3668ad1 e192eff 3668ad1 e192eff 3668ad1 e192eff 3668ad1 | 1 2 3 4 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 | import streamlit as st
from transformers import pipeline
# Set up chatbot pipeline (you can change the model)
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium", cache_dir="/app/cache")
st.title("Simple Chatbot")
st.write("Chat with an AI below:")
# Session state to store the chat history
if "history" not in st.session_state:
st.session_state.history = []
# User input
user_input = st.text_input("You:", key="input")
if st.button("Send"):
if user_input:
st.session_state.history.append(f"You: {user_input}")
# Get response from model
response = chatbot(user_input, max_length=100, pad_token_id=50256)[0]["generated_text"]
reply = response.split(user_input)[-1].strip()
st.session_state.history.append(f"Bot: {reply}")
else:
st.warning("Please enter a message.")
# Display conversation
for line in st.session_state.history:
st.write(line) |