uzmi-ui / main.py
Rajan Singh
Add safe version of main.py
5cc30ef
raw
history blame contribute delete
710 Bytes
import streamlit as st
import requests
import os
st.title("My Hugging Face Model Interface")
input_text = st.text_area("Enter your text:", "")
HF_TOKEN = os.getenv("HF_TOKEN") # Loaded from Hugging Face Secrets
if st.button("Get Prediction") and input_text:
headers = {"Authorization": f"Bearer {HF_TOKEN}"} if HF_TOKEN else {}
response = requests.post(
"https://api-inference.huggingface.co/models/rajan3208/uzmi-gpt",
headers=headers,
json={"inputs": input_text}
)
if response.status_code == 200:
st.success("Prediction:")
st.write(response.json()[0]['generated_text'])
else:
st.error(f"Error {response.status_code}: {response.text}")