xJuuzouYTx
commited on
Commit
•
0cb3834
1
Parent(s):
91bc9e7
[ADD] post and search models
Browse files- .gitignore +2 -0
- app.py +130 -12
.gitignore
CHANGED
@@ -9,6 +9,8 @@ __pycache__
|
|
9 |
hubert_base.pt
|
10 |
/logs
|
11 |
/env
|
|
|
|
|
12 |
.venv
|
13 |
alexforkINSTALL.bat
|
14 |
Changelog_CN.md
|
|
|
9 |
hubert_base.pt
|
10 |
/logs
|
11 |
/env
|
12 |
+
/zips/
|
13 |
+
/unzips/
|
14 |
.venv
|
15 |
alexforkINSTALL.bat
|
16 |
Changelog_CN.md
|
app.py
CHANGED
@@ -1,6 +1,56 @@
|
|
1 |
import gradio as gr
|
2 |
from inference import Inference
|
3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def infer(model, f0_method, audio_file):
|
6 |
print("****", audio_file)
|
@@ -15,20 +65,88 @@ def infer(model, f0_method, audio_file):
|
|
15 |
return output, output['file']
|
16 |
else:
|
17 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
with gr.Blocks() as app:
|
20 |
gr.HTML("<h1> Simple RVC Inference - by Juuxn 💻 </h1>")
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
app.queue(concurrency_count=511, max_size=1022).launch(share=True)
|
|
|
1 |
import gradio as gr
|
2 |
from inference import Inference
|
3 |
import os
|
4 |
+
import zipfile
|
5 |
+
import hashlib
|
6 |
+
from utils.model import model_downloader, get_model
|
7 |
+
import requests
|
8 |
+
|
9 |
+
api_url = "https://rvc-models-api.onrender.com/uploadfile/"
|
10 |
+
|
11 |
+
zips_folder = "./zips"
|
12 |
+
unzips_folder = "./unzips"
|
13 |
+
if not os.path.exists(zips_folder):
|
14 |
+
os.mkdir(zips_folder)
|
15 |
+
if not os.path.exists(unzips_folder):
|
16 |
+
os.mkdir(unzips_folder)
|
17 |
+
|
18 |
+
def calculate_md5(file_path):
|
19 |
+
hash_md5 = hashlib.md5()
|
20 |
+
with open(file_path, "rb") as f:
|
21 |
+
for chunk in iter(lambda: f.read(4096), b""):
|
22 |
+
hash_md5.update(chunk)
|
23 |
+
return hash_md5.hexdigest()
|
24 |
+
|
25 |
+
def compress(modelname, files):
|
26 |
+
file_path = os.path.join(zips_folder, f"{modelname}.zip")
|
27 |
+
# Select the compression mode ZIP_DEFLATED for compression
|
28 |
+
# or zipfile.ZIP_STORED to just store the file
|
29 |
+
compression = zipfile.ZIP_DEFLATED
|
30 |
+
|
31 |
+
# Comprueba si el archivo ZIP ya existe
|
32 |
+
if not os.path.exists(file_path):
|
33 |
+
# Si no existe, crea el archivo ZIP
|
34 |
+
with zipfile.ZipFile(file_path, mode="w") as zf:
|
35 |
+
try:
|
36 |
+
for file in files:
|
37 |
+
if file:
|
38 |
+
# Agrega el archivo al archivo ZIP
|
39 |
+
zf.write(unzips_folder if ".index" in file else os.path.join(unzips_folder, file), compress_type=compression)
|
40 |
+
except FileNotFoundError as fnf:
|
41 |
+
print("An error occurred", fnf)
|
42 |
+
else:
|
43 |
+
# Si el archivo ZIP ya existe, agrega los archivos a un archivo ZIP existente
|
44 |
+
with zipfile.ZipFile(file_path, mode="a") as zf:
|
45 |
+
try:
|
46 |
+
for file in files:
|
47 |
+
if file:
|
48 |
+
# Agrega el archivo al archivo ZIP
|
49 |
+
zf.write(unzips_folder if ".index" in file else os.path.join(unzips_folder, file), compress_type=compression)
|
50 |
+
except FileNotFoundError as fnf:
|
51 |
+
print("An error occurred", fnf)
|
52 |
+
|
53 |
+
return file_path
|
54 |
|
55 |
def infer(model, f0_method, audio_file):
|
56 |
print("****", audio_file)
|
|
|
65 |
return output, output['file']
|
66 |
else:
|
67 |
return
|
68 |
+
|
69 |
+
def post_model(name, model_url, version, creator):
|
70 |
+
modelname = model_downloader(model_url, zips_folder, unzips_folder)
|
71 |
+
model_files = get_model(unzips_folder, modelname)
|
72 |
+
md5_hash = calculate_md5(os.path.join(unzips_folder,model_files['pth']))
|
73 |
+
zipfile = compress(modelname, list(model_files.values()))
|
74 |
+
file_to_upload = open(zipfile, "rb")
|
75 |
+
data = {
|
76 |
+
"name": name,
|
77 |
+
"version": version,
|
78 |
+
"creator": creator,
|
79 |
+
"hash": md5_hash
|
80 |
+
}
|
81 |
+
print("Subiendo archivo...")
|
82 |
+
# Realizar la solicitud POST
|
83 |
+
response = requests.post(api_url, files={"file": file_to_upload}, data=data)
|
84 |
+
|
85 |
+
# Comprobar la respuesta
|
86 |
+
if response.status_code == 200:
|
87 |
+
result = response.json()
|
88 |
+
return result
|
89 |
+
else:
|
90 |
+
print("Error al cargar el archivo:", response.status_code)
|
91 |
+
return result
|
92 |
+
|
93 |
+
def search_model(name):
|
94 |
+
web_service_url = "https://script.google.com/macros/s/AKfycbzfIOiwmPj-q8-hEyvjRQfgLtO7ESolmtsQmnNheCujwnitDApBSjgTecdfXb8f2twT/exec"
|
95 |
+
response = requests.post(web_service_url, json={
|
96 |
+
'type': 'search_by_filename',
|
97 |
+
'name': name
|
98 |
+
})
|
99 |
+
result = []
|
100 |
+
response.raise_for_status() # Lanza una excepción en caso de error
|
101 |
+
json_response = response.json()
|
102 |
+
cont = 0
|
103 |
+
if json_response.get('ok', None):
|
104 |
+
for model in json_response['ocurrences']:
|
105 |
+
if cont < 20:
|
106 |
+
model_name = model.get('name', 'N/A')
|
107 |
+
model_url = model.get('url', 'N/A')
|
108 |
+
result.append(f"**Nombre del modelo: {model_name}**</br>{model_url}</br>")
|
109 |
+
yield "</br>".join(result)
|
110 |
+
cont += 1
|
111 |
|
112 |
with gr.Blocks() as app:
|
113 |
gr.HTML("<h1> Simple RVC Inference - by Juuxn 💻 </h1>")
|
114 |
+
|
115 |
+
with gr.Tab("Inferencia"):
|
116 |
+
model_url = gr.Textbox(placeholder="https://huggingface.co/AIVER-SE/BillieEilish/resolve/main/BillieEilish.zip", label="Url del modelo", show_label=True)
|
117 |
+
audio_path = gr.Audio(label="Archivo de audio", show_label=True, type="filepath", )
|
118 |
+
f0_method = gr.Dropdown(choices=["harvest", "pm", "crepe", "crepe-tiny", "mangio-crepe", "mangio-crepe-tiny", "rmvpe"],
|
119 |
+
value="harvest",
|
120 |
+
label="Algoritmo", show_label=True)
|
121 |
+
# Salida
|
122 |
+
with gr.Row():
|
123 |
+
vc_output1 = gr.Textbox(label="Salida")
|
124 |
+
vc_output2 = gr.Audio(label="Audio de salida")
|
125 |
+
|
126 |
+
btn = gr.Button(value="Convertir")
|
127 |
+
btn.click(infer, inputs=[model_url, f0_method, audio_path], outputs=[vc_output1, vc_output2])
|
128 |
+
|
129 |
+
with gr.Tab("Recursos"):
|
130 |
+
gr.HTML("<h4>Buscar modelos</h4>")
|
131 |
+
search_name = gr.Textbox(placeholder="Billie Eillish (RVC v2 - 100 epoch)", label="Nombre", show_label=True)
|
132 |
+
# Salida
|
133 |
+
with gr.Row():
|
134 |
+
sarch_output = gr.Markdown(label="Salida")
|
135 |
+
|
136 |
+
btn_search_model = gr.Button(value="Buscar")
|
137 |
+
btn_search_model.click(fn=search_model, inputs=[search_name], outputs=[sarch_output])
|
138 |
+
|
139 |
+
gr.HTML("<h4>Publica tu modelo</h4>")
|
140 |
+
post_name = gr.Textbox(placeholder="Billie Eillish (RVC v2 - 100 epoch)", label="Nombre", show_label=True)
|
141 |
+
post_model_url = gr.Textbox(placeholder="https://huggingface.co/AIVER-SE/BillieEilish/resolve/main/BillieEilish.zip", label="Url del modelo", show_label=True)
|
142 |
+
post_creator = gr.Textbox(placeholder="ID de discord o enlace al perfil del creador", label="Creador", show_label=True)
|
143 |
+
post_version = gr.Dropdown(choices=["RVC v1", "RVC v2"], value="RVC v1", label="Versión", show_label=True)
|
144 |
+
|
145 |
+
# Salida
|
146 |
+
with gr.Row():
|
147 |
+
post_output = gr.Markdown(label="Salida")
|
148 |
+
|
149 |
+
btn_post_model = gr.Button(value="Publicar")
|
150 |
+
btn_post_model.click(fn=post_model, inputs=[post_name, post_model_url, post_version, post_creator], outputs=[post_output])
|
151 |
|
152 |
app.queue(concurrency_count=511, max_size=1022).launch(share=True)
|