Alireza1913 commited on
Commit
2deabfd
·
verified ·
1 Parent(s): e156678

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -16
app.py CHANGED
@@ -13,7 +13,7 @@ DATASET_REPO = "Alireza1913/Crazy-Ai-Dataset"
13
  try:
14
  dataset = load_dataset(DATASET_REPO, token=os.environ.get("HF_TOKEN"), split="train")
15
  df = pd.DataFrame(dataset)
16
- TEXT_COLUMN = df.columns[0] if len(df.columns) > 0 else None
17
  except Exception:
18
  df = None
19
  TEXT_COLUMN = None
@@ -37,7 +37,7 @@ textarea { background-color: #120e1e !important; color: #ffffff !important; bord
37
  textarea:focus { border-color: #8b5cf6 !important; outline: none !important; }
38
  """
39
 
40
- # پرامپت‌های ۳ گانه
41
  PROMPTS = {
42
  "Pure Crazy": "You are Kimi K2.6, a SOTA multimodal reasoning model optimized for Lateral Thinking. Avoid obvious, linear answers. Challenge assumptions, explore unexpected workflows, and offer highly creative, out-of-the-box solutions in the user's language.",
43
  "Super Genius": "You are Kimi K2.6, an absolute master in Full-Stack Coding, Mathematics, and Logic. Provide step-by-step, highly analytical, production-ready technical breakdowns in the user's language.",
@@ -56,7 +56,6 @@ def search_knowledge_base(user_query):
56
  except Exception: pass
57
  return ""
58
 
59
- # موتور گفتگوی زنده ۱۰۰٪ همگام با معماری لیست تاپل‌ها در نسخه جدید گرادیو ۶
60
  def stable_chat_engine(message, history, current_mode):
61
  if not message.strip():
62
  yield history
@@ -65,7 +64,6 @@ def stable_chat_engine(message, history, current_mode):
65
  system_prompt = PROMPTS.get(current_mode, PROMPTS["Pure Crazy"])
66
  formatted_messages = [{"role": "system", "content": system_prompt}]
67
 
68
- # پردازش تاریخچه به فرمت لیست تاپل برای مدل
69
  for user_msg, bot_msg in history:
70
  if user_msg: formatted_messages.append({"role": "user", "content": user_msg})
71
  if bot_msg: formatted_messages.append({"role": "assistant", "content": bot_msg})
@@ -73,7 +71,6 @@ def stable_chat_engine(message, history, current_mode):
73
  full_payload = message + search_knowledge_base(message)
74
  formatted_messages.append({"role": "user", "content": full_payload})
75
 
76
- # اضافه کردن ساختار تاپل به تاریخچه چت بر اساس نیاز گرادیو ۶ جدید
77
  updated_history = list(history)
78
  updated_history.append((message, ""))
79
  yield updated_history
@@ -104,12 +101,12 @@ def stable_chat_engine(message, history, current_mode):
104
  updated_history[-1] = (message, f"⚠️ Backend Connection Error: {str(e)}")
105
  yield updated_history
106
 
107
- # رفع باگ فراخوانی css و حذف کلید خطاساز title از Blocks طبق هشدارهای لاگ تصویر شما
108
- with gr.Blocks(css=PREMIUM_UI_CSS) as demo:
109
  active_mode = gr.State("Pure Crazy")
110
 
111
  with gr.Row():
112
- # سایدبار سمت چپ همراه با لوگو
113
  with gr.Column(scale=1, elem_classes="sidebar-panel"):
114
  gr.HTML(f'<div class="logo-container"><img src="{LOGO_URL}" class="logo-img" alt="Crazy AI"></div>')
115
  gr.HTML('<h2 class="brand-title">CRAZY AI</h2>')
@@ -125,11 +122,10 @@ with gr.Blocks(css=PREMIUM_UI_CSS) as demo:
125
  gr.Markdown("<br><b style='color:#5c5573; font-size:12px; letter-spacing:1px;'>RECENT SESSIONS</b>")
126
  gr.Button("• Deep Learning Architectures", elem_classes="preset-btn")
127
 
128
- # کادر اصلی چت سمت راست با فرمت ساختاری اصلاح شده پایدار
129
  with gr.Column(scale=3, elem_classes="chat-window"):
130
  mode_display = gr.Markdown("### 🛰️ Active Mode: **Pure Crazy** (Mad Lateral Thinking)")
131
 
132
- # حذف آرگومان منسوخ‌شده type="messages" برای از بین بردن قطعی خطای لاگ تصویر
133
  chatbot = gr.Chatbot(height=500, show_label=False)
134
 
135
  with gr.Row():
@@ -141,7 +137,6 @@ with gr.Blocks(css=PREMIUM_UI_CSS) as demo:
141
  )
142
  submit_btn = gr.Button("⚡ Send", scale=1)
143
 
144
- # مدیریت دکمه‌های ناوبری مدها
145
  def set_genius(): return "Super Genius", "### 🛰️ Active Mode: **Super Genius** (Logic & Mathematics)"
146
  def set_philo(): return "Philosophical", "### 🛰️ Active Mode: **Philosophical** (Ideas & Metaphors)"
147
  def set_crazy(): return "Pure Crazy", "### 🛰️ Active Mode: **Pure Crazy** (Mad Lateral Thinking)"
@@ -150,23 +145,20 @@ with gr.Blocks(css=PREMIUM_UI_CSS) as demo:
150
  btn_philo.click(fn=set_philo, outputs=[active_mode, mode_display])
151
  btn_crazy.click(fn=set_crazy, outputs=[active_mode, mode_display])
152
 
153
- # منطق زدن دکمه ارسال پیام
154
  submit_btn.click(
155
  fn=stable_chat_engine,
156
  inputs=[txt_input, chatbot, active_mode],
157
  outputs=[chatbot]
158
  ).then(fn=lambda: "", outputs=[txt_input])
159
 
160
- # منطق زدن دکمه اینتر کیبورد
161
  txt_input.submit(
162
  fn=stable_chat_engine,
163
  inputs=[txt_input, chatbot, active_mode],
164
  outputs=[chatbot]
165
  ).then(fn=lambda: "", outputs=[txt_input])
166
 
167
- # دکمه پاک‌سازی چت
168
  clear_btn.click(fn=lambda: ([], ""), outputs=[chatbot, txt_input])
169
 
170
  if __name__ == "__main__":
171
- # انتقال آرگومان title به متد launch برای جلوگیری از UserWarning مجدد کانتینر
172
- demo.launch(title="Crazy AI Studio")
 
13
  try:
14
  dataset = load_dataset(DATASET_REPO, token=os.environ.get("HF_TOKEN"), split="train")
15
  df = pd.DataFrame(dataset)
16
+ TEXT_COLUMN = df.columns if len(df.columns) > 0 else None
17
  except Exception:
18
  df = None
19
  TEXT_COLUMN = None
 
37
  textarea:focus { border-color: #8b5cf6 !important; outline: none !important; }
38
  """
39
 
40
+ # پرامپت‌های ۳ گانه سیستم
41
  PROMPTS = {
42
  "Pure Crazy": "You are Kimi K2.6, a SOTA multimodal reasoning model optimized for Lateral Thinking. Avoid obvious, linear answers. Challenge assumptions, explore unexpected workflows, and offer highly creative, out-of-the-box solutions in the user's language.",
43
  "Super Genius": "You are Kimi K2.6, an absolute master in Full-Stack Coding, Mathematics, and Logic. Provide step-by-step, highly analytical, production-ready technical breakdowns in the user's language.",
 
56
  except Exception: pass
57
  return ""
58
 
 
59
  def stable_chat_engine(message, history, current_mode):
60
  if not message.strip():
61
  yield history
 
64
  system_prompt = PROMPTS.get(current_mode, PROMPTS["Pure Crazy"])
65
  formatted_messages = [{"role": "system", "content": system_prompt}]
66
 
 
67
  for user_msg, bot_msg in history:
68
  if user_msg: formatted_messages.append({"role": "user", "content": user_msg})
69
  if bot_msg: formatted_messages.append({"role": "assistant", "content": bot_msg})
 
71
  full_payload = message + search_knowledge_base(message)
72
  formatted_messages.append({"role": "user", "content": full_payload})
73
 
 
74
  updated_history = list(history)
75
  updated_history.append((message, ""))
76
  yield updated_history
 
101
  updated_history[-1] = (message, f"⚠️ Backend Connection Error: {str(e)}")
102
  yield updated_history
103
 
104
+ # حذف کامل پارامترهای تداخل‌ساز جهت تضمین بیلد بدون نقص
105
+ with gr.Blocks() as demo:
106
  active_mode = gr.State("Pure Crazy")
107
 
108
  with gr.Row():
109
+ # سایدبار سمت چپ
110
  with gr.Column(scale=1, elem_classes="sidebar-panel"):
111
  gr.HTML(f'<div class="logo-container"><img src="{LOGO_URL}" class="logo-img" alt="Crazy AI"></div>')
112
  gr.HTML('<h2 class="brand-title">CRAZY AI</h2>')
 
122
  gr.Markdown("<br><b style='color:#5c5573; font-size:12px; letter-spacing:1px;'>RECENT SESSIONS</b>")
123
  gr.Button("• Deep Learning Architectures", elem_classes="preset-btn")
124
 
125
+ # کادر اصلی چت سمت راست
126
  with gr.Column(scale=3, elem_classes="chat-window"):
127
  mode_display = gr.Markdown("### 🛰️ Active Mode: **Pure Crazy** (Mad Lateral Thinking)")
128
 
 
129
  chatbot = gr.Chatbot(height=500, show_label=False)
130
 
131
  with gr.Row():
 
137
  )
138
  submit_btn = gr.Button("⚡ Send", scale=1)
139
 
 
140
  def set_genius(): return "Super Genius", "### 🛰️ Active Mode: **Super Genius** (Logic & Mathematics)"
141
  def set_philo(): return "Philosophical", "### 🛰️ Active Mode: **Philosophical** (Ideas & Metaphors)"
142
  def set_crazy(): return "Pure Crazy", "### 🛰️ Active Mode: **Pure Crazy** (Mad Lateral Thinking)"
 
145
  btn_philo.click(fn=set_philo, outputs=[active_mode, mode_display])
146
  btn_crazy.click(fn=set_crazy, outputs=[active_mode, mode_display])
147
 
 
148
  submit_btn.click(
149
  fn=stable_chat_engine,
150
  inputs=[txt_input, chatbot, active_mode],
151
  outputs=[chatbot]
152
  ).then(fn=lambda: "", outputs=[txt_input])
153
 
 
154
  txt_input.submit(
155
  fn=stable_chat_engine,
156
  inputs=[txt_input, chatbot, active_mode],
157
  outputs=[chatbot]
158
  ).then(fn=lambda: "", outputs=[txt_input])
159
 
 
160
  clear_btn.click(fn=lambda: ([], ""), outputs=[chatbot, txt_input])
161
 
162
  if __name__ == "__main__":
163
+ # تمامی پارامترهای ظاهری و استایل سفارشی به طور یکپارچه به متد نهایی فرستاده شدند
164
+ demo.launch(css=PREMIUM_UI_CSS)