Spaces:
Build error
Build error
Download src/streamlit_app.py from Swapnilbpatil/model_do-uplode: direct link, hf CLI and curl.
- Browser
- Download file 910 Bytes
-
https://huggingface.co/spaces/Swapnilbpatil/model_do-uplode/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/Swapnilbpatil/model_do-uplode/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/Swapnilbpatil/model_do-uplode/resolve/main/src/streamlit_app.py
910 Bytes
| import streamlit as st | |
| from langchain_huggingface import ChatHuggingFace, HuggingFacePipeline | |
| import os | |
| # Load model | |
| def load_model(): | |
| llm = HuggingFacePipeline.from_model_id( | |
| model_id='TinyLlama/TinyLlama-1.1B-Chat-v1.0', | |
| task='text-generation', | |
| pipeline_kwargs=dict( | |
| temperature=0.5, | |
| max_new_tokens=100 | |
| ) | |
| ) | |
| return ChatHuggingFace(llm=llm) | |
| model = load_model() | |
| # Streamlit UI | |
| st.set_page_config(page_title="TinyLlama Chatbot", layout="centered") | |
| st.title("🦙 TinyLlama Chatbot") | |
| st.markdown("Ask any question and get an answer using TinyLlama!") | |
| # Input box | |
| user_input = st.text_input("Enter your question here:", "") | |
| # Generate and display answer | |
| if user_input: | |
| with st.spinner("Generating response..."): | |
| response = model.invoke(user_input) | |
| st.success("Response:") | |
| st.write(response.content) | |