Spaces:
Runtime error
Runtime error
Download app.py from nightprogrammer/lolo: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/nightprogrammer/lolo/resolve/main/app.py
- Command line
-
hf download hf://spaces/nightprogrammer/lolo/app.py
-
curl -L -o app.py https://huggingface.co/spaces/nightprogrammer/lolo/resolve/main/app.py
1.19 kB
| import streamlit as st | |
| from transformers import pipeline | |
| st.set_page_config(page_title="TinyLlama Chatbot", page_icon="🤖") | |
| 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}") |