|
|
import streamlit as st |
|
|
from transformers import pipeline |
|
|
from huggingface_hub import login |
|
|
|
|
|
|
|
|
try: |
|
|
HF_TOKEN = st.secrets["huggingface"]["api_token"] |
|
|
login(HF_TOKEN) |
|
|
except Exception: |
|
|
st.error("β Missing or invalid Hugging Face API token. Please check secrets.toml.") |
|
|
st.stop() |
|
|
|
|
|
|
|
|
@st.cache_resource |
|
|
def load_model(): |
|
|
return pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1", token=HF_TOKEN) |
|
|
|
|
|
model = load_model() |
|
|
|
|
|
|
|
|
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) |
|
|
|