Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,26 +6,26 @@ pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
|
6 |
|
7 |
narrator = pipeline("text-to-speech", model="kakao-enterprise/vits-ljs")
|
8 |
|
9 |
-
def launch(
|
10 |
-
# Step 1: Extract
|
11 |
-
caption = pipe(input_image)[0][
|
12 |
|
13 |
-
# Step 2:
|
14 |
audio_output = narrator(caption)
|
|
|
|
|
15 |
|
16 |
-
# Step 3:
|
17 |
-
|
18 |
-
sampling_rate = audio_output["sampling_rate"]
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
iface = gr.Interface(launch,
|
24 |
fn=launch,
|
25 |
-
inputs=gr.Image(type='pil'),
|
26 |
-
outputs=
|
|
|
|
|
|
|
27 |
title="SeeSay",
|
28 |
description="Upload an image to hear its context narrated aloud."
|
29 |
-
|
30 |
-
|
31 |
-
iface.launch()
|
|
|
6 |
|
7 |
narrator = pipeline("text-to-speech", model="kakao-enterprise/vits-ljs")
|
8 |
|
9 |
+
def launch(input_image):
|
10 |
+
# Step 1: Extract caption
|
11 |
+
caption = pipe(input_image)[0]["generated_text"]
|
12 |
|
13 |
+
# Step 2: Convert caption to audio
|
14 |
audio_output = narrator(caption)
|
15 |
+
audio_array = np.array(audio_output["audio"])
|
16 |
+
sample_rate = audio_output["sampling_rate"]
|
17 |
|
18 |
+
# Step 3: Return audio + caption
|
19 |
+
return (audio_array, sample_rate), caption
|
|
|
20 |
|
21 |
+
# Use dictionary to avoid conflicting argument ordering
|
22 |
+
iface = gr.Interface(
|
|
|
|
|
23 |
fn=launch,
|
24 |
+
inputs=gr.Image(type='pil', label="Upload Image"),
|
25 |
+
outputs=[
|
26 |
+
gr.Audio(type="numpy", label="Narrated Audio"),
|
27 |
+
gr.Textbox(label="Extracted Caption")
|
28 |
+
],
|
29 |
title="SeeSay",
|
30 |
description="Upload an image to hear its context narrated aloud."
|
31 |
+
)
|
|
|
|