-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Update to v1.3.0 - Part 4] — Added offline interface
- Loading branch information
1 parent
ed31e92
commit ae856db
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import os | ||
import sys | ||
|
||
import gradio as gr | ||
|
||
from tabs.conversion.conversion import conversion_tab | ||
from tabs.install.install_models import files_upload, zip_upload | ||
from tabs.uvr.uvr import uvr_tab | ||
from tabs.welcome import welcome_tab | ||
|
||
DEFAULT_PORT = 4000 | ||
MAX_PORT_ATTEMPTS = 10 | ||
|
||
|
||
with gr.Blocks( | ||
title="PolGen - Politrees", | ||
css="footer{display:none !important}", | ||
theme=gr.themes.Soft( | ||
primary_hue="green", | ||
secondary_hue="green", | ||
neutral_hue="neutral", | ||
spacing_size="sm", | ||
radius_size="lg", | ||
), | ||
) as PolGen: | ||
|
||
with gr.Tab("Велком/Контакты"): | ||
welcome_tab() | ||
|
||
with gr.Tab("Преобразование голоса (RVC)"): | ||
conversion_tab() | ||
|
||
with gr.Tab("Разделение аудио (UVR)"): | ||
uvr_tab() | ||
|
||
with gr.Tab("Загрузка RVC моделей"): | ||
zip_upload() | ||
files_upload() | ||
|
||
|
||
def launch(port): | ||
PolGen.launch( | ||
favicon_path=os.path.join(os.getcwd(), "assets", "logo.ico"), | ||
share="--share" in sys.argv, | ||
inbrowser="--open" in sys.argv, | ||
server_port=port, | ||
) | ||
|
||
|
||
def get_port_from_args(): | ||
if "--port" in sys.argv: | ||
port_index = sys.argv.index("--port") + 1 | ||
if port_index < len(sys.argv): | ||
return int(sys.argv[port_index]) | ||
return DEFAULT_PORT | ||
|
||
|
||
if __name__ == "__main__": | ||
port = get_port_from_args() | ||
for _ in range(MAX_PORT_ATTEMPTS): | ||
try: | ||
launch(port) | ||
break | ||
except OSError: | ||
print( | ||
f"Не удалось запустить на порту {port}, повторяем попытку на порту {port - 1}..." | ||
) | ||
port -= 1 | ||
except Exception as error: | ||
print(f"Произошла ошибка при запуске Gradio: {error}") | ||
break |