Lyte commited on
Commit
b6e8173
·
verified ·
1 Parent(s): e3c1a18

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -0
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import outetts
3
+ from outetts.models.config import GenerationConfig
4
+ from huggingface_hub import hf_hub_download, login
5
+ import os
6
+ import numpy as np
7
+
8
+ login(token=os.environ.get("HF_TOKEN"))
9
+
10
+ model_path = hf_hub_download(
11
+ repo_id="Lyte/DarijaTTS",
12
+ filename="unsloth.Q8_0.gguf",
13
+ )
14
+ model_config = outetts.GGUFModelConfig_v2(
15
+ model_path=model_path,
16
+ tokenizer_path="Lyte/DarijaTTS",
17
+ #verbose=False
18
+ )
19
+ interface = outetts.InterfaceGGUF(model_version="0.3", cfg=model_config)
20
+
21
+ # TTS function
22
+ def tts(text, temperature, repetition_penalty):
23
+ try:
24
+ gen_cfg = GenerationConfig(
25
+ text=text,
26
+ temperature=temperature,
27
+ repetition_penalty=repetition_penalty,
28
+ max_length=4096,
29
+ speaker=None
30
+ )
31
+
32
+ output = interface.generate(config=gen_cfg)
33
+
34
+ output_path = "output.wav"
35
+ output.save(output_path)
36
+
37
+ return output_path
38
+ except Exception as e:
39
+ raise gr.Error(f"Error generating audio: {str(e)}")
40
+
41
+ with gr.Blocks() as demo:
42
+ gr.Markdown("# Darija TTS Demo (alpha)")
43
+ gr.Markdown("### Note: this is an early alpha which still needs training.")
44
+
45
+ with gr.Row():
46
+ text_input = gr.Textbox(
47
+ label="Enter text for TTS",
48
+ value="السلام كيداير لاباس عليك؟"
49
+ )
50
+
51
+ output_audio = gr.Audio(label="Generated Audio", type="filepath")
52
+ generate_btn = gr.Button("Generate Audio")
53
+
54
+
55
+ with gr.Row():
56
+ temperature = gr.Slider(
57
+ minimum=0.01,
58
+ maximum=1.0,
59
+ value=0.1,
60
+ step=0.01,
61
+ label="Temperature"
62
+ )
63
+
64
+ repetition_penalty = gr.Slider(
65
+ minimum=0.8,
66
+ maximum=1.5,
67
+ value=1.1,
68
+ step=0.05,
69
+ label="Repetition Penalty"
70
+ )
71
+
72
+ with gr.Row():
73
+ gr.Markdown("### Examples:")
74
+ gr.Examples(
75
+ [
76
+ ["رمضان مبارك سعيد"],
77
+ ["اشنو بان ليك فهادشي مزيان؟"],
78
+ ["السلام كيداير لاباس عليك؟"],
79
+ ["واش كاين شي جديد اليوم؟"]
80
+ ],
81
+ inputs=[text_input])
82
+
83
+ generate_btn.click(
84
+ fn=tts,
85
+ inputs=[text_input, temperature, repetition_penalty],
86
+ outputs=output_audio
87
+ )
88
+
89
+ demo.launch(debug=True)