Spaces:
Runtime error
Runtime error
File size: 832 Bytes
77fdb73 e6247d9 050589b 8841624 050589b e8f3e6c 050589b e8f3e6c 050589b e6247d9 8841624 e6247d9 6e6af84 77fdb73 050589b 77fdb73 050589b 77fdb73 050589b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 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)
|