Spaces:
Running
Running
File size: 1,123 Bytes
5c4e8e0 |
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 31 32 |
import gradio as gr
import requests
from PIL import Image
from transformers import BlipProcessor, BlipForConditionalGeneration
# Load your model and processor
processor = BlipProcessor.from_pretrained("quadranttechnologies/Dileep_model")
model = BlipForConditionalGeneration.from_pretrained("quadranttechnologies/Dileep_model")
# Define a function to generate captions for the uploaded image
def generate_caption(image):
# Convert the image into the required format for the model
inputs = processor(image, return_tensors="pt")
# Generate caption
outputs = model.generate(**inputs)
caption = processor.decode(outputs[0], skip_special_tokens=True)
return caption
# Set up Gradio interface for image upload and caption generation
interface = gr.Interface(
fn=generate_caption,
inputs=gr.Image(type="pil"), # Accepts uploaded images
outputs="text", # Displays the caption as text
title="Image Captioning Model",
description="Upload an image to receive a caption generated by the model."
)
# Launch the Gradio app
if __name__ == "__main__":
interface.launch()
|