Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 3 |
from PIL import Image
|
|
|
|
|
|
|
| 4 |
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 5 |
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
|
|
|
|
|
|
| 6 |
def caption_image(image):
|
| 7 |
inputs = processor(images=image, return_tensors="pt")
|
| 8 |
out = model.generate(**inputs)
|
| 9 |
caption = processor.decode(out[0], skip_special_tokens=True)
|
| 10 |
return caption
|
|
|
|
|
|
|
| 11 |
iface = gr.Interface(
|
| 12 |
fn=caption_image,
|
| 13 |
inputs=gr.Image(type="pil"),
|
| 14 |
outputs="text",
|
| 15 |
title="Image Caption Generator",
|
| 16 |
-
flagging_mode="never"
|
|
|
|
|
|
|
| 17 |
)
|
| 18 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 3 |
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Load processor and model
|
| 6 |
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 7 |
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 8 |
+
|
| 9 |
+
# Captioning function
|
| 10 |
def caption_image(image):
|
| 11 |
inputs = processor(images=image, return_tensors="pt")
|
| 12 |
out = model.generate(**inputs)
|
| 13 |
caption = processor.decode(out[0], skip_special_tokens=True)
|
| 14 |
return caption
|
| 15 |
+
|
| 16 |
+
# Interface
|
| 17 |
iface = gr.Interface(
|
| 18 |
fn=caption_image,
|
| 19 |
inputs=gr.Image(type="pil"),
|
| 20 |
outputs="text",
|
| 21 |
title="Image Caption Generator",
|
| 22 |
+
flagging_mode="never",
|
| 23 |
+
# 👇 api_name define karna zaroori hai
|
| 24 |
+
examples=None
|
| 25 |
)
|
| 26 |
+
|
| 27 |
+
# Queue for API & launch
|
| 28 |
+
iface.queue(api_open=True).launch(share=True)
|