wasm-dastee8 / app.py
wasmdashai's picture
Update app.py
78d4a12 verified
raw
history blame
1.02 kB
import gradio as gr
from transformers import VitsModel, AutoTokenizer
import torch
import tempfile
import shutil
import os
import soundfile as sf
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()