Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 11 |
|
| 12 |
def caption(image):
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
demo = gr.Interface(
|
| 17 |
fn = caption,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
from transformers import BlipForConditionalGeneration
|
| 5 |
+
from transformers import AutoProcessor
|
| 6 |
+
|
| 7 |
+
model = BlipForConditionalGeneration.from_pretrained(
|
| 8 |
+
"./models/Salesforce/blip-image-captioning-base")
|
| 9 |
+
processor = AutoProcessor.from_pretrained(
|
| 10 |
+
"./models/Salesforce/blip-image-captioning-base")
|
| 11 |
|
|
|
|
| 12 |
|
| 13 |
def caption(image):
|
| 14 |
+
inputs = processor(image,return_tensors="pt")
|
| 15 |
+
out = model.generate(**inputs)
|
| 16 |
+
|
| 17 |
+
return processor.decode(out[0], skip_special_tokens=True)
|
| 18 |
|
| 19 |
demo = gr.Interface(
|
| 20 |
fn = caption,
|