Spaces:
Sleeping
Sleeping
File size: 814 Bytes
473cd7a 2c1c357 473cd7a |
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 torch
from transformers import pipeline
from PIL import Image
import gradio as gr
import os
# Specify the device (CPU or GPU)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Load the image-to-text pipeline
caption_image = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large", device=device)
# List of local image paths
example_images = ["flower.jpg"]
# Function to process the image
def process_image(image):
caption = caption_image(image)[0]['generated_text']
return caption
# Create Gradio interface with example images
iface = gr.Interface(
fn=process_image,
inputs=gr.Image(type="pil"),
outputs=gr.Textbox(label="Generated Caption"),
examples=example_images # Use local images as examples
)
# Launch the interface
iface.launch() |