lolo / app.py
nightprogrammer's picture
Update app.py
e789fd8 verified
Raw History Blame Contribute Delete
1.19 kB
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}")