Spaces:
Runtime error
Runtime error
failed attempt
Browse files- app.py +59 -4
- requirements.txt +0 -0
app.py
CHANGED
@@ -1,7 +1,62 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
import tempfile
|
4 |
+
import os
|
5 |
|
6 |
+
# Load TTS client
|
7 |
+
tts_client = InferenceClient("medmac01/Darija-Arabic-TTS")
|
8 |
|
9 |
+
# Load text generation client
|
10 |
+
text_client = InferenceClient("deepseek-ai/DeepSeek-R1-Distill-Qwen-32B")
|
11 |
+
|
12 |
+
def generate_conversation(subject, speaker1_audio, speaker2_audio):
|
13 |
+
prompt = f"""
|
14 |
+
Generate a natural Moroccan Darija conversation between two people about: "{subject}".
|
15 |
+
Format:
|
16 |
+
Speaker 1: ...
|
17 |
+
Speaker 2: ...
|
18 |
+
Speaker 1: ...
|
19 |
+
Speaker 2: ...
|
20 |
+
Keep it short and casual (4 lines).
|
21 |
+
"""
|
22 |
+
|
23 |
+
result = text_client.text_generation(prompt, max_new_tokens=300, temperature=0.7)
|
24 |
+
lines = [line.strip() for line in result.split('\n') if line.strip().startswith("Speaker")]
|
25 |
+
|
26 |
+
# Generate audio files using TTS
|
27 |
+
audio_paths = []
|
28 |
+
idx = 0
|
29 |
+
for line in lines:
|
30 |
+
audio_path = speaker1_audio if line.startswith("Speaker 1") else speaker2_audio
|
31 |
+
text = line.split(":", 1)[1].strip()
|
32 |
+
|
33 |
+
# Read speaker audio as bytes
|
34 |
+
with open(audio_path, "rb") as f:
|
35 |
+
speaker_audio_bytes = f.read()
|
36 |
+
|
37 |
+
# Create TTS audio
|
38 |
+
audio_bytes = tts_client.text_to_speech(text, voice=speaker_audio_bytes)
|
39 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
|
40 |
+
tmp.write(audio_bytes)
|
41 |
+
tmp.flush()
|
42 |
+
audio_paths.append(tmp.name)
|
43 |
+
idx += 1
|
44 |
+
|
45 |
+
return audio_paths
|
46 |
+
|
47 |
+
with gr.Blocks() as demo:
|
48 |
+
gr.Markdown("# 🗣️ Moroccan Darija Conversation Generator")
|
49 |
+
gr.Markdown("Enter a discussion topic and upload 2 speaker voices. We'll generate a Darija conversation!")
|
50 |
+
|
51 |
+
with gr.Row():
|
52 |
+
subject = gr.Textbox(label="Subject of the discussion", placeholder="e.g. Going to the souk")
|
53 |
+
with gr.Row():
|
54 |
+
speaker1 = gr.Audio(label="Speaker 1 Reference (4-5 sec)", type="filepath")
|
55 |
+
speaker2 = gr.Audio(label="Speaker 2 Reference (4-5 sec)", type="filepath")
|
56 |
+
|
57 |
+
btn = gr.Button("🎤 Generate Conversation")
|
58 |
+
outputs = [gr.Audio(label=f"Line {i+1}") for i in range(4)]
|
59 |
+
|
60 |
+
btn.click(generate_conversation, inputs=[subject, speaker1, speaker2], outputs=outputs)
|
61 |
+
|
62 |
+
demo.launch()
|
requirements.txt
CHANGED
Binary files a/requirements.txt and b/requirements.txt differ
|
|