Spaces:
Sleeping
Sleeping
File size: 909 Bytes
e06fe15 |
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 27 28 29 30 |
import gradio as gr
from PIL import Image
processor = AutoProcessor.from_pretrained(daliavanilla/BLIP-Radiology-model)
model = BlipForConditionalGeneration.from_pretrained(daliavanilla/BLIP-Radiology-model)
# Define the prediction function
def generate_caption(image):
# Process the image
image = Image.fromarray(image)
#inputs = tokenizer(image, return_tensors="pt")
inputs = processor(images=image, return_tensors="pt")#.to(device)
pixel_values = inputs.pixel_values
# Generate caption
generated_ids = model.generate(pixel_values=pixel_values, max_length=50)
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
return generated_caption
# Define the Gradio interface
interface = gr.Interface(
fn=generate_caption,
inputs=gr.Image(),
outputs=gr.Textbox(),
live=True
)
# Launch the Gradio interface
interface.launch()
|