Spaces:
Sleeping
Sleeping
marcellohalfeld
commited on
Commit
•
f8ad3f6
1
Parent(s):
fe6253c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
from transformers import AutoProcessor, BlipForConditionalGeneration
|
5 |
+
|
6 |
+
processor = # write your code here
|
7 |
+
model = # write your code here
|
8 |
+
|
9 |
+
def caption_image(input_image: np.ndarray):
|
10 |
+
# Convert numpy array to PIL Image and convert to RGB
|
11 |
+
raw_image = Image.fromarray(input_image).convert('RGB')
|
12 |
+
|
13 |
+
# Process the image
|
14 |
+
|
15 |
+
|
16 |
+
# Generate a caption for the image
|
17 |
+
|
18 |
+
|
19 |
+
# Decode the generated tokens to text and store it into `caption`
|
20 |
+
|
21 |
+
|
22 |
+
return caption
|
23 |
+
|
24 |
+
iface = gr.Interface(
|
25 |
+
fn=caption_image,
|
26 |
+
inputs=gr.Image(),
|
27 |
+
outputs="text",
|
28 |
+
title="Image Captioning",
|
29 |
+
description="This is a simple web app for generating captions for images using a trained model."
|
30 |
+
)
|
31 |
+
|
32 |
+
iface = gr.Interface(
|
33 |
+
fn=caption_image,
|
34 |
+
inputs=gr.Image(),
|
35 |
+
outputs="text",
|
36 |
+
title="Image Captioning",
|
37 |
+
description="This is a simple web app for generating captions for images using a trained model."
|
38 |
+
)
|