Dileep7729
commited on
Upload 2 files
Browse files- README (2).md +14 -0
- app.py +35 -0
README (2).md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Image Upload Model
|
3 |
+
emoji: 📚
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: blue
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.5.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
short_description: '"Upload an image to get model-generated results via an API"'
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
try:
|
13 |
+
# Convert the image into the required format for the model
|
14 |
+
inputs = processor(image, return_tensors="pt")
|
15 |
+
|
16 |
+
# Generate caption
|
17 |
+
outputs = model.generate(**inputs)
|
18 |
+
caption = processor.decode(outputs[0], skip_special_tokens=True)
|
19 |
+
return caption
|
20 |
+
except Exception as e:
|
21 |
+
return f"Error generating caption: {e}"
|
22 |
+
|
23 |
+
# Set up Gradio interface for image upload and caption generation
|
24 |
+
interface = gr.Interface(
|
25 |
+
fn=generate_caption,
|
26 |
+
inputs=gr.Image(type="pil"), # Accepts uploaded images
|
27 |
+
outputs="text", # Displays the caption as text
|
28 |
+
title="Image Captioning Model",
|
29 |
+
description="Upload an image to receive a caption generated by the model."
|
30 |
+
)
|
31 |
+
|
32 |
+
# Launch the Gradio app
|
33 |
+
if __name__ == "__main__":
|
34 |
+
interface.launch(share=True) # Set share=True to enable public link if needed
|
35 |
+
|