Download app.py from Anandhu-Jayan/Image-captioning-api-3: direct link, hf CLI and curl.
- Browser
- Download file 672 Bytes
-
https://huggingface.co/spaces/Anandhu-Jayan/Image-captioning-api-3/resolve/main/app.py
- Command line
-
hf download hf://spaces/Anandhu-Jayan/Image-captioning-api-3/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Anandhu-Jayan/Image-captioning-api-3/resolve/main/app.py
672 Bytes
| import io | |
| import os | |
| import requests | |
| from PIL import Image | |
| from model import get_caption_model, generate_caption | |
| import gradio as gr | |
| def get_model(): | |
| return get_caption_model() | |
| caption_model = get_model() | |
| def predict(): | |
| captions = [] | |
| pred_caption = generate_caption('tmp.jpg', caption_model) | |
| captions.append(pred_caption) | |
| return captions; | |
| def launch(inputs): | |
| img = Image.open(requests.get(inputs, stream=True).raw) | |
| img = img.convert('RGB') | |
| img.save('tmp.jpg') | |
| predictedCaption=predict() | |
| os.remove('tmp.jpg') | |
| return predictedCaption[0] | |
| iface = gr.Interface(launch, inputs="text", outputs="text",) | |
| iface.launch(debug=True,) | |