Spaces:
Sleeping
Sleeping
Download app.py from a7madmostafa/image-caption2: direct link, hf CLI and curl.
- Browser
- Download file 609 Bytes
-
https://huggingface.co/spaces/a7madmostafa/image-caption2/resolve/main/app.py
- Command line
-
hf download hf://spaces/a7madmostafa/image-caption2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/a7madmostafa/image-caption2/resolve/main/app.py
609 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| pipe = pipeline( | |
| "image-to-text", | |
| model="Salesforce/blip-image-captioning-base" | |
| ) | |
| def caption_image(image): | |
| if image is None: | |
| return "Please upload an image." | |
| result = pipe(image) | |
| return result[0]["generated_text"] | |
| demo = gr.Interface( | |
| fn=caption_image, | |
| inputs=gr.Image(type="pil", label="Upload Image"), | |
| outputs=gr.Textbox(label="Generated Caption"), | |
| title="Image Captioning App", | |
| description="Upload an image and the BLIP model will generate a caption." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |