Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,7 @@ model.to(device)
|
|
16 |
processor = AutoProcessor.from_pretrained(model_id)
|
17 |
|
18 |
pipe = pipeline(
|
19 |
-
"
|
20 |
model=model,
|
21 |
tokenizer=processor.tokenizer,
|
22 |
feature_extractor=processor.feature_extractor,
|
@@ -24,20 +24,21 @@ pipe = pipeline(
|
|
24 |
device=device,
|
25 |
)
|
26 |
|
27 |
-
def
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
42 |
|
43 |
-
|
|
|
16 |
processor = AutoProcessor.from_pretrained(model_id)
|
17 |
|
18 |
pipe = pipeline(
|
19 |
+
"text-to-speech",
|
20 |
model=model,
|
21 |
tokenizer=processor.tokenizer,
|
22 |
feature_extractor=processor.feature_extractor,
|
|
|
24 |
device=device,
|
25 |
)
|
26 |
|
27 |
+
def generate_caption_and_speech(input_image):
|
28 |
+
# Generate caption
|
29 |
+
caption = captioner(input_image)[0]['generated_text']
|
30 |
+
|
31 |
+
# Generate speech from caption
|
32 |
+
audio_output = pipe(caption)
|
33 |
+
|
34 |
+
return (np.array(audio_output["audio"]), audio_output["sampling_rate"]), caption
|
35 |
+
|
36 |
+
# Gradio Interface
|
37 |
+
iface = gr.Interface(
|
38 |
+
fn=generate_caption_and_speech,
|
39 |
+
inputs=gr.Image(type='pil', label="Upload Image"),
|
40 |
+
outputs=[gr.Audio(type="numpy", label="Generated Audio"), gr.Textbox(label="Generated Caption")],
|
41 |
+
title="SeeSay",
|
42 |
+
description="Upload an image to generate a caption and hear it described with speech."")
|
43 |
|
44 |
+
iface.launch(share=True)
|