File size: 7,589 Bytes
dacd46c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import os
from modelscope_studio.components.pro.chatbot import ChatbotActionConfig, ChatbotBotConfig, ChatbotUserConfig, ChatbotWelcomeConfig, ChatbotMarkdownConfig
from modelscope_studio.components.pro.multimodal_input import MultimodalInputUploadConfig
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Oss

# OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET。
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

endpoint = os.getenv("OSS_ENDPOINT")

region = os.getenv("OSS_REGION")

bucket_name = os.getenv("OSS_BUCKET_NAME")

bucket = oss2.Bucket(auth, endpoint, bucket_name, region=region)

# Env
is_cn = os.getenv('MODELSCOPE_ENVIRONMENT') == 'studio'
api_key = os.getenv('API_KEY')
base_url = "https://dashscope.aliyuncs.com/compatible-mode/v1"


def get_text(text: str, cn_text: str):
    if is_cn:
        return cn_text
    return text


# Save history in browser
save_history = True
MODEL = "qwen3-vl-235b-a22b-instruct"
THINKING_MODEL = "qwen3-vl-235b-a22b-thinking"


# Chatbot Config
def markdown_config():
    return ChatbotMarkdownConfig()


def user_config(disabled_actions=None):
    return ChatbotUserConfig(
        class_names=dict(content="user-message-content"),
        actions=[
            "copy", "edit",
            ChatbotActionConfig(
                action="delete",
                popconfirm=dict(title=get_text("Delete the message", "删除消息"),
                                description=get_text(
                                    "Are you sure to delete this message?",
                                    "确认删除该消息?"),
                                okButtonProps=dict(danger=True)))
        ],
        disabled_actions=disabled_actions)


def bot_config(disabled_actions=None):
    return ChatbotBotConfig(actions=[
        "copy", "edit",
        ChatbotActionConfig(
            action="retry",
            popconfirm=dict(
                title=get_text("Regenerate the message", "重新生成消息"),
                description=get_text(
                    "Regenerate the message will also delete all subsequent messages.",
                    "重新生成消息会删除所有后续消息。"),
                okButtonProps=dict(danger=True))),
        ChatbotActionConfig(action="delete",
                            popconfirm=dict(
                                title=get_text("Delete the message", "删除消息"),
                                description=get_text(
                                    "Are you sure to delete this message?",
                                    "确认删除该消息?"),
                                okButtonProps=dict(danger=True)))
    ],
                            avatar="./assets/qwen.png",
                            disabled_actions=disabled_actions)


def welcome_config():
    return ChatbotWelcomeConfig(
        variant="borderless",
        icon="./assets/qwen.png",
        title=get_text("Hello, I'm Qwen3-VL", "你好,我是 Qwen3-VL"),
        description=get_text(
            "Enter text and upload images or videos to get started.",
            "输入文本并上传图片或视频,开始对话吧。"),
        prompts=dict(
            title=get_text("How can I help you today?", "有什么我能帮助您的吗?"),
            styles={
                "list": {
                    "width": '100%',
                },
                "item": {
                    "flex": 1,
                },
            },
            items=[{
                "label":
                get_text("🤔 Logic Reasoning", "🤔 逻辑推理"),
                "children": [{
                    "urls": [
                        "https://misc-assets.oss-cn-beijing.aliyuncs.com/Qwen/Qwen3-VL-Demo/r-1-1.png",
                        "https://misc-assets.oss-cn-beijing.aliyuncs.com/Qwen/Qwen3-VL-Demo/r-1-2.png",
                        "https://misc-assets.oss-cn-beijing.aliyuncs.com/Qwen/Qwen3-VL-Demo/r-1-3.png"
                    ],
                    "description":
                    get_text(
                        "Which one of these does the kitty seem to want to try first?",
                        "这只猫看起来要尝试先做什么?")
                }, {
                    "urls": [
                        "https://misc-assets.oss-cn-beijing.aliyuncs.com/Qwen/Qwen3-VL-Demo/r-2.png",
                    ],
                    "description":
                    get_text(
                        "In the circuit, the diodes are ideal and the voltage source is Vs = 4 sin(ωt) V. Find the value measured on the ammeter.",
                        "电路中的 diodes 是理想的,电压源为 Vs = 4 sin(ωt) V。求电流表测量的数值。")
                }, {
                    "urls": [
                        "https://misc-assets.oss-cn-beijing.aliyuncs.com/Qwen/Qwen3-VL-Demo/r-3.png"
                    ],
                    "description":
                    get_text(
                        "Which is the most popular Friday drink in Boston?\nAnswer the question using a single word or phrase.",
                        " Boston 的星期五饮料中最受欢迎的是什么?\n请用一个单词或短语回答该问题。")
                }]
            }, {
                "label":
                get_text("👨‍💻 Coding", "👨‍💻 编程"),
                "children": [
                    {
                        "urls": [
                            "https://misc-assets.oss-cn-beijing.aliyuncs.com/Qwen/Qwen3-VL-Demo/c-1.png"
                        ],
                        "description":
                        get_text(
                            "Create the webpage using HTML and CSS based on my sketch design. Color it in dark mode.",
                            "基于我的草图设计,用 HTML 和 CSS 创建网页,并暗色模式下颜色。")
                    },
                    {
                        "urls": [
                            "https://misc-assets.oss-cn-beijing.aliyuncs.com/Qwen/Qwen3-VL-Demo/c-2.png"
                        ],
                        "description":
                        get_text(
                            "Solve the problem using C++. Starter code:\nclass Solution {\npublic:\n    int countStableSubsequences(vector<int>& nums) {\n\n    }\n};",
                            "使用 C++ 解决问题。起始代码:\nclass Solution {\npublic:\n    int countStableSubsequences(vector<int>& nums) {\n\n    }\n};"
                        )
                    },
                    {
                        "urls": [
                            "https://misc-assets.oss-cn-beijing.aliyuncs.com/Qwen/Qwen3-VL-Demo/c-3.png"
                        ],
                        "description":
                        get_text("How to draw this plot using matplotlib?",
                                 "如何使用 matplotlib 绘制这张图?")
                    },
                ]
            }]),
    )


def upload_config():
    return MultimodalInputUploadConfig(
        accept="image/*,video/*",
        placeholder={
            "inline": {
                "title":
                "Upload files",
                "description":
                "Click or drag files to this area to upload images or videos"
            },
            "drop": {
                "title": "Drop files here",
            }
        })


DEFAULT_SYS_PROMPT = "You are a helpful and harmless assistant."

DEFAULT_THEME = {
    "token": {
        "colorPrimary": "#6A57FF",
    }
}