yousifalishah's picture
Update app.py
050589b verified
raw
history blame contribute delete
832 Bytes
import streamlit as st
from transformers import pipeline
from huggingface_hub import login
# βœ… Retrieve API token securely
try:
HF_TOKEN = st.secrets["huggingface"]["api_token"]
login(HF_TOKEN) # Log in to Hugging Face Hub
except Exception:
st.error("❌ Missing or invalid Hugging Face API token. Please check secrets.toml.")
st.stop()
# βœ… Load the model
@st.cache_resource
def load_model():
return pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1", token=HF_TOKEN)
model = load_model()
# Streamlit UI
st.title("πŸ€– AI Developer Assistant")
st.write("A chatbot powered by Mistral-7B!")
user_input = st.text_input("You:")
if st.button("Send"):
if user_input:
response = model(user_input, max_length=100, do_sample=True)[0]['generated_text']
st.write(response)