Spaces:
Runtime error
Runtime error
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536import ioimport requestsfrom PIL import Imageimport gradio as grfrom transformers import pipeline# Modell betöltése (BLIP image captioning)captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")def caption_from_url(image_url: str) -> str:if not image_url or not image_url.strip():return "Please paste a public direct image URL (jpg/png)."try:r = requests.get(image_url, timeout=15)r.raise_for_status()image = Image.open(io.BytesIO(r.content)).convert("RGB")except Exception as e:return f"Couldn't download/open the image. Check the URL. Error: {e}"try:result = captioner(image)caption = result[0].get("generated_text", "").strip()return caption or "No caption generated."except Exception as e:return f"Model error: {e}"# FONTOS: Spaces-hez elég, ha LÉTEZIK egy Gradio objektum változóban (pl. 'demo').# NEM kell .launch()-t hívni.demo = gr.Interface(fn=caption_from_url,inputs=gr.Textbox(label="Image URL (public, direct)", placeholder="https://.../image.jpg"),outputs=gr.Textbox(label="Caption"),title="MediGlowX – Image Caption",description="Paste a public JPG/PNG image URL. We do not store the image; it's used only for processing.")
app.py+36