Spaces:
Running
Running
Dileep7729
commited on
Commit
•
5c4e8e0
1
Parent(s):
d8b1087
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from PIL import Image
|
4 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
5 |
+
|
6 |
+
# Load your model and processor
|
7 |
+
processor = BlipProcessor.from_pretrained("quadranttechnologies/Dileep_model")
|
8 |
+
model = BlipForConditionalGeneration.from_pretrained("quadranttechnologies/Dileep_model")
|
9 |
+
|
10 |
+
# Define a function to generate captions for the uploaded image
|
11 |
+
def generate_caption(image):
|
12 |
+
# Convert the image into the required format for the model
|
13 |
+
inputs = processor(image, return_tensors="pt")
|
14 |
+
|
15 |
+
# Generate caption
|
16 |
+
outputs = model.generate(**inputs)
|
17 |
+
caption = processor.decode(outputs[0], skip_special_tokens=True)
|
18 |
+
return caption
|
19 |
+
|
20 |
+
# Set up Gradio interface for image upload and caption generation
|
21 |
+
interface = gr.Interface(
|
22 |
+
fn=generate_caption,
|
23 |
+
inputs=gr.Image(type="pil"), # Accepts uploaded images
|
24 |
+
outputs="text", # Displays the caption as text
|
25 |
+
title="Image Captioning Model",
|
26 |
+
description="Upload an image to receive a caption generated by the model."
|
27 |
+
)
|
28 |
+
|
29 |
+
# Launch the Gradio app
|
30 |
+
if __name__ == "__main__":
|
31 |
+
interface.launch()
|