model_do-uplode / src /streamlit_app.py
Swapnilbpatil's picture
Update src/streamlit_app.py
23a7d6f verified
Raw History Blame Contribute Delete
910 Bytes
import streamlit as st
from langchain_huggingface import ChatHuggingFace, HuggingFacePipeline
import os
# Load model
@st.cache_resource
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)