Spaces:
Running
Running
File size: 1,577 Bytes
b6df2f4 e1429a9 b6df2f4 6e6c263 b6df2f4 6e6c263 |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import streamlit as st
import requests
# Configuración de la barra lateral
st.sidebar.title("Inference Provider")
st.sidebar.markdown(
"""
Esta aplicación permite ejecutar inferencias con diferentes modelos usando la API de Hugging Face.
Ingresa tu token y selecciona el modelo que deseas usar.
"""
)
token = st.sidebar.text_input("Token de Hugging Face", type="password")
# Lista de modelos disponibles; puedes agregar o quitar modelos según necesites
model_list = ["Qwen/QwQ-32B", "gpt2", "distilbert-base-uncased"]
model_choice = st.sidebar.selectbox("Selecciona el modelo", model_list)
# Área principal para la inferencia
st.title("Inferencia del Modelo")
prompt = st.text_area("Ingresa tu prompt", "Escribe aquí...")
if st.button("Ejecutar Inferencia"):
if not token:
st.error("Por favor, ingresa tu token de Hugging Face.")
else:
API_URL = f"https://api-inference.huggingface.co/models/{model_choice}"
headers = {"Authorization": f"Bearer {token}"}
payload = {"inputs": prompt}
with st.spinner("Ejecutando inferencia..."):
response = requests.post(API_URL, headers=headers, json=payload)
if response.status_code == 200:
try:
result = response.json()
st.write("Salida:")
st.write(result)
except Exception as e:
st.error("Error al interpretar la respuesta de la API.")
else:
st.error(f"Error {response.status_code}: {response.text}")
|