Spaces:
Running
Running
File size: 994 Bytes
fcd1b85 78d4a12 fcd1b85 78d4a12 fcd1b85 78d4a12 fcd1b85 78d4a12 fcd1b85 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
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()
|