Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,11 @@
|
|
| 1 |
-
from PIL import Image
|
| 2 |
-
import requests
|
| 3 |
import gradio as gr
|
| 4 |
-
|
| 5 |
-
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 6 |
|
| 7 |
model_id = "Salesforce/blip-image-captioning-large"
|
| 8 |
-
|
| 9 |
-
model = BlipForConditionalGeneration.from_pretrained(model_id)
|
| 10 |
-
processor = BlipProcessor.from_pretrained(model_id)
|
| 11 |
|
| 12 |
def launch(input):
|
| 13 |
-
|
| 14 |
-
inputs = processor(image, return_tensors="pt")
|
| 15 |
-
out = model.generate(**inputs)
|
| 16 |
-
return processor.decode(out[0], skip_special_tokens=True)
|
| 17 |
|
| 18 |
-
iface = gr.Interface(launch, inputs="
|
| 19 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
model_id = "Salesforce/blip-image-captioning-large"
|
| 5 |
+
captioner = pipeline(model=model_id)
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def launch(input):
|
| 8 |
+
return captioner(input)
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
iface = gr.Interface(launch, inputs="pil", outputs="text")
|
| 11 |
iface.launch()
|