Spaces:
Running
Running
Freddy Boulton
commited on
Commit
·
667be37
1
Parent(s):
11c7580
Add code
Browse files- README.md +2 -0
- app.py +61 -0
- requirements.txt +1 -0
README.md
CHANGED
@@ -9,6 +9,8 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
license: mit
|
11 |
short_description: Use Dia tts model through HF Inference
|
|
|
|
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
9 |
pinned: false
|
10 |
license: mit
|
11 |
short_description: Use Dia tts model through HF Inference
|
12 |
+
hf_oauth_scopes:
|
13 |
+
- inference-api
|
14 |
---
|
15 |
|
16 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import httpx
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
from gradio_dialogue import Dialogue
|
5 |
+
|
6 |
+
emotions = ["(laughs)", "(clears throat)", "(sighs)", "(gasps)", "(coughs)", "(singing)", "(sings)", "(mumbles)", "(beep)", "(groans)", "(sniffs)", "(claps)", "(screams)", "(inhales)", "(exhales)", "(applause)", "(burps)", "(humming)", "(sneezes)", "(chuckle)", "(whistles)"]
|
7 |
+
speakers = ["Speaker 1", "Speaker 2"]
|
8 |
+
|
9 |
+
client = httpx.AsyncClient(timeout=180)
|
10 |
+
|
11 |
+
|
12 |
+
async def query(dialogue: str, token: gr.OAuthToken | None):
|
13 |
+
if token is None:
|
14 |
+
raise gr.Error("No token provided. Use Sign in with Hugging Face to get a token.")
|
15 |
+
API_URL = "https://router.huggingface.co/fal-ai/fal-ai/dia-tts"
|
16 |
+
headers = {
|
17 |
+
"Authorization": f"Bearer {token.token}",
|
18 |
+
}
|
19 |
+
response = await client.post(API_URL, headers=headers, json={"text": dialogue})
|
20 |
+
url = response.json()["audio"]["url"]
|
21 |
+
print("URL: ", url)
|
22 |
+
return url
|
23 |
+
|
24 |
+
def formatter(speaker, text):
|
25 |
+
speaker = speaker.split(" ")[1]
|
26 |
+
return f"[S{speaker}]: {text}"
|
27 |
+
|
28 |
+
with gr.Blocks() as demo:
|
29 |
+
with gr.Sidebar():
|
30 |
+
login_button = gr.LoginButton()
|
31 |
+
gr.HTML(
|
32 |
+
"""
|
33 |
+
<h1 style='text-align: center; display: flex; align-items: center; justify-content: center;'>
|
34 |
+
<img src=https://cdn-lfs-us-1.hf.co/repos/0f/d0/0fd0968732b9b1a23edbcfa11604db1b053ea9f874bbc66b0aceeab9c5a3c517/0946854c0d2e4813049b21cfb123680dd2cf11b837bda827d75c3c8dec47982b?response-content-disposition=inline%3B+filename*%3DUTF-8%27%27Vibing%252520Huggy.gif%3B+filename%3D%22Vibing%2520Huggy.gif%22%3B&response-content-type=image%2Fgif&Expires=1745535621&Policy=eyJTdGF0ZW1lbnQiOlt7IkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTc0NTUzNTYyMX19LCJSZXNvdXJjZSI6Imh0dHBzOi8vY2RuLWxmcy11cy0xLmhmLmNvL3JlcG9zLzBmL2QwLzBmZDA5Njg3MzJiOWIxYTIzZWRiY2ZhMTE2MDRkYjFiMDUzZWE5Zjg3NGJiYzY2YjBhY2VlYWI5YzVhM2M1MTcvMDk0Njg1NGMwZDJlNDgxMzA0OWIyMWNmYjEyMzY4MGRkMmNmMTFiODM3YmRhODI3ZDc1YzNjOGRlYzQ3OTgyYj9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPSomcmVzcG9uc2UtY29udGVudC10eXBlPSoifV19&Signature=c2qfu6PYMaKDWG8PqF2xpa2p4yPONOOLPlqU%7EUDVFhXCMmXQF3XO7mPSkdBtaEYv-5A4Jwd9y5Qasa%7ECJoVhvdeAefz84v%7ESK0wVVjIBDlrYZoTe4IvQ1H26-i0tKYC-fa6qHZ2Dd5OFZdHvPlhx4tvJBcGB-r0puc2-6TQ85kqre%7EIK%7E6UHaJl8y7Orl4CKlKqir2LKim7ORP2zMLsfrC6j82Fk%7EmJDcsPDxqQ6EPiphRuiHFNI16vDYrGoIH4AXqF6l3tQh8sLbSnKfO-V4DgaoSCM2soxGmvkrN%7EwvB7DzT7ZB%7ENt-rqKKHLlBlHfNLLdBlyMFrnqSBpPAtRrRA__&Key-Pair-Id=K24J24Z295AEI9 alt="Dancing Huggy" style="height: 100px; margin-right: 10px"> Dia Dialogue Generation Model
|
35 |
+
</h1>
|
36 |
+
<h2 style='text-align: center; display: flex; align-items: center; justify-content: center;'>Model by <a href="https://huggingface.co/nari-labs/Dia-1.6B"> Nari Labs</a>. Powered by HF and <a href="https://fal.ai/">Fal AI</a> API.</h2>
|
37 |
+
<h3>Dia is a dialogue generation model that can generate realistic dialogue between two speakers. Use the dialogue component to create a conversation and then hit the submit button in the bottom right corner to see it come to life .</h3>
|
38 |
+
"""
|
39 |
+
)
|
40 |
+
with gr.Row():
|
41 |
+
with gr.Column():
|
42 |
+
dialogue = Dialogue(speakers=speakers, emotions=emotions,
|
43 |
+
formatter=formatter)
|
44 |
+
with gr.Column():
|
45 |
+
with gr.Row():
|
46 |
+
audio = gr.Audio(label="Audio")
|
47 |
+
with gr.Row():
|
48 |
+
gr.DeepLinkButton(value="Share Audio via Link")
|
49 |
+
with gr.Row():
|
50 |
+
gr.Examples(examples=[
|
51 |
+
[[{"speaker": "Speaker 1", "text": "Why did the chicken cross the road?"},
|
52 |
+
{"speaker": "Speaker 2", "text": "I don't know!"},
|
53 |
+
{"speaker": "Speaker 1", "text": "to get to the other side! (laughs)"}]],
|
54 |
+
[[{"speaker": "Speaker 1", "text": "(sighs) I am a little tired today."},
|
55 |
+
{"speaker": "Speaker 2", "text": "Hang in there!"},
|
56 |
+
]]], inputs=[dialogue], cache_examples=False)
|
57 |
+
|
58 |
+
dialogue.submit(query, [dialogue], audio)
|
59 |
+
|
60 |
+
demo.launch()
|
61 |
+
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gradio-dialogue>=0.0.3
|