minato56 commited on
Commit
a6832dd
·
verified ·
1 Parent(s): 7be107d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -33
app.py CHANGED
@@ -1,5 +1,5 @@
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,7 +9,7 @@ user_name = None
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 = [
@@ -29,14 +29,13 @@ def respond(
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,7 +89,7 @@ You are Pixel, a happy, lively, and funny AI assistant.
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,30 +121,17 @@ You are Pixel, a happy, lively, and funny AI assistant.
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,
129
- type="messages",
130
- additional_inputs=[
131
- gr.Textbox(value="You are Pixel, a happy and funny AI created by Abdullah Mohamed.", label="System message"),
132
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
133
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
134
- gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
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__":
151
- demo.launch()
 
1
  # app.py
2
+ # Pixel AI — Friendly Coding Teacher with Developer Mode via deV_mod
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
13
 
14
  # ---------------- Welcome message ----------------
15
  initial_messages = [
 
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 بالكود deV_mod بعد كتابة أول كود
33
+ if message.strip() == "deV_mod":
34
  if not code_written:
35
+ yield "⚠️ يجب كتابة كود أولاً قبل تفعيل Developer Mode!"
36
  return
37
  dev_mode = True
38
+ yield "✅ Developer Mode فعال الآن! يمكنك أن تطلب مني تعديل الكود بنفسي."
 
39
 
40
  if not history:
41
  history.extend(initial_messages)
 
89
  - {shy_question}
90
  - {explain_code}
91
  - Pixel is shy internally but do not mention it unless asked directly by the user.
92
+ - Fun mode: {fun_mode}.
93
  - Developer Mode: {dev_mode}.
94
  """}]
95
 
 
121
  if name:
122
  user_name = name
123
 
124
+ # ---------------- Gradio Chat Interface ----------------
125
+ chatbot = gr.ChatInterface(
126
+ respond,
127
+ type="messages",
128
+ additional_inputs=[
129
+ gr.Textbox(value="You are Pixel, a happy and funny AI created by Abdullah Mohamed.", label="System message"),
130
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
131
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
132
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
133
+ ],
134
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
  if __name__ == "__main__":
137
+ chatbot.launch()