Spaces:
Running
Running
prithivMLmods
commited on
Commit
β’
59a3ada
1
Parent(s):
8a0e250
Upload 3 files
Browse files- README.md +14 -0
- app.py +72 -0
- requirements.txt +8 -0
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: EDGE TTS
|
3 |
+
emoji: π
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: green
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.9.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: creativeml-openrail-m
|
11 |
+
short_description: Answer in speech
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import re
|
3 |
+
import gradio as gr
|
4 |
+
import edge_tts
|
5 |
+
import asyncio
|
6 |
+
import time
|
7 |
+
import tempfile
|
8 |
+
from huggingface_hub import InferenceClient
|
9 |
+
|
10 |
+
css= '''
|
11 |
+
#important{
|
12 |
+
display: none;
|
13 |
+
}
|
14 |
+
'''
|
15 |
+
DESCRIPTION = """## EDGE TTS
|
16 |
+
"""
|
17 |
+
|
18 |
+
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
19 |
+
|
20 |
+
system_instructions = "[INST] Answers by π, Keep conversation very short, clear, friendly and concise."
|
21 |
+
|
22 |
+
async def generate(prompt):
|
23 |
+
generate_kwargs = dict(
|
24 |
+
temperature=0.6,
|
25 |
+
max_new_tokens=256,
|
26 |
+
top_p=0.95,
|
27 |
+
repetition_penalty=1,
|
28 |
+
do_sample=True,
|
29 |
+
seed=42,
|
30 |
+
)
|
31 |
+
formatted_prompt = system_instructions + prompt + "[/INST]"
|
32 |
+
stream = client.text_generation(
|
33 |
+
formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
34 |
+
output = ""
|
35 |
+
for response in stream:
|
36 |
+
output += response.token.text
|
37 |
+
|
38 |
+
communicate = edge_tts.Communicate(output)
|
39 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
40 |
+
tmp_path = tmp_file.name
|
41 |
+
await communicate.save(tmp_path)
|
42 |
+
yield tmp_path
|
43 |
+
|
44 |
+
with gr.Blocks(css=css) as demo:
|
45 |
+
gr.Markdown(DESCRIPTION)
|
46 |
+
with gr.Row():
|
47 |
+
user_input = gr.Textbox(label="Prompt")
|
48 |
+
input_text = gr.Textbox(label="Input Text", elem_id="important")
|
49 |
+
output_audio = gr.Audio(label="Audio", type="filepath",
|
50 |
+
interactive=False,
|
51 |
+
autoplay=True,
|
52 |
+
elem_classes="audio")
|
53 |
+
with gr.Row():
|
54 |
+
translate_btn = gr.Button("Response")
|
55 |
+
translate_btn.click(fn=generate, inputs=user_input,
|
56 |
+
outputs=output_audio, api_name="translate")
|
57 |
+
|
58 |
+
# Add examples
|
59 |
+
gr.Examples(
|
60 |
+
examples=[
|
61 |
+
["What is AI?"],
|
62 |
+
["Add 2*3345"],
|
63 |
+
["Describe Mt. Everest"]
|
64 |
+
],
|
65 |
+
inputs=user_input,
|
66 |
+
outputs=output_audio,
|
67 |
+
fn=generate,
|
68 |
+
cache_examples=True
|
69 |
+
)
|
70 |
+
|
71 |
+
if __name__ == "__main__":
|
72 |
+
demo.queue(max_size=20).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
edge-tts
|
2 |
+
gradio
|
3 |
+
asyncio
|
4 |
+
transformers
|
5 |
+
torch
|
6 |
+
audiosegment
|
7 |
+
scipy
|
8 |
+
librosa
|