import shutil import gradio as gr #from mysite.libs.utilities import chat_with_interpreter, completion, process_file #from interpreter import interpreter #import mysite.interpreter.interpreter_config # インポートするだけで設定が適用されます import importlib import os import pkgutil #from babyagi.babyagi import gradio_babyagi #from routers.gra_02_openInterpreter.OpenInterpreter import gradio_interface #from llamafactory.webui.interface import create_ui import importlib import os import pkgutil import importlib import os import pkgutil import traceback def include_gradio_interfaces(): package_dir = "/home/user/app/controllers" # controllers/ 直下を探索 gradio_interfaces = [] gradio_names = set() # `controllers/` 以下の全てのサブディレクトリを探索 package_paths = [] for root, dirs, files in os.walk(package_dir): if "__pycache__" in root: # __pycache__ を除外 continue package_paths.append(root) for package_path in package_paths: # パッケージの Python モジュールを取得 rel_path = os.path.relpath(package_path, package_dir) package_name = "controllers" + (("." + rel_path.replace(os.sep, ".")) if rel_path != "." else "") for module_info in pkgutil.iter_modules([package_path]): sub_module_name = f"{package_name}.{module_info.name}" print(f"Trying to import {sub_module_name}") try: module = importlib.import_module(sub_module_name) print(f"Successfully imported {sub_module_name}") if hasattr(module, "gradio_interface"): print(f"Found gradio_interface in {sub_module_name}") interface_name = module_info.name if interface_name not in gradio_names: gradio_interfaces.append(module.gradio_interface) gradio_names.add(interface_name) else: unique_name = f"{interface_name}_{len(gradio_names)}" gradio_interfaces.append(module.gradio_interface) gradio_names.add(unique_name) except ModuleNotFoundError as e: print(f"ModuleNotFoundError: {sub_module_name} - {e}") except AttributeError as e: print(f"AttributeError in {sub_module_name}: {e}") except Exception as e: print(f"Failed to import {sub_module_name}: {e}") print(traceback.format_exc()) print(f"Collected Gradio Interfaces: {gradio_names}") return gradio_interfaces, list(gradio_names) def setup_gradio_interfaces(): ## #from routers.gra_06_video.video import gradio_interface as video default_interfaces = []#,demo] default_names = ["CreateTASK","Chat","OpenInterpreter","DataBase","CreateFromDOC","HTML","FILES"]#"demo"] gradio_interfaces, gradio_names = include_gradio_interfaces() all_interfaces = default_interfaces + gradio_interfaces all_names = gradio_names tabs = gr.TabbedInterface(all_interfaces, all_names) tabs.queue() return tabs if __name__ == "__main__": interfaces, names = include_gradio_interfaces()