Mmdv2's picture
Update app.py from anycoder
6634a9f verified
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"]
)