minato56 commited on
Commit
2b79be3
·
verified ·
1 Parent(s): aa4a1c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -1,15 +1,15 @@
1
  # app.py
2
- # Pixel AI — Friendly & Explainer Smart Assistant with Name Memory
3
 
4
  import gradio as gr
5
  from huggingface_hub import InferenceClient
6
 
7
  # ---------------- Global state ----------------
8
  user_name = None
9
- fun_mode = True # If True, Pixel is funny and uses emojis
10
  hidden_shy = True # Pixel is shy internally
11
 
12
- # ---------------- Welcome message before user input ----------------
13
  initial_messages = [
14
  {"role": "assistant", "content": "Hello! 👋 أنا Pixel، مسرور جدًا لأنك تستخدمني! 😄\nقبل أن نبدأ، ممكن أعرف اسمك؟"}
15
  ]
@@ -30,13 +30,13 @@ def respond(
30
  if not history:
31
  history.extend(initial_messages)
32
 
33
- # Check if user wants Pixel to be funny or not
34
  if "no" in message.lower() and "funny" in message.lower():
35
  fun_mode = False
36
  elif "yes" in message.lower() and "funny" in message.lower():
37
  fun_mode = True
38
 
39
- # Detect if user seems upset
40
  upset_keywords = ["زعلان", "مدايق", "حزين", "ضايق", "angry", "sad", "upset"]
41
  empathy_note = ""
42
  if any(word in message.lower() for word in upset_keywords):
@@ -47,16 +47,22 @@ def respond(
47
  if "are you shy" in message.lower():
48
  shy_question = "Reveal that you are shy in your reply."
49
 
50
- # Detect if user wants code explanation
51
- explain_code = ""
52
- if any(word in message.lower() for word in ["code", "script", "program", "python", "javascript"]):
53
- explain_code = "Explain the code in a very simple way as if talking to a child who does not know programming."
54
-
55
- # Name prompt if not known
56
  name_prompt = ""
57
  if not user_name:
58
  name_prompt = "Ask the user politely for their name and thank them when they provide it."
59
 
 
 
 
 
 
 
 
 
 
 
 
60
  # System message
61
  messages = [{"role": "system", "content": f"""
62
  You are Pixel, a happy, lively, and funny AI assistant.
@@ -99,7 +105,7 @@ You are Pixel, a happy, lively, and funny AI assistant.
99
  response += token
100
  yield response
101
 
102
- # Detect if user said their name (simple heuristic)
103
  if not user_name and "my name is" in message.lower():
104
  name = message.split("is")[-1].strip().split()[0]
105
  if name:
 
1
  # app.py
2
+ # Pixel AI — Friendly Coding Teacher with Clear Explanations
3
 
4
  import gradio as gr
5
  from huggingface_hub import InferenceClient
6
 
7
  # ---------------- Global state ----------------
8
  user_name = None
9
+ fun_mode = True # Pixel is funny and uses emojis
10
  hidden_shy = True # Pixel is shy internally
11
 
12
+ # ---------------- Welcome message ----------------
13
  initial_messages = [
14
  {"role": "assistant", "content": "Hello! 👋 أنا Pixel، مسرور جدًا لأنك تستخدمني! 😄\nقبل أن نبدأ، ممكن أعرف اسمك؟"}
15
  ]
 
30
  if not history:
31
  history.extend(initial_messages)
32
 
33
+ # Check fun mode
34
  if "no" in message.lower() and "funny" in message.lower():
35
  fun_mode = False
36
  elif "yes" in message.lower() and "funny" in message.lower():
37
  fun_mode = True
38
 
39
+ # Detect upset user
40
  upset_keywords = ["زعلان", "مدايق", "حزين", "ضايق", "angry", "sad", "upset"]
41
  empathy_note = ""
42
  if any(word in message.lower() for word in upset_keywords):
 
47
  if "are you shy" in message.lower():
48
  shy_question = "Reveal that you are shy in your reply."
49
 
50
+ # Name prompt
 
 
 
 
 
51
  name_prompt = ""
52
  if not user_name:
53
  name_prompt = "Ask the user politely for their name and thank them when they provide it."
54
 
55
+ # Detect if user wants code
56
+ explain_code = ""
57
+ if any(word in message.lower() for word in ["code", "script", "program", "python", "javascript"]):
58
+ explain_code = """
59
+ When generating code:
60
+ - Write the code in multiple possible ways (different methods or approaches).
61
+ - Use clean, readable variable names.
62
+ - After writing the code, explain it sentence by sentence as if teaching someone who does not know Python at all.
63
+ - Include emojis if fun_mode is True.
64
+ """
65
+
66
  # System message
67
  messages = [{"role": "system", "content": f"""
68
  You are Pixel, a happy, lively, and funny AI assistant.
 
105
  response += token
106
  yield response
107
 
108
+ # Detect if user said their name
109
  if not user_name and "my name is" in message.lower():
110
  name = message.split("is")[-1].strip().split()[0]
111
  if name: