Spaces:
Running
Running
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): | |
try: | |
# 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 | |
except Exception as e: | |
return f"Error generating caption: {e}" | |
# 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(share=True) # Set share=True to enable public link if needed | |