File size: 3,310 Bytes
1681061
 
 
 
 
 
 
91f6931
1681061
25d3046
 
1681061
7355eb9
1681061
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
963fb7b
1681061
 
 
963fb7b
1681061
 
 
963fb7b
1681061
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
963fb7b
1681061
 
 
 
963fb7b
1681061
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
963fb7b
 
 
 
1681061
 
963fb7b
 
 
 
 
1681061
 
 
 
 
 
 
963fb7b
 
 
1681061
 
 
 
 
963fb7b
1681061
 
963fb7b
 
1681061
 
 
 
 
963fb7b
 
1681061
 
 
 
 
 
963fb7b
1681061
 
 
 
 
 
 
 
 
 
963fb7b
 
 
 
1681061
 
 
 
963fb7b
 
 
 
1681061
 
 
 
 
 
 
 
 
963fb7b
1681061
 
 
 
 
 
 
 
 
 
963fb7b
 
1681061
 
 
 
 
 
 
 
963fb7b
1681061
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
963fb7b
1681061
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import os
import zipfile
import shutil
import gdown
import gradio as gr
import spaces
import torch

from rvc_engine.infer import voice_convert


MODEL_DIR = "models"

os.makedirs(
    MODEL_DIR,
    exist_ok=True
)


print("CUDA:", torch.cuda.is_available())

if torch.cuda.is_available():
    print(
        "GPU:",
        torch.cuda.get_device_name(0)
    )


def download_model(drive_url):

    zip_path = "model.zip"

    if os.path.exists(zip_path):
        os.remove(zip_path)


    try:
        gdown.download(
            drive_url,
            zip_path,
            quiet=False
        )

    except Exception as e:
        return None, None, f"خطأ تحميل الموديل: {str(e)}"


    if not os.path.exists(zip_path):
        return None, None, "فشل تحميل ملف ZIP"


    extract_dir = os.path.join(
        MODEL_DIR,
        "current"
    )


    if os.path.exists(extract_dir):
        shutil.rmtree(extract_dir)


    os.makedirs(
        extract_dir,
        exist_ok=True
    )


    try:

        with zipfile.ZipFile(zip_path, "r") as z:
            z.extractall(extract_dir)

    except Exception as e:

        return None, None, f"خطأ فك الضغط: {str(e)}"



    pth = None
    index = None


    for root, dirs, files in os.walk(extract_dir):

        for file in files:

            if file.endswith(".pth"):
                pth = os.path.join(
                    root,
                    file
                )


            if file.endswith(".index"):
                index = os.path.join(
                    root,
                    file
                )



    if not pth or not index:

        return None, None, (
            "لم يتم العثور على ملفات "
            ".pth و .index"
        )


    return (
        pth,
        index,
        "تم تحميل الموديل بنجاح"
    )



@spaces.GPU
def convert(audio, model_url):


    if not audio:

        return None, "يرجى رفع ملف صوتي"



    if not model_url:

        return None, "ضع رابط Google Drive للموديل"



    pth, index, status = download_model(
        model_url
    )


    if not pth:

        return None, status



    output = "output.wav"



    try:

        result = voice_convert(
            audio,
            pth,
            index,
            output
        )


        return (
            result,
            "تم التحويل بنجاح"
        )


    except Exception as e:

        return (
            None,
            f"خطأ في محرك RVC: {str(e)}"
        )





with gr.Blocks() as demo:


    gr.Markdown(
        "# 🎙️ RVC Voice Converter"
    )


    audio = gr.Audio(
        type="filepath",
        label="الصوت الأصلي"
    )


    model_url = gr.Textbox(
        label="رابط Google Drive للموديل ZIP",
        placeholder="ملف ZIP يحتوي pth و index"
    )


    button = gr.Button(
        "تحويل الصوت"
    )


    output = gr.Audio(
        label="الصوت الناتج"
    )


    info = gr.Textbox(
        label="الحالة"
    )


    button.click(
        convert,
        inputs=[
            audio,
            model_url
        ],
        outputs=[
            output,
            info
        ]
    )



demo.launch()