Spaces:
Runtime error
Runtime error
File size: 6,265 Bytes
eeb0f9c |
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 |
import gradio as gr
import logging
import modelscope_studio.components.pro as pro
from modelscope_studio.components.pro.chatbot import (
ChatbotBotConfig, ChatbotDataMessage,
ChatbotPromptsConfig, ChatbotUserConfig, ChatbotWelcomeConfig,
ChatbotActionConfig
)
from modelscope_studio.components.pro.multimodal_input import MultimodalInputUploadConfig
logger = logging.getLogger(__name__)
def create_header():
"""Create the header markdown component and content"""
return gr.Markdown(
"""
# 🏥 Trợ Lý Sức Khỏe AI
### Sức khỏe của bạn cũng là sức khỏe của chúng tôi
⚠️ **Lưu ý:** Đây là tư vấn tham khảo. Hãy gặp bác sĩ cho các vấn đề nghiêm trọng.
"""
)
def create_chatbot():
"""Create the chatbot component with welcome config and prompts"""
return pro.Chatbot(
value=[], # Start with empty history
height=800, # Use flex=1 to fill remaining space
elem_style=dict(flex=1, border="1px solid #eee", borderRadius="8px", padding="10px"),
welcome_config=ChatbotWelcomeConfig(
variant="borderless",
icon="https://photoavatarmaker.com/wp-content/uploads/2025/04/doctor-avatar-sample.jpeg",
title="Xin chào, tôi là Trợ Lý Sức Khỏe AI",
description="Bạn có thể upload hình ảnh và nhập text để bắt đầu.",
prompts=ChatbotPromptsConfig(
title="Tôi có thể giúp bạn gì hôm nay?",
styles={
"list": {
"width": '100%',
},
"item": {
"flex": 1,
},
},
items=[{
"label": "📅 Lập kế hoạch",
"children": [{
"description": "Giúp tôi lập kế hoạch chế độ ăn uống"
}, {
"description": "Giúp tôi lập kế hoạch tập luyện"
}, {
"description": "Giúp tôi lập kế hoạch sức khỏe toàn diện"
}]
}, {
"label": "🏥 Tư vấn sức khỏe",
"children": [{
"description": "Tôi bị đau đầu thường xuyên, nên làm gì?"
}, {
"description": "Làm thế nào để cải thiện giấc ngủ?"
}, {
"description": "Tôi nên ăn gì để tăng cường miễn dịch?"
}]
}])),
user_config=ChatbotUserConfig(
actions=["copy", "edit"],
avatar="https://api.dicebear.com/7.x/miniavs/svg?seed=3"
),
bot_config=ChatbotBotConfig(
header="Trợ Lý Sức Khỏe AI",
actions=["copy", "like", "dislike", "retry",
ChatbotActionConfig(
action="delete",
popconfirm=dict(
title="Delete the message",
description="Are you sure to delete this message?",
okButtonProps=dict(danger=True))
)
],
avatar="https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*s5sNRo5LjfQAAAAAAAAAAAAADgCCAQ/fmt.webp"
),
)
def create_input_row():
"""Create the input block with textbox and submit button inside same container"""
with gr.Group(elem_classes=["input-block"]) as block:
gr.Markdown("💡 Mô tả chi tiết vấn đề của bạn để nhận được lời khuyên phù hợp nhất", elem_classes=["input-label"])
with gr.Row(elem_classes=["input-row"]):
message = gr.Textbox(
label="Nhập tin nhắn của bạn",
placeholder="Ví dụ: Tôi bị đau đầu thường xuyên, nên làm gì?",
elem_classes=["message-input"],
scale=9,
show_label=False,
container=False
)
submit_btn = gr.Button("Gửi", variant="primary", scale=1, size="sm")
return block, message, submit_btn
def create_clear_button():
"""Create the clear button as a badge overlay"""
clear_btn = gr.Button("Xóa lịch sử", variant="secondary", size="sm", elem_classes=["clear-badge"])
return clear_btn
def create_top_header():
"""Create the top header"""
with gr.Row() as row:
welcome_text = gr.Markdown("")
login_btn = gr.Button("🔐 Đăng nhập", scale=1,
elem_classes=["small-button"])
logout_btn = gr.Button("🔐 Đăng xuất", visible=False,
scale=1, elem_classes=["small-button"])
return row, welcome_text, login_btn, logout_btn
def create_login_form():
with gr.Column(visible=False, elem_id="login-form", elem_classes=["login-form-container"]) as column:
gr.Markdown("## 🔐 Đăng nhập để lưu lịch sử",
elem_id="login-title", elem_classes=["login-title"])
username = gr.Textbox(
label="👤 Tên đăng nhập", placeholder="Nhập tên đăng nhập...", lines=1, elem_classes=["login-input"])
password = gr.Textbox(label="🔑 Mật khẩu", placeholder="Nhập mật khẩu...",
type="password", lines=1, elem_classes=["login-input"])
with gr.Row(elem_classes=["login-buttons"]):
login_submit = gr.Button(
"Đăng nhập", variant="primary", elem_classes=["login-btn"])
register_btn = gr.Button(
"Đăng ký", variant="secondary", elem_classes=["register-btn"])
back_btn = gr.Button("Trở lại", variant="primary",
elem_classes=["back-btn"])
status = gr.Textbox(label="Trạng thái",
interactive=False, elem_classes=["login-status"])
return column, username, password, login_submit, register_btn, back_btn, status
|