Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
+
|
4 |
+
def get_speech(text, voice):
|
5 |
+
try:
|
6 |
+
client = Client("https://collabora-whisperspeech.hf.space/")
|
7 |
+
result = client.predict(
|
8 |
+
text, # str in 'Enter multilingual text💬📝' Textbox component
|
9 |
+
voice, # filepath in 'Upload or Record Speaker Audio (optional)🌬️💬' Audio component
|
10 |
+
"", # str in 'alternatively, you can paste in an audio file URL:' Textbox component
|
11 |
+
14, # float (numeric value between 10 and 15) in 'Tempo (in characters per second)' Slider component
|
12 |
+
api_name="/whisper_speech_demo"
|
13 |
+
)
|
14 |
+
print(result)
|
15 |
+
return result
|
16 |
+
except ValueError as e:
|
17 |
+
raise gr.Error(f"Error in get_speech: {str(e)}")
|
18 |
+
|
19 |
+
def get_dreamtalk(image_in, speech):
|
20 |
+
try:
|
21 |
+
client = Client("https://fffiloni-dreamtalk.hf.space/")
|
22 |
+
result = client.predict(
|
23 |
+
speech, # filepath in 'Audio input' Audio component
|
24 |
+
image_in, # filepath in 'Image' Image component
|
25 |
+
"M030_front_neutral_level1_001.mat", # Literal in 'emotional style' Dropdown component
|
26 |
+
api_name="/infer"
|
27 |
+
)
|
28 |
+
print(result)
|
29 |
+
return result['video']
|
30 |
+
except ValueError as e:
|
31 |
+
raise gr.Error(f"Error in get_dreamtalk: {str(e)}")
|
32 |
+
|
33 |
+
def pipe(text, voice, image_in):
|
34 |
+
try:
|
35 |
+
speech = get_speech(text, voice)
|
36 |
+
video = get_dreamtalk(image_in, speech)
|
37 |
+
return video
|
38 |
+
except Exception as e:
|
39 |
+
raise gr.Error(f"An error occurred while processing: {str(e)}")
|
40 |
+
|
41 |
+
with gr.Blocks() as demo:
|
42 |
+
with gr.Column():
|
43 |
+
gr.HTML("""
|
44 |
+
<h1 style="text-align: center;">
|
45 |
+
Talking Image
|
46 |
+
</h1>
|
47 |
+
<p style="text-align: center;"></p>
|
48 |
+
<h3 style="text-align: center;">
|
49 |
+
Clone your voice and make your photos speak.
|
50 |
+
</h3>
|
51 |
+
<p style="text-align: center;"></p>
|
52 |
+
""")
|
53 |
+
with gr.Row():
|
54 |
+
with gr.Column():
|
55 |
+
image_in = gr.Image(label="Portrait IN", type="filepath", value="./creatus.jpg")
|
56 |
+
with gr.Column():
|
57 |
+
voice = gr.Audio(type="filepath", label="Upload or Record Speaker audio (Optional voice cloning)")
|
58 |
+
text = gr.Textbox(label="text")
|
59 |
+
submit_btn = gr.Button('Submit')
|
60 |
+
with gr.Column():
|
61 |
+
video_o = gr.Video(label="Video result")
|
62 |
+
submit_btn.click(
|
63 |
+
fn=pipe,
|
64 |
+
inputs=[text, voice, image_in],
|
65 |
+
outputs=[video_o],
|
66 |
+
concurrency_limit=3
|
67 |
+
)
|
68 |
+
demo.queue(max_size=10).launch(show_error=True, show_api=False)
|