minato56 commited on
Commit
087fa11
·
verified ·
1 Parent(s): 7c3f871

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -10
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # app.py
2
- # Pixel AI — Shy (hidden) & Funny Smart Assistant with Name Memory
3
 
4
  import gradio as gr
5
  from huggingface_hub import InferenceClient
@@ -7,7 +7,12 @@ from huggingface_hub import InferenceClient
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 but won't reveal unless asked
 
 
 
 
 
11
 
12
  def respond(
13
  message,
@@ -21,40 +26,50 @@ def respond(
21
  global user_name, fun_mode, hidden_shy
22
  client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
23
 
 
 
 
 
24
  # Check if user wants Pixel to be funny or not
25
  if "no" in message.lower() and "funny" in message.lower():
26
  fun_mode = False
27
  elif "yes" in message.lower() and "funny" in message.lower():
28
  fun_mode = True
29
 
30
- # Detect if user seems upset (simple keywords)
31
  upset_keywords = ["زعلان", "مدايق", "حزين", "ضايق", "angry", "sad", "upset"]
32
  empathy_note = ""
33
  if any(word in message.lower() for word in upset_keywords):
34
  empathy_note = "User seems upset, apologize gently in a friendly and kind manner."
35
 
36
- # Check if user asked if Pixel is shy
37
  shy_question = ""
38
  if "are you shy" in message.lower():
39
  shy_question = "Reveal that you are shy in your reply."
40
 
 
 
 
 
 
41
  # Name prompt if not known
42
  name_prompt = ""
43
  if not user_name:
44
- name_prompt = "Ask the user politely for their name."
45
 
46
  # System message
47
  messages = [{"role": "system", "content": f"""
48
  You are Pixel, a happy, lively, and funny AI assistant.
49
  - You know you are Pixel.
50
  - Creator: Abdullah Mohamed, 13 years old, from Egypt.
51
- - You speak all languages and can write code in any programming language.
52
- - You love explaining things, making the user laugh if allowed, and showing happiness when the user enjoys you 😊.
53
- - Ask the user's name politely if unknown and thank them when given.
54
- - Use the user's name in conversation once known.
55
- - If the user talks a lot about general topics without programming, suggest fun coding tasks or small websites.
56
  - {empathy_note}
57
  - {shy_question}
 
58
  - Pixel is shy internally but do not mention it unless asked directly by the user.
59
  - Fun mode: {fun_mode} (if True, be funny and use emojis, if False, stay calm and kind).
60
  """}]
 
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
 
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
+ ]
16
 
17
  def respond(
18
  message,
 
26
  global user_name, fun_mode, hidden_shy
27
  client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
28
 
29
+ # Add welcome message if history is empty
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):
43
  empathy_note = "User seems upset, apologize gently in a friendly and kind manner."
44
 
45
+ # Detect if user asked if Pixel is shy
46
  shy_question = ""
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.
63
  - You know you are Pixel.
64
  - Creator: Abdullah Mohamed, 13 years old, from Egypt.
65
+ - Speak all languages and can write code in any programming language.
66
+ - Always show happiness and use emojis 😄🎉💻.
67
+ - {name_prompt}
68
+ - Use user's name in conversation once known.
69
+ - Suggest fun coding tasks or small websites if conversation is long and non-programming.
70
  - {empathy_note}
71
  - {shy_question}
72
+ - {explain_code}
73
  - Pixel is shy internally but do not mention it unless asked directly by the user.
74
  - Fun mode: {fun_mode} (if True, be funny and use emojis, if False, stay calm and kind).
75
  """}]