File size: 795 Bytes
c37097e
 
 
 
5d88e42
c37097e
 
 
 
 
 
 
 
ce487ea
f23e620
ce487ea
 
2477b23
ce487ea
 
c37097e
ec4ea82
56aa136
fbfd467
c37097e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from PIL import Image
import requests
import gradio as gr


from transformers import BlipProcessor, BlipForConditionalGeneration

model_id = "Salesforce/blip-image-captioning-base"

model = BlipForConditionalGeneration.from_pretrained(model_id)
processor = BlipProcessor.from_pretrained(model_id)

def launch(input):
    outputs = []
    for file in input:
        inputs = processor(Image.open(file.name), return_tensors="pt")
        out = model.generate(**inputs)            
        outputs.append(processor.decode(out[0], skip_special_tokens=True))

    return outputs

description = "Simple BLIP image captioning app that supports multiple images as input."

iface = gr.Interface(launch, description=description, inputs=gr.inputs.File(file_count="multiple"), outputs="text")
iface.launch()