adapt everything to work with new config file

This commit is contained in:
Jaikinator
2024-01-24 15:58:37 +01:00
parent 7c200d4506
commit 6217e3a9b3
4 changed files with 81 additions and 23 deletions
+11 -10
View File
@@ -1,10 +1,13 @@
launch:
# The following are the default values for the launch configuration
# for more informations look at https://www.gradio.app/docs/interface
server_port: 8080
server_port: 7860
server_name: 0.0.0.0
inbrowser: true
inline: false
inbrowser: true
share : false
debug : false
max-threads: 40
quiet: false
auth:
@@ -12,7 +15,9 @@ launch:
auth_username: admin
auth_password: admin
auth_message: null
prevent_thread_lock : false
show_error : false
show_tips : true
favicon_path : null
ssl_keyfile : null
ssl_certfile : null
@@ -22,21 +27,17 @@ launch:
show_api : false
allowed_paths : null
blocked_paths : null
root_path : null
root_path : ''
app_kwargs : null
state_session_capacity : 1000
share_server_address : null
share_server_protocol : null
share : false
debug : false
queue:
# The following are the default values for the queue configuration
# for more informations look at hhttps://www.gradio.app/docs/interface
concurrency_count : 1
status_update_rate : 'auto'
api_open : null
max_size : null
concurrency_count : null
default_concurrency_limit : 'not_set'
layout:
header: scraibe/app/header.html
footer: null
+9 -9
View File
@@ -31,21 +31,18 @@ LANGUAGES = [
"Vietnamese", "Welsh"
]
CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
def gradio_Interface():
def gradio_Interface(layout = None,):
with gr.Blocks(theme=theme,title='ScrAIbe: Automatic Audio Transcription') as demo:
# Define components
hname = os.path.join(CURRENT_PATH, "header.html")
header = open(hname, "r").read()
# ugly hack to get the logo to work
header = header.replace("/file=logo.svg", f"/file={CURRENT_PATH}/logo.svg" )
gr.HTML(header, visible= True, show_label=False)
if layout.get('header') is not None:
gr.HTML(layout.get('header'), visible= True, show_label=False)
with gr.Row():
@@ -98,7 +95,10 @@ def gradio_Interface():
visible= False, interactive= True)
annotate = gr.Button(value="Annotate", visible= False, interactive= True)
if layout.get('footer') is not None:
gr.HTML(layout.get('footer'), visible= True, show_label=False)
# Define usage of components
input.change(fn=select_origin, inputs=[input],
outputs=[audio1, audio2, video1, video2, file_in])
+12 -2
View File
@@ -68,13 +68,23 @@ def model_worker(model_params : Union[Scraibe, dict],
clear_queue(response_queue)
loaded_event.clear()
def start_model_worker(model_params, request_queue, last_active_time, response_queue,loaded_event, running_event, *args, **kwargs):
def start_model_worker(model_params,
request_queue,
last_active_time,
response_queue,
loaded_event,
running_event,
*args, **kwargs):
context = multiprocessing.get_context('spawn')
model_process = context.Process(target=model_worker, args=(model_params, request_queue, last_active_time, response_queue,loaded_event, running_event, *args), kwargs=kwargs)
model_process.start()
return model_process
def timer_thread(request_queue, last_active_time,loaded_event, running_event, timeout=30):
def timer_thread(request_queue,
last_active_time,
loaded_event,
running_event,
timeout=30):
while True:
time.sleep(timeout)
+49 -2
View File
@@ -1,9 +1,12 @@
from email import header
from math import e
import os
import warnings
import yaml
import scraibe.app.global_var as gv
CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
class ConfigLoader:
def __init__(self, config):
@@ -42,6 +45,7 @@ class ConfigLoader:
config = cls.get_default_config()
# Override with another YAML file if provided
if yaml_path:
with open(yaml_path, 'r') as file:
override_config = yaml.safe_load(file)
@@ -106,7 +110,7 @@ class AppConfig(ConfigLoader):
self.set_launch_options()
self.set_layout_options()
self.lauch = self.config.get("launch")
self.launch = self.config.get("launch")
self.model = self.config.get("model")
self.advanced = self.config.get("advanced")
self.queue = self.config.get("queue")
@@ -141,7 +145,50 @@ class AppConfig(ConfigLoader):
self.config['layout']['header'] = self.check_and_set_path(self.config['layout'], 'header')
self.config['layout']['footer'] = self.check_and_set_path(self.config['layout'], 'footer')
self.config['layout']['logo'] = self.check_and_set_path(self.config['layout'], 'logo')
def get_layout(self):
if not os.path.exists(self.config['layout']['header']) and \
self.config['layout']['header'] == "scraibe/app/header.html":
hname = os.path.join(CURRENT_PATH, "header.html")
header = open(hname).read()
elif not os.path.exists(self.config['layout']['header']) and self.config['layout']['header'] != "scraibe/app/header.html":
warnings.warn(f"Header file not found: {self.config['layout']['header']} \n" \
"fall back to default.")
hname = os.path.join(CURRENT_PATH, "header.html")
header = open(hname).read()
elif os.path.exists(self.config['layout']['header']):
header = open(self.config['layout']['header']).read()
else:
warnings.warn(f"Header file not found: {self.config['layout']['header']}")
header = None
if header != None:
if self.config['layout']['logo'] == "scraibe/app/logo.svg":
header = header.replace("/file=logo.svg", f"/file={os.path.join(CURRENT_PATH, 'logo.svg')}")
elif self.config['layout']['logo'] != "scraibe/app/logo.svg":
header = header.replace("/file=logo.svg", f"/file={self.config['layout']['logo']}")
else:
warnings.warn(f"Logo file not found: {self.config['layout']['logo']}")
if self.config['layout']['footer'] != None:
if os.path.exists(self.config['layout']['footer']):
footer = open(self.config['layout']['footer']).read()
elif self.config['layout']['footer'] == None:
footer = None
else:
warnings.warn(f"Footer file not found: {self.config['layout']['footer']}")
else:
footer = None
return {'header' : header ,
'footer' : footer}
@staticmethod
def check_and_set_path(config_item, key):