Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,36 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import VitsModel, AutoTokenizer
|
3 |
import torch
|
|
|
|
|
|
|
|
|
4 |
|
|
|
|
|
|
|
5 |
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
13 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import VitsModel, AutoTokenizer
|
3 |
import torch
|
4 |
+
import tempfile
|
5 |
+
import shutil
|
6 |
+
import os
|
7 |
+
import soundfile as sf
|
8 |
|
9 |
+
def text_to_speech(text):
|
10 |
+
# 1. إنشاء مجلد مؤقت
|
11 |
+
temp_model_dir = tempfile.mkdtemp()
|
12 |
|
13 |
+
# 2. تحميل النموذج والتوكنرايزر داخل المجلد المؤقت
|
14 |
+
model = VitsModel.from_pretrained("wasmdashai/vits-ar-sa-huba-v2", cache_dir=temp_model_dir)
|
15 |
+
tokenizer = AutoTokenizer.from_pretrained("wasmdashai/vits-ar-sa-huba-v2", cache_dir=temp_model_dir)
|
16 |
|
17 |
+
shutil.rmtree(temp_model_dir)
|
18 |
+
return temp_model_dir # Gradio سيعرض الملف الصوتي
|
19 |
+
|
20 |
+
|
21 |
+
# 5. حذف المجلد الذي تم تحميل النموذج فيه
|
22 |
+
|
23 |
+
|
24 |
+
def cleanup_file(file_path):
|
25 |
+
if os.path.exists(file_path):
|
26 |
+
os.remove(file_path)
|
27 |
+
|
28 |
+
# إعداد واجهة Gradio
|
29 |
+
demo = gr.Interface(
|
30 |
+
fn=text_to_speech,
|
31 |
+
inputs=gr.Textbox(label="أدخل نصاً"),
|
32 |
+
outputs=['text'])
|
33 |
+
|
34 |
+
|
35 |
|
|
|
36 |
demo.launch()
|