|
import gradio as gr |
|
import requests |
|
from PIL import Image |
|
from transformers import BlipProcessor, BlipForConditionalGeneration |
|
|
|
|
|
processor = BlipProcessor.from_pretrained("quadranttechnologies/Dileep_model") |
|
model = BlipForConditionalGeneration.from_pretrained("quadranttechnologies/Dileep_model") |
|
|
|
|
|
def generate_caption(image): |
|
try: |
|
|
|
inputs = processor(image, return_tensors="pt") |
|
|
|
|
|
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}" |
|
|
|
|
|
interface = gr.Interface( |
|
fn=generate_caption, |
|
inputs=gr.Image(type="pil"), |
|
outputs="text", |
|
title="Image Captioning Model", |
|
description="Upload an image to receive a caption generated by the model." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch(share=True) |
|
|
|
|