Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
|
5 |
+
img_text_pipe = pipeline("image-to-text",
|
6 |
+
model="./models/Salesforce/blip-image-captioning-base")
|
7 |
+
|
8 |
+
narrator = pipeline("text-to-speech",
|
9 |
+
model="./models/kakao-enterprise/vits-ljs")
|
10 |
+
|
11 |
+
def describe_image(file_path):
|
12 |
+
|
13 |
+
img_text_pip_output = img_text_pipe(file_path)
|
14 |
+
|
15 |
+
description_text = img_text_pip_output[0]['generated_text']
|
16 |
+
|
17 |
+
narrated_text = narrator(description_text)
|
18 |
+
|
19 |
+
return narrated_text["audio"][0]
|
20 |
+
|
21 |
+
|
22 |
+
iface = gr.Interface(fn=describe_image,
|
23 |
+
inputs=gr.Image(label="Input image",
|
24 |
+
type="pil"),
|
25 |
+
outputs="audio"
|
26 |
+
)
|
27 |
+
iface.launch()
|