File size: 2,769 Bytes
bd0e607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright: DAMO Academy, Alibaba Group
# By Xuan Phi Nguyen at DAMO Academy, Alibaba Group

# Description:
"""
Demo script to launch Language chat model 
"""


import os
from gradio.themes import ThemeClass as Theme
import numpy as np
import argparse
# import torch
import gradio as gr
from typing import Any, Iterator
from typing import Iterator, List, Optional, Tuple
import filelock
import glob
import json
import time
from gradio.routes import Request
from gradio.utils import SyncToAsyncIterator, async_iteration
from gradio.helpers import special_args
import anyio
from typing import AsyncGenerator, Callable, Literal, Union, cast

from gradio_client.documentation import document, set_documentation_group

from typing import List, Optional, Union, Dict, Tuple
from tqdm.auto import tqdm
from huggingface_hub import snapshot_download
from langchain_community.embeddings import HuggingFaceEmbeddings, HuggingFaceBgeEmbeddings
from gradio.components import Button, Component
from gradio.events import Dependency, EventListenerMethod

from multipurpose_chatbot.demos.base_demo import CustomTabbedInterface

from multipurpose_chatbot.configs import (
    MODEL_TITLE,
    MODEL_DESC,
    MODEL_INFO,
    CITE_MARKDOWN,
    ALLOWED_PATHS,
    PROXY,
    PORT,
    MODEL_PATH,
    MODEL_NAME,
    BACKEND,
    DEMOS,
)


demo = None





def launch_demo():
    global demo, MODEL_ENGINE
    model_desc = MODEL_DESC
    model_path = MODEL_PATH

    print(f'Begin importing models')
    from multipurpose_chatbot.demos import get_demo_class

    # demos = {
    #     k: get_demo_class(k)().create_demo()
    #     for k in demo_and_tab_names.keys()
    # }
    print(f'{DEMOS=}')
    demo_class_objects = {
        k: get_demo_class(k)()
        for k in DEMOS
    }
    demos = {
        k: get_demo_class(k)().create_demo()
        for k in DEMOS
    }
    demos_names = [x.tab_name for x in demo_class_objects.values()]

    descriptions = model_desc
    if MODEL_INFO is not None and MODEL_INFO != "":
        descriptions += (
            f"<br>" + 
            MODEL_INFO.format(model_path=model_path)
        )

    demo = CustomTabbedInterface(
        interface_list=list(demos.values()),
        tab_names=demos_names,
        title=f"{MODEL_TITLE}",
        description=descriptions,
    )

    demo.title = MODEL_NAME
    
    with demo:
        gr.Markdown(CITE_MARKDOWN)
        
    demo.queue(api_open=False)
    return demo



if __name__ == "__main__":
    demo = launch_demo()
    if PROXY is not None and PROXY != "":
        print(f'{PROXY=} {PORT=}')
        demo.launch(server_port=PORT, root_path=PROXY, show_api=False, allowed_paths=ALLOWED_PATHS)
    else:
        demo.launch(server_port=PORT, show_api=False, allowed_paths=ALLOWED_PATHS)