File size: 1,180 Bytes
e8b40b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# clients/streamlit_client_app.py
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}")