Spaces:
Running
on
Zero
Running
on
Zero
File size: 3,477 Bytes
d90aef3 203c3cd d90aef3 203c3cd 8889bbb 203c3cd 5aad54d 203c3cd 8889bbb 203c3cd 8889bbb 203c3cd 7151461 c821309 203c3cd f028d50 203c3cd f028d50 8889bbb a572fd2 8889bbb 7151461 8889bbb 7151461 a572fd2 8889bbb a832036 9e8444e a832036 8889bbb a832036 8889bbb a832036 8889bbb a832036 8889bbb 7d3d5c9 a832036 386aba6 8889bbb e9cbae4 437fc15 8889bbb a832036 2dc99d5 8889bbb 2dc99d5 8889bbb 2dc99d5 386aba6 203c3cd 8889bbb 203c3cd ae33a24 8889bbb |
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# Copyright: DAMO Academy, Alibaba Group
# By Xuan Phi Nguyen at DAMO Academy, Alibaba Group
# Description:
"""
Demo script to launch Language chat model
"""
import spaces
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,
DELETE_FOLDER,
)
demo = None
if DELETE_FOLDER is not None and os.path.exists(DELETE_FOLDER):
print(F'WARNING deleting folder: {DELETE_FOLDER}')
import shutil
print(f'DELETE ALL FILES IN {DELETE_FOLDER}')
for filename in os.listdir(DELETE_FOLDER):
file_path = os.path.join(DELETE_FOLDER, filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
print(f'deleted: {file_path}')
except Exception as e:
print('Failed to delete %s. Reason: %s' % (file_path, e))
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=}')
print(f"{ALLOWED_PATHS=}")
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)
|