Spaces:
Sleeping
Sleeping
Commit
·
2836ad6
1
Parent(s):
d2fd455
add code for inference with BlipForConditionalGeneration
Browse files- app.py +17 -3
- requirements.txt +2 -0
app.py
CHANGED
@@ -1,7 +1,21 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import requests
|
4 |
|
5 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
|
|
6 |
|
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(input):
|
14 |
+
image = Image.open(requests.get(input, stream=True).raw).convert('RGB')
|
15 |
+
inputs = processor(image, return_tensors="pt")
|
16 |
+
out = model.generate(**inputs)
|
17 |
+
return processor.decode(out[0], skip_special_tokens=True)
|
18 |
+
|
19 |
+
|
20 |
+
iface = gr.Interface(launch, inputs="text", outputs="text")
|
21 |
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
git+https://github.com/huggingface/transformers.git@main
|
2 |
+
torch
|