Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
import datetime
|
3 |
+
import os
|
4 |
+
|
5 |
+
print(f"pip3 uninstall scepter")
|
6 |
+
results = os.popen(f"pip3 uninstall scepter -y")
|
7 |
+
print(results.readlines())
|
8 |
+
results = os.popen(f"pip3 install scepter -i https://pypi.tuna.tsinghua.edu.cn/simple")
|
9 |
+
print(results.readlines())
|
10 |
+
import random
|
11 |
+
|
12 |
+
import gradio as gr
|
13 |
+
|
14 |
+
import scepter
|
15 |
+
from scepter.modules.utils.config import Config
|
16 |
+
from scepter.modules.utils.file_system import FS
|
17 |
+
from scepter.modules.utils.logger import get_logger, init_logger
|
18 |
+
|
19 |
+
|
20 |
+
def prepare(config):
|
21 |
+
if 'FILE_SYSTEM' in config:
|
22 |
+
for fs_info in config['FILE_SYSTEM']:
|
23 |
+
FS.init_fs_client(fs_info)
|
24 |
+
|
25 |
+
if 'LOG_FILE' in config:
|
26 |
+
logger = get_logger()
|
27 |
+
tid = '{0:%Y%m%d%H%M%S%f}'.format(datetime.datetime.now()) + ''.join(
|
28 |
+
[str(random.randint(1, 10)) for i in range(3)])
|
29 |
+
init_logger(logger, log_file=config['LOG_FILE'].format(tid))
|
30 |
+
|
31 |
+
class TabManager():
|
32 |
+
def __init__(self):
|
33 |
+
pass
|
34 |
+
|
35 |
+
config_file = os.path.join(os.path.dirname(scepter.dirname), "scepter/methods/studio/scepter_ui.yaml")
|
36 |
+
config = Config(load=True, cfg_file=config_file)
|
37 |
+
|
38 |
+
for v in config.FILE_SYSTEM:
|
39 |
+
v.TEMP_DIR = os.path.join("/home", v.TEMP_DIR)
|
40 |
+
os.makedirs(v.TEMP_DIR, exist_ok=True)
|
41 |
+
|
42 |
+
prepare(config)
|
43 |
+
|
44 |
+
language = "en"
|
45 |
+
debug = False
|
46 |
+
|
47 |
+
|
48 |
+
tab_manager = TabManager()
|
49 |
+
interfaces = []
|
50 |
+
for info in config['INTERFACE']:
|
51 |
+
name = info.get('NAME_EN',
|
52 |
+
'') if language == 'en' else info['NAME']
|
53 |
+
ifid = info['IFID']
|
54 |
+
if not FS.exists(info['CONFIG']):
|
55 |
+
info['CONFIG'] = os.path.join(os.path.dirname(scepter.dirname), info['CONFIG'])
|
56 |
+
if not FS.exists(info['CONFIG']):
|
57 |
+
raise f"{info['CONFIG']} doesn't exist."
|
58 |
+
interface = None
|
59 |
+
if ifid == 'home':
|
60 |
+
from scepter.studio.home.home import HomeUI
|
61 |
+
interface = HomeUI(info['CONFIG'],
|
62 |
+
is_debug=debug,
|
63 |
+
language=language,
|
64 |
+
root_work_dir=config.WORK_DIR)
|
65 |
+
if ifid == 'inference':
|
66 |
+
from scepter.studio.inference.inference import InferenceUI
|
67 |
+
interface = InferenceUI(
|
68 |
+
info['CONFIG'],
|
69 |
+
is_debug=debug,
|
70 |
+
language=language,
|
71 |
+
root_work_dir=config.WORK_DIR)
|
72 |
+
if ifid == '':
|
73 |
+
pass # TODO: Add New Features
|
74 |
+
if interface:
|
75 |
+
interfaces.append((interface, name, ifid))
|
76 |
+
setattr(tab_manager, ifid, interface)
|
77 |
+
|
78 |
+
with gr.Blocks() as demo:
|
79 |
+
if 'BANNER' in config:
|
80 |
+
gr.HTML(config.BANNER)
|
81 |
+
else:
|
82 |
+
gr.Markdown(
|
83 |
+
f"<h2><center>{config.get('TITLE', 'SCEPTER Studio')}</center></h2>"
|
84 |
+
)
|
85 |
+
with gr.Tabs(elem_id='tabs') as tabs:
|
86 |
+
for interface, label, ifid in interfaces:
|
87 |
+
with gr.TabItem(label, id=ifid, elem_id=f'tab_{ifid}'):
|
88 |
+
interface.create_ui()
|
89 |
+
for interface, label, ifid in interfaces:
|
90 |
+
interface.set_callbacks(tab_manager)
|
91 |
+
|
92 |
+
demo.queue(status_update_rate=1, api_open=False).launch(share=False, show_error=True, enable_queue=True)
|