Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,23 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
#
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
gr.Interface.load("models/Salesforce/blip-image-captioning-base").launch()
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
import requests
|
| 3 |
import gradio as gr
|
| 4 |
+
from io import BytesIO
|
| 5 |
|
| 6 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 7 |
|
| 8 |
+
model_id = "Salesforce/blip-image-captioning-base"
|
| 9 |
|
| 10 |
+
model = BlipForConditionalGeneration.from_pretrained(model_id)
|
| 11 |
+
processor = BlipProcessor.from_pretrained(model_id)
|
| 12 |
|
| 13 |
+
def launch(image):
|
| 14 |
+
#image = Image.open(BytesIO(input_image)).convert('RGB')
|
| 15 |
+
inputsData = data.pop("inputs", data)
|
| 16 |
+
# decode base64 image to PIL
|
| 17 |
+
image = Image.open(BytesIO(base64.b64decode(inputsData["image"])))
|
| 18 |
+
inputs = processor(image, return_tensors="pt")
|
| 19 |
+
out = model.generate(**inputs)
|
| 20 |
+
return processor.decode(out[0], skip_special_tokens=True)
|
| 21 |
|
| 22 |
+
iface = gr.Interface(launch, inputs=gr.inputs.Image(), outputs="text")
|
| 23 |
+
iface.launch()
|
|
|
|
|
|