File size: 6,630 Bytes
6634a9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import random
import time

def generate_response(message, temperature, max_tokens, model_mode):
    # شبیه‌سازی پاسخ مدل
    responses = [
        f"سلام! من DeepSeek V3.2 هستم. پیام شما: '{message}' را دریافت کردم.",
        f"با دمای {temperature} و حداکثر {max_tokens} توکن",
        f"DeepSeek V3.2 در حال پردازش پیام شماست...",
        f"پاسخ در حالت '{model_mode}': من در حال تولید متن بر اساس پارامترهای تنظیم شده.",
        f"مدل در حال تحلیل پیام '{message}' و آماده ارائه پاسخ.",
        f"پاسخ مدل با دمای {temperature} و {max_tokens} توکن.",
        f"DeepSeek V3.2 Experimental: پیام شما دریافت شد و در حال پردازش است."
    ]
    
    # شبیه‌سازی تاخیر پردازش
    time.sleep(1)
    
    return random.choice(responses)

def create_chatbot_interface():
    with gr.Blocks() as demo:
        # هدر اصلی
        with gr.Row():
            with gr.Column(scale=1):
                gr.Markdown("# 🧠 DeepSeek V3.2 Experimental")
                gr.Markdown("### رابط کاربری پیشرفته برای مدل زبانی بزرگ")
        
        # محتوی اصلی
        with gr.Row():
            # سایدبار سمت چپ
            with gr.Column(scale=1, min_width=300):
                # اطلاعات مدل
                with gr.Group():
                    gr.Markdown("## 📊 اطلاعات مدل")
                    with gr.Row():
                        gr.Markdown("**نام مدل:** DeepSeek-V3.2-Exp")
                    with gr.Row():
                        gr.Markdown("**ارائه‌دهنده:** Novita")
                    with gr.Row():
                        status_dot = gr.HTML("""<div style="width: 12px; height: 12px; background: #10b981; border-radius: 50%; animation: pulse 2s infinite;"></div>")
                    with gr.Row():
                        gr.Markdown("**وضعیت:** فعال و آماده")
                    with gr.Row():
                        gr.Markdown("**تعداد پارامترها:** 236B")
                    with gr.Row():
                        gr.Markdown("**تاریخ انتشار:** 2024")
        
        # تنظیمات
                with gr.Group():
                    gr.Markdown("## � تنظیمات مدل")
                
                temperature = gr.Slider(
                    minimum=0.0,
                    maximum=1.0,
                    value=0.7,
                    step=0.1,
                    label="دمای مدل (Temperature)"),
                    info="مقادیر بالاتر = خلاقانه‌تر")
                
                max_tokens = gr.Slider(
                    minimum=100,
                    maximum=4096,
                    value=2048,
                    step=1,
                    label="حداکثر توکن‌ها")
                
                model_mode = gr.Dropdown(
                    choices=["خلاقانه", "متعادل", "دقیق"],
                    value="متعادل",
                    label="حالت مدل")
        
        # محیط چت
        with gr.Column(scale=2):
            chatbot = gr.Chatbot(
                value=[
                    {"role": "assistant", "content": "سلام! من DeepSeek V3.2 هستم. چگونه می‌توانم به شما کمک کنم؟"),
                height=500
            )
            
            with gr.Row():
                message_input = gr.Textbox(
                    placeholder="پیام خود را اینجا تایپ کنید...",
                    lines=2,
                    max_lines=5
                )
                
                with gr.Row():
                    clear_btn = gr.Button("🧹 پاک کردن تاریخچه")
                    reset_btn = gr.Button("🔄 راه‌اندازی مجدد")
            
            with gr.Row():
                send_btn = gr.Button("✈️ ارسال پیام", variant="primary")
        
        # ایونت‌ها
        def send_message(message, chat_history, temp, tokens, mode):
                if message.strip() == "":
                    return "", chat_history
                
                # اضافه کردن پیام کاربر
                chat_history.append({"role": "user", "content": message})
                
                # شبیه‌سازی تایپ کردن
                time.sleep(1)
                
                # تولید پاسخ مدل
                bot_response = generate_response(message, temp, tokens, mode)
                chat_history.append({"role": "assistant", "content": bot_response})
                
                return "", chat_history
            
        send_btn.click(
                fn=send_message,
                inputs=[message_input, chatbot, temperature, max_tokens, model_mode],
                outputs=[message_input, chatbot]
            )
            
            clear_btn.click(lambda: None, None, chatbot, queue=False)
            
            def reset_settings():
                return {
                    temperature: 0.7,
                    max_tokens: 2048,
                    model_mode: "متعادل"
                }
            
            reset_btn.click(
                fn=reset_settings,
                outputs=[temperature, max_tokens, model_mode]
            )
    
    return demo

# ایجاد دمو
demo = create_chatbot_interface()

# راه‌اندازی اپلیکیشن
if __name__ == "__main__":
    demo.launch(
        theme=gr.themes.Soft(
            primary_hue="purple",
            secondary_hue="emerald",
            neutral_hue="slate",
            font=gr.themes.GoogleFont("Vazirmatn"),
            text_size="lg",
            spacing_size="lg",
            radius_size="md"
        ).set(
            button_primary_background_fill="*primary_600",
            button_primary_background_fill_hover="*primary_700",
            block_title_text_weight="600"
        ),
        css="""
        .gradio-container {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .darktest {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
        }
        """,
        footer_links=[
            {"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"]
    )