Dileep7729's picture
Create app.py
5c4e8e0 verified
raw
history blame
1.12 kB
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()