wasm-dastee8 / app.py
wasmdashai's picture
Update app.py
c5a603f verified
raw
history blame
1.04 kB
import gradio as gr
from transformers import VitsModel, AutoTokenizer
import torch
import tempfile
import shutil
import os
C=0
def text_to_speech(text):
global C
# 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)
C+=1
print("C:",C)
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()