File size: 1,181 Bytes
55adc26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import sys
import gradio as gr
from assets.i18n.i18n import I18nAuto
import requests

now_dir = os.getcwd()
sys.path.append(now_dir)

from assets.flask.server import start_flask, load_config_flask, save_config

i18n = I18nAuto()


def flask_server_tab():
    with gr.Row():
        with gr.Column():
            flask_checkbox = gr.Checkbox(
                label=i18n(
                    "Enable Applio integration with applio.org/models using flask"
                ),
                info=i18n(
                    "It will activate the possibility of downloading models with a click from the website."
                ),
                interactive=True,
                value=load_config_flask(),
            )
            flask_checkbox.change(
                fn=toggle,
                inputs=[flask_checkbox],
                outputs=[],
            )


def toggle(checkbox):
    save_config(bool(checkbox))
    if load_config_flask() == True:
        start_flask()
    else:
        try:
            requests.post("http://localhost:8000/shutdown")
        except requests.exceptions.ConnectionError:
            pass