Spaces:
Sleeping
Sleeping
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() | |