|
|
|
|
|
import os, requests, streamlit as st
|
|
|
|
|
|
SPACE_URL = os.environ.get("UPSTREAM_SPACE_URL", "https://<usuario>-<space>.hf.space")
|
|
|
|
|
|
st.set_page_config(page_title="Cliente Salamandra (Streamlit)", layout="centered")
|
|
|
st.title("Cliente Salamandra 路 Streamlit")
|
|
|
|
|
|
img = st.file_uploader("Sube una imagen", type=["jpg","jpeg","png"])
|
|
|
prompt = st.text_area("Texto/prompt", "Describe la imagen con detalle (ES/CA).")
|
|
|
cols = st.columns(2)
|
|
|
max_new = cols[0].slider("max_new_tokens", 16, 1024, 256, 16)
|
|
|
temperature = cols[1].slider("temperature", 0.0, 1.5, 0.7, 0.05)
|
|
|
|
|
|
if st.button("Generar") and img is not None:
|
|
|
with st.spinner("Llamando al Space ZeroGPU..."):
|
|
|
url = SPACE_URL.rstrip("/") + "/api/describe_raw"
|
|
|
files = {"image": (img.name, img.getvalue(), "application/octet-stream")}
|
|
|
data = {"text": prompt, "max_new_tokens": str(max_new), "temperature": str(temperature)}
|
|
|
r = requests.post(url, files=files, data=data, timeout=600)
|
|
|
if r.ok:
|
|
|
st.text_area("Descripci贸n", r.json().get("text",""), height=300)
|
|
|
else:
|
|
|
st.error(f"Error {r.status_code}: {r.text}")
|
|
|
|