Spaces:
Runtime error
Runtime error
File size: 1,193 Bytes
c505b20 d18034e e789fd8 d18034e 867ab4e e789fd8 867ab4e daa9004 c505b20 d18034e c505b20 e789fd8 527d106 c505b20 d18034e 867ab4e d18034e 527d106 d18034e daa9004 d18034e | 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 31 32 33 34 35 36 37 38 39 40 | import streamlit as st
from transformers import pipeline
st.set_page_config(page_title="TinyLlama Chatbot", page_icon="🤖")
@st.cache_resource
def get_chatbot():
return pipeline(
"text-generation",
model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
max_new_tokens=256,
do_sample=True,
temperature=0.7,
top_p=0.9,
)
chatbot = get_chatbot()
st.title("🤖 TinyLlama Chatbot (1.1B)")
st.write("Ask me anything! Powered by Hugging Face Transformers. No API key required.")
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
user_input = st.text_input("You:", key="input")
if st.button("Send") and user_input.strip():
st.session_state.chat_history.append(("You", user_input))
with st.spinner("Thinking..."):
prompt = user_input
response = chatbot(prompt)
bot_output = response[0]["generated_text"][len(prompt):].strip()
st.session_state.chat_history.append(("Bot", bot_output))
st.experimental_rerun()
for speaker, text in st.session_state.chat_history:
if speaker == "You":
st.markdown(f"**You:** {text}")
else:
st.markdown(f"**Bot:** {text}") |