Spaces:
Running
Running
import gradio as gr | |
from transformers import VitsModel, AutoTokenizer | |
import torch | |
import tempfile | |
import shutil | |
import os | |
def text_to_speech(text): | |
# 1. إنشاء مجلد مؤقت | |
temp_model_dir = tempfile.mkdtemp() | |
# 2. تحميل النموذج والتوكنرايزر داخل المجلد المؤقت | |
model = VitsModel.from_pretrained("wasmdashai/vits-ar-sa-huba-v2", cache_dir=temp_model_dir) | |
tokenizer = AutoTokenizer.from_pretrained("wasmdashai/vits-ar-sa-huba-v2", cache_dir=temp_model_dir) | |
shutil.rmtree(temp_model_dir) | |
return temp_model_dir # Gradio سيعرض الملف الصوتي | |
# 5. حذف المجلد الذي تم تحميل النموذج فيه | |
def cleanup_file(file_path): | |
if os.path.exists(file_path): | |
os.remove(file_path) | |
# إعداد واجهة Gradio | |
demo = gr.Interface( | |
fn=text_to_speech, | |
inputs=gr.Textbox(label="أدخل نصاً"), | |
outputs=['text']) | |
demo.launch() | |