File size: 2,310 Bytes
3d2aa58
024edca
de235e2
1afbeb8
f669ed4
1afbeb8
 
 
5684888
 
 
1afbeb8
824093d
1afbeb8
 
 
7bfb334
1afbeb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
024edca
 
f008d39
33cf9a2
5684888
6eeeb07
024edca
1afbeb8
 
 
95dc2cf
1afbeb8
 
024edca
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
def include_gradio_interfaces():
    package_dir = "/home/user/app/routers"
    gradio_interfaces = []
    gradio_names = set()

    for module_info in pkgutil.walk_packages([package_dir], "controllers."):
        sub_module_name = module_info.name
        try:
            print(f"Trying to import {sub_module_name}")
            module = importlib.import_module(sub_module_name)
            if hasattr(module, "gradio_interface"):
                print(f"Found gradio_interface in {sub_module_name}")
                interface_name = module_info.name.split(".")[-1]
                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:
            print(f"ModuleNotFoundError: {sub_module_name}")
            pass
        except Exception as e:
            print(f"Failed to import {sub_module_name}: {e}")

    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 = [gradio_babyagi,gradio_interface,create_ui()]#,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 = default_names + gradio_names

    tabs = gr.TabbedInterface(all_interfaces, all_names)
    tabs.queue()
    return tabs