scepter_studio / app.py
jiangzeyinzi's picture
Update app.py
08a6424 verified
raw
history blame
3.96 kB
# -*- coding: utf-8 -*-
import datetime
import os
# print(f"pip3 uninstall gradio")
# results = os.popen(f"pip3 uninstall gradio -y")
# print(results.readlines())
results = os.popen(f"ls -lR ~/.cache/huggingface/hub")
print("step0:", results.readlines())
results = os.popen(f"pip3 install -r requirements.txt -i https://pypi.org/simple")
print("step1:", results.readlines())
results = os.popen(f"pip3 uninstall scepter -y")
print("step2:", results.readlines())
results = os.popen(f"pip3 install scepter -i https://pypi.org/simple")
print("step3:", results.readlines())
results = os.popen(f"pip3 list")
print("step4:", results.readlines())
results = os.popen(f"sudo chmod 777 /data")
print("step5:", results.readlines())
print("finish install")
import random
import gradio as gr
import scepter
from scepter.modules.utils.config import Config
from scepter.modules.utils.file_system import FS
from scepter.modules.utils.logger import get_logger, init_logger
def prepare(config):
if 'FILE_SYSTEM' in config:
for fs_info in config['FILE_SYSTEM']:
FS.init_fs_client(fs_info)
if 'LOG_FILE' in config:
logger = get_logger()
tid = '{0:%Y%m%d%H%M%S%f}'.format(datetime.datetime.now()) + ''.join(
[str(random.randint(1, 10)) for i in range(3)])
init_logger(logger, log_file=config['LOG_FILE'].format(tid))
class TabManager():
def __init__(self):
pass
config_file = os.path.join(os.path.dirname(scepter.dirname), "scepter/methods/studio/scepter_ui.yaml")
config = Config(load=True, cfg_file=config_file)
for v in config.FILE_SYSTEM:
# v.TEMP_DIR = os.path.join("/home", v.TEMP_DIR)
# v.TEMP_DIR = os.path.join("/data/.huggingface", v.TEMP_DIR)
v.TEMP_DIR = os.path.join("~/.cache/huggingface/hub", v.TEMP_DIR)
os.makedirs(v.TEMP_DIR, exist_ok=True)
prepare(config)
language = "en"
debug = False
tab_manager = TabManager()
interfaces = []
for info in config['INTERFACE']:
name = info.get('NAME_EN',
'') if language == 'en' else info['NAME']
ifid = info['IFID']
if not FS.exists(info['CONFIG']):
info['CONFIG'] = os.path.join(os.path.dirname(scepter.dirname), info['CONFIG'])
if not FS.exists(info['CONFIG']):
raise f"{info['CONFIG']} doesn't exist."
interface = None
if ifid == 'home':
from scepter.studio.home.home import HomeUI
interface = HomeUI(info['CONFIG'],
is_debug=debug,
language=language,
root_work_dir=config.WORK_DIR)
if ifid == 'tuner_manager':
from scepter.studio.tuner_manager.tuner_manager import TunerManagerUI
interface = TunerManagerUI(info['CONFIG'],
is_debug=debug,
language=language,
root_work_dir=config.WORK_DIR)
if ifid == 'inference':
from scepter.studio.inference.inference import InferenceUI
interface = InferenceUI(
info['CONFIG'],
is_debug=debug,
language=language,
root_work_dir=config.WORK_DIR)
if ifid == '':
pass # TODO: Add New Features
if interface:
interfaces.append((interface, name, ifid))
setattr(tab_manager, ifid, interface)
with gr.Blocks() as demo:
if 'BANNER' in config:
gr.HTML(config.BANNER)
else:
gr.Markdown(
f"<h2><center>{config.get('TITLE', 'SCEPTER Studio')}</center></h2>"
)
with gr.Tabs(elem_id='tabs') as tabs:
setattr(tab_manager, 'tabs', tabs)
for interface, label, ifid in interfaces:
with gr.TabItem(label, id=ifid, elem_id=f'tab_{ifid}'):
interface.create_ui()
for interface, label, ifid in interfaces:
interface.set_callbacks(tab_manager)
demo.queue(status_update_rate=1, api_open=False).launch(share=False, show_error=True, enable_queue=True)