| #!/usr/bin/env python | |
| from __future__ import annotations | |
| import gradio as gr | |
| def read_info(file_name: str) -> str: | |
| with open(file_name) as f: | |
| content = f.read() | |
| return content | |
| def load_model(model_name: str) -> gr.Interface: | |
| iface = gr.Interface.load(model_name, src='models') | |
| for component in iface.output_components: | |
| component.label = f'{component.label} ({model_name})' | |
| return iface | |
| def load_models(model_names: list[str]) -> list[gr.Interface]: | |
| return [load_model(name) for name in model_names] | |
| title = read_info('TITLE') | |
| description = read_info('DESCRIPTION') | |
| article = read_info('ARTICLE') | |
| model_names = read_info('MODEL_NAMES').split('\n') | |
| interfaces = load_models(model_names) | |
| gr.Parallel( | |
| *interfaces, | |
| title=title, | |
| description=description, | |
| article=article, | |
| ).launch() | |