Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
|
| 4 |
-
# Load model directly
|
| 5 |
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 6 |
|
|
|
|
| 7 |
processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 8 |
model = AutoModelForImageTextToText.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 9 |
|
| 10 |
-
|
| 11 |
def caption(image):
|
| 12 |
-
|
|
|
|
| 13 |
out = model.generate(**inputs)
|
| 14 |
-
|
| 15 |
return processor.decode(out[0], skip_special_tokens=True)
|
| 16 |
|
| 17 |
demo = gr.Interface(
|
| 18 |
-
fn
|
| 19 |
-
inputs
|
| 20 |
-
outputs
|
| 21 |
)
|
| 22 |
|
| 23 |
-
demo.launch(
|
| 24 |
-
server_port=int(os.environ['PORT1']))
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
|
|
|
| 3 |
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 4 |
|
| 5 |
+
# Load model and processor
|
| 6 |
processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 7 |
model = AutoModelForImageTextToText.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 8 |
|
|
|
|
| 9 |
def caption(image):
|
| 10 |
+
# 'image' is now a PIL Image object because of type="pil"
|
| 11 |
+
inputs = processor(image, return_tensors="pt")
|
| 12 |
out = model.generate(**inputs)
|
|
|
|
| 13 |
return processor.decode(out[0], skip_special_tokens=True)
|
| 14 |
|
| 15 |
demo = gr.Interface(
|
| 16 |
+
fn=caption,
|
| 17 |
+
inputs=gr.Image(label="Upload Image", type="pil"),
|
| 18 |
+
outputs="text"
|
| 19 |
)
|
| 20 |
|
| 21 |
+
demo.launch()
|
|
|