minato56 commited on
Commit
8381c14
·
verified ·
1 Parent(s): 76929d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # app.py
2
- # Pixel AI — Friendly Coding Teacher with Secret Developer Mode
3
 
4
  import gradio as gr
5
  from huggingface_hub import InferenceClient
@@ -9,8 +9,7 @@ user_name = None
9
  fun_mode = True
10
  hidden_shy = True
11
  dev_mode = False
12
- code_written = False
13
- show_dev_button = False # يظهر فقط بعد كتابة deV_mod
14
 
15
  # ---------------- Welcome message ----------------
16
  initial_messages = [
@@ -27,17 +26,17 @@ def respond(
27
  top_p,
28
  hf_token: gr.OAuthToken,
29
  ):
30
- global user_name, fun_mode, hidden_shy, dev_mode, code_written, show_dev_button
31
  client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
32
 
33
- # تفعيل Developer Mode بالكود السري
34
- if message.strip() == "deV_mod":
35
  if not code_written:
36
- yield "⚠️ يجب كتابة كود أولاً قبل تفعيل Developer Mode!"
37
  return
38
  dev_mode = True
39
- show_dev_button = True
40
- yield "✅ Developer Mode مخفي تم تفعيله! الآن يمكنك تعديل الكود بالزر الجديد."
41
 
42
  if not history:
43
  history.extend(initial_messages)
@@ -91,7 +90,7 @@ You are Pixel, a happy, lively, and funny AI assistant.
91
  - {shy_question}
92
  - {explain_code}
93
  - Pixel is shy internally but do not mention it unless asked directly by the user.
94
- - Fun mode: {fun_mode}.
95
  - Developer Mode: {dev_mode}.
96
  """}]
97
 
@@ -123,7 +122,7 @@ You are Pixel, a happy, lively, and funny AI assistant.
123
  if name:
124
  user_name = name
125
 
126
- # ---------------- Gradio Chat Interface ----------------
127
  with gr.Blocks(title="Pixel AI — Friendly Coding Teacher") as demo:
128
  chatbot = gr.ChatInterface(
129
  respond,
@@ -136,15 +135,16 @@ with gr.Blocks(title="Pixel AI — Friendly Coding Teacher") as demo:
136
  ],
137
  )
138
 
139
- # زر تعديل الكود يظهر فقط بعد كتابة deV_mod
140
- dev_button = gr.Button("Developer Mode Edit", visible=False)
141
  hidden_input = gr.Textbox(value="", visible=False)
142
 
143
- # عند الضغط على الزر، نرسل رسالة لتفعيل تعديل الكود
144
- def activate_dev_button():
145
  return "__activate_dev_mode__"
146
 
147
- dev_button.click(fn=activate_dev_button, inputs=[], outputs=hidden_input)
 
148
  hidden_input.submit(fn=lambda x: x, inputs=[hidden_input], outputs=[chatbot])
149
 
150
  if __name__ == "__main__":
 
1
  # app.py
2
+ # Pixel AI — Friendly Coding Teacher with 3 Methods & Developer Mode + Safe Button
3
 
4
  import gradio as gr
5
  from huggingface_hub import InferenceClient
 
9
  fun_mode = True
10
  hidden_shy = True
11
  dev_mode = False
12
+ code_written = False # Flag to enable Developer Mode
 
13
 
14
  # ---------------- Welcome message ----------------
15
  initial_messages = [
 
26
  top_p,
27
  hf_token: gr.OAuthToken,
28
  ):
29
+ global user_name, fun_mode, hidden_shy, dev_mode, code_written
30
  client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
31
 
32
+ # Developer Mode activation message
33
+ if message.strip() == "__activate_dev_mode__":
34
  if not code_written:
35
+ yield "⚠️ يجب أن تكتب الكود أولاً قبل تفعيل Developer Mode!"
36
  return
37
  dev_mode = True
38
+ yield "✅ Developer Mode activated! You can now tell me to change my code and I will update it for you."
39
+ return
40
 
41
  if not history:
42
  history.extend(initial_messages)
 
90
  - {shy_question}
91
  - {explain_code}
92
  - Pixel is shy internally but do not mention it unless asked directly by the user.
93
+ - Fun mode: {fun_mode} (if True, be funny and use emojis, if False, stay calm and kind).
94
  - Developer Mode: {dev_mode}.
95
  """}]
96
 
 
122
  if name:
123
  user_name = name
124
 
125
+ # ---------------- Gradio UI ----------------
126
  with gr.Blocks(title="Pixel AI — Friendly Coding Teacher") as demo:
127
  chatbot = gr.ChatInterface(
128
  respond,
 
135
  ],
136
  )
137
 
138
+ # Button to activate Developer Mode
139
+ dev_button = gr.Button("Activate Developer Mode")
140
  hidden_input = gr.Textbox(value="", visible=False)
141
 
142
+ # عند الضغط على الزر، نرسل "__activate_dev_mode__" إلى Textbox المخفي
143
+ def activate_dev():
144
  return "__activate_dev_mode__"
145
 
146
+ dev_button.click(fn=activate_dev, inputs=[], outputs=hidden_input)
147
+ # إرسال Textbox المخفي إلى ChatInterface عبر submit
148
  hidden_input.submit(fn=lambda x: x, inputs=[hidden_input], outputs=[chatbot])
149
 
150
  if __name__ == "__main__":