File size: 1,241 Bytes
183ba69 471f43d 4273fa3 471f43d 3a2edfc 471f43d 3a2edfc 471f43d 183ba69 93b333b 183ba69 ab2efba 0a2dd0e 3a2edfc 7ed0992 ab2efba 183ba69 |
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 26 |
import gradio as gr
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
def caption(img, min, max):
raw_image = Image.open(img).convert('RGB')
inputs = processor(raw_image, return_tensors="pt")
out = model.generate(**inputs, min_length=min, max_length=max)
return processor.decode(out[0], skip_special_tokens=True)
def greet(img):
return caption(img)
iface = gr.Interface(fn=greet,
title='Blip Image Captioning Large',
description="[Salesforce/blip-image-captioning-large](https://huggingface.co/Salesforce/blip-image-captioning-large)",
inputs=[gr.Image(type='filepath', label='Image'), gr.Slider(label='Minimum Length', minimum=1, maximum=1000, value=30), gr.Slider(label='Maximum Length', minimum=1, maximum=1000, value=100)],
outputs=gr.Textbox(label='Caption'),
theme = gr.themes.Base(primary_hue="teal",secondary_hue="teal",neutral_hue="slate"),)
iface.launch() |