Upload 5 files
Browse files- app.py +15 -11
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -43,7 +43,15 @@ def infer_core(image: Image.Image, text: str, max_new_tokens: int = 256, tempera
|
|
| 43 |
out = model.generate(**inputs, max_new_tokens=int(max_new_tokens), temperature=float(temperature))
|
| 44 |
return processor.decode(out[0], skip_special_tokens=True).strip()
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
with gr.Blocks(title="Salamandra Vision 7B · ZeroGPU") as demo:
|
| 48 |
gr.Markdown("## Salamandra-Vision 7B · ZeroGPU\nImagen + texto → descripción.")
|
| 49 |
with gr.Row():
|
|
@@ -55,17 +63,13 @@ with gr.Blocks(title="Salamandra Vision 7B · ZeroGPU") as demo:
|
|
| 55 |
btn = gr.Button("Generar", variant="primary")
|
| 56 |
with gr.Column():
|
| 57 |
out = gr.Textbox(label="Descripción", lines=18)
|
|
|
|
|
|
|
| 58 |
btn.click(infer_core, [in_img, in_txt, max_new, temp], out, api_name="describe")
|
| 59 |
|
| 60 |
-
#
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
@spaces.GPU
|
| 65 |
-
def describe_raw(image: gr.File, text: str = "Describe la imagen con detalle.",
|
| 66 |
-
max_new_tokens: int = 256, temperature: float = 0.7) -> Dict[str, str]:
|
| 67 |
-
img = Image.open(image)
|
| 68 |
-
result = infer_core(img, text, max_new_tokens, temperature)
|
| 69 |
-
return {"text": result}
|
| 70 |
|
| 71 |
demo.queue(concurrency_count=1, max_size=16).launch()
|
|
|
|
| 43 |
out = model.generate(**inputs, max_new_tokens=int(max_new_tokens), temperature=float(temperature))
|
| 44 |
return processor.decode(out[0], skip_special_tokens=True).strip()
|
| 45 |
|
| 46 |
+
|
| 47 |
+
# ---------- Helper for API ----------
|
| 48 |
+
def describe_raw(image: Image.Image, text: str = "Describe la imagen con detalle.",
|
| 49 |
+
max_new_tokens: int = 256, temperature: float = 0.7) -> Dict[str, str]:
|
| 50 |
+
result = infer_core(image, text, max_new_tokens, temperature)
|
| 51 |
+
return {"text": result}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# ---------- UI and API ----------
|
| 55 |
with gr.Blocks(title="Salamandra Vision 7B · ZeroGPU") as demo:
|
| 56 |
gr.Markdown("## Salamandra-Vision 7B · ZeroGPU\nImagen + texto → descripción.")
|
| 57 |
with gr.Row():
|
|
|
|
| 63 |
btn = gr.Button("Generar", variant="primary")
|
| 64 |
with gr.Column():
|
| 65 |
out = gr.Textbox(label="Descripción", lines=18)
|
| 66 |
+
|
| 67 |
+
# Endpoint for UI
|
| 68 |
btn.click(infer_core, [in_img, in_txt, max_new, temp], out, api_name="describe")
|
| 69 |
|
| 70 |
+
# Endpoint for API (no UI)
|
| 71 |
+
demo.load(None, [gr.Image(label="image", type="pil"), gr.Textbox(value="Describe la imagen con detalle."),
|
| 72 |
+
gr.Slider(16, 1024, value=256), gr.Slider(0.0, 1.5, value=0.7)],
|
| 73 |
+
describe_raw, api_name="describe_raw")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
demo.queue(concurrency_count=1, max_size=16).launch()
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# app (ZeroGPU Gradio)
|
| 2 |
-
gradio>=4.44.
|
| 3 |
spaces>=0.25.0
|
| 4 |
transformers>=4.44.0
|
| 5 |
torch>=2.2
|
|
|
|
| 1 |
# app (ZeroGPU Gradio)
|
| 2 |
+
gradio>=4.44.1
|
| 3 |
spaces>=0.25.0
|
| 4 |
transformers>=4.44.0
|
| 5 |
torch>=2.2
|