Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 3 |
from PIL import Image
|
| 4 |
-
|
| 5 |
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 6 |
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 7 |
-
|
| 8 |
def caption_image(image):
|
| 9 |
inputs = processor(images=image, return_tensors="pt")
|
| 10 |
out = model.generate(**inputs)
|
| 11 |
caption = processor.decode(out[0], skip_special_tokens=True)
|
| 12 |
return caption
|
| 13 |
-
|
| 14 |
iface = gr.Interface(
|
| 15 |
fn=caption_image,
|
| 16 |
inputs=gr.Image(type="pil"),
|
|
@@ -18,6 +15,4 @@ iface = gr.Interface(
|
|
| 18 |
title="Image Caption Generator",
|
| 19 |
allow_flagging="never"
|
| 20 |
)
|
| 21 |
-
|
| 22 |
-
iface.queue(api_open=True)
|
| 23 |
-
iface.launch(share=False)
|
|
|
|
| 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"),
|
|
|
|
| 15 |
title="Image Caption Generator",
|
| 16 |
allow_flagging="never"
|
| 17 |
)
|
| 18 |
+
iface.queue(api_open=True).launch(share=False)
|
|
|
|
|
|