Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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-base"
|
| 8 |
+
|
| 9 |
+
model = BlipForConditionalGeneration.from_pretrained(model_id)
|
| 10 |
+
processor = BlipProcessor.from_pretrained(model_id)
|
| 11 |
+
|
| 12 |
+
##
|
| 13 |
+
|
| 14 |
+
def launch(input):
|
| 15 |
+
image = Image.open(requests.get(input, stream=True).raw).convert('RGB')
|
| 16 |
+
inputs = processor(image, return_tensors="pt")
|
| 17 |
+
out = model.generate(**inputs)
|
| 18 |
+
return processor.decode(out[0], skip_special_tokens=True)
|
| 19 |
+
|
| 20 |
+
iface = gr.Interface(launch, inputs="text", outputs="text")
|
| 21 |
+
iface.launch()
|