Aya-Ch commited on
Commit
ba9a48e
·
2 Parent(s): 805c796 e120b5a

Merge branch 'aya' of https://huggingface.co/spaces/AiDi-UIR/TTS-Conv-Darija

Browse files
Files changed (2) hide show
  1. app.py +80 -0
  2. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ from gradio_client import Client, handle_file
4
+ import tempfile
5
+ import os
6
+
7
+ # Load TTS client - using the correct Space URL
8
+ tts_client = Client("https://medmac01-darija-arabic-tts.hf.space/")
9
+
10
+ # Load text generation client
11
+ text_client = InferenceClient("deepseek-ai/DeepSeek-R1-Distill-Qwen-32B")
12
+
13
+ def generate_conversation(subject, speaker1_audio, speaker2_audio):
14
+ prompt = f"""
15
+ Generate a natural Moroccan Darija conversation between two people about: "{subject}".
16
+ Format:
17
+ Speaker 1: ...
18
+ Speaker 2: ...
19
+ Speaker 1: ...
20
+ Speaker 2: ...
21
+ Keep it short and casual (4 lines).
22
+ """
23
+
24
+ result = text_client.text_generation(prompt, max_new_tokens=300, temperature=0.7)
25
+ lines = [line.strip() for line in result.split('\n') if line.strip().startswith("Speaker")]
26
+
27
+ # Generate audio files using TTS
28
+ audio_paths = []
29
+ idx = 0
30
+ for line in lines:
31
+ speaker_audio = speaker1_audio if line.startswith("Speaker 1") else speaker2_audio
32
+ text = line.split(":", 1)[1].strip()
33
+
34
+ # Create TTS audio using the correct API call
35
+ result = tts_client.predict(
36
+ text=text,
37
+ speaker_audio_path=handle_file(speaker_audio),
38
+ temperature=0.75,
39
+ api_name="/infer_EGTTS"
40
+ )
41
+
42
+ # Save the result to a temporary file
43
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
44
+ with open(result, "rb") as f:
45
+ tmp.write(f.read())
46
+ tmp.flush()
47
+ audio_paths.append(tmp.name)
48
+ idx += 1
49
+
50
+ # Format the conversation text
51
+ conversation_text = "\n".join(lines)
52
+
53
+ # Return all outputs in the correct order
54
+ return [conversation_text] + audio_paths
55
+
56
+ with gr.Blocks() as demo:
57
+ gr.Markdown("# 🗣️ Moroccan Darija Conversation Generator")
58
+ gr.Markdown("Enter a discussion topic and upload 2 speaker voices. We'll generate a Darija conversation!")
59
+
60
+ with gr.Row():
61
+ subject = gr.Textbox(label="Subject of the discussion", placeholder="e.g. Going to the souk")
62
+ with gr.Row():
63
+ speaker1 = gr.Audio(label="Speaker 1 Reference (4-5 sec)", type="filepath")
64
+ speaker2 = gr.Audio(label="Speaker 2 Reference (4-5 sec)", type="filepath")
65
+
66
+ btn = gr.Button("🎤 Generate Conversation")
67
+
68
+ # Add text output for the conversation
69
+ conversation_output = gr.Textbox(label="Generated Conversation", lines=6)
70
+
71
+ # Audio outputs
72
+ audio_outputs = [gr.Audio(label=f"Line {i+1}") for i in range(4)]
73
+
74
+ btn.click(
75
+ generate_conversation,
76
+ inputs=[subject, speaker1, speaker2],
77
+ outputs=[conversation_output] + audio_outputs
78
+ )
79
+
80
+ demo.launch()
requirements.txt ADDED
Binary file (190 Bytes). View file