taras-sereda commited on
Commit
fcfc5d9
1 Parent(s): 06e545a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """PUBLIC
2
+ Simple demo app.
3
+
4
+ Copyright PolyAI Limited.
5
+ """
6
+ import time
7
+ from pathlib import Path
8
+
9
+ import gradio as gr
10
+
11
+ from transformer_infer import PhemeClient, parse_arguments
12
+
13
+ # TODO
14
+ VOICE_OPTIONS = [
15
+ "male_voice",
16
+ "POD1000000004_S0000246",
17
+ "POD1000000018_S0000253",
18
+ "POD1000000048_S0000035",
19
+ "YOU1000000006_S0000051",
20
+ "YOU1000000044_S0000798",
21
+ "empress",
22
+ ]
23
+
24
+ args = parse_arguments()
25
+ model = PhemeClient(args)
26
+
27
+
28
+ def inference(
29
+ text,
30
+ voice,
31
+ top_k,
32
+ temperature
33
+ ):
34
+ with open("PhemeVoice.log", "a") as f:
35
+ f.write(f"{voice}: {text} \n")
36
+ start_time = time.time()
37
+
38
+ data = model.infer(
39
+ text, voice, top_k=top_k, temperature=temperature)
40
+ samplerate = 16_000
41
+ print("Time taken: ", time.time() - start_time)
42
+ yield (samplerate, data)
43
+
44
+
45
+ def main():
46
+ title = "Pheme"
47
+ description = """Model can generate a variety of conversational voices."""
48
+ text = gr.Textbox(
49
+ lines=3,
50
+ value="Our property has several wedding venues.",
51
+ label="Text",
52
+ )
53
+
54
+ voice = gr.Dropdown(
55
+ VOICE_OPTIONS, value="empress", label="Select voice:", type="value"
56
+ )
57
+ temperature = gr.Slider(minimum=.3, maximum=1.5, value=0.7, step=0.05)
58
+ top_k = gr.Slider(minimum=10, maximum=250, value=210)
59
+ output_audio = gr.Audio(label="audio:", autoplay=True)
60
+ interface = gr.Interface(
61
+ fn=inference,
62
+ inputs=[
63
+ text,
64
+ voice,
65
+ top_k,
66
+ temperature,
67
+ ],
68
+ title=title,
69
+ description=description,
70
+ outputs=[output_audio],
71
+ )
72
+ interface.queue().launch(share=True)
73
+
74
+
75
+ if __name__ == "__main__":
76
+ main()