alexgenovese's picture
Update app.py
64a1867 verified
raw
history blame contribute delete
607 Bytes
from PIL import Image
import requests
import gradio as gr
from transformers import BlipProcessor, Blip2ForConditionalGeneration
model_id = "Salesforce/blip2-flan-t5-xl"
processor = BlipProcessor.from_pretrained(model_id)
model = Blip2ForConditionalGeneration.from_pretrained(model_id)
def launch(input):
image = Image.open(requests.get(input, stream=True).raw).convert('RGB')
inputs = processor(image, return_tensors="pt")
out = model.generate(**inputs)
return processor.decode(out[0], skip_special_tokens=True)
iface = gr.Interface(launch, inputs="text", outputs="text")
iface.launch()