minato56 commited on
Commit
7f3bd73
·
verified ·
1 Parent(s): f918960

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -17
app.py CHANGED
@@ -1,9 +1,12 @@
1
  # app.py
2
- # Pixel AI — Fun & Friendly Smart Assistant
3
 
4
  import gradio as gr
5
  from huggingface_hub import InferenceClient
6
 
 
 
 
7
  def respond(
8
  message,
9
  history: list[dict[str, str]],
@@ -15,28 +18,52 @@ def respond(
15
  ):
16
  """
17
  Pixel AI Personality:
18
- - Pixel knows he is Pixel
19
- - Creator: Abdullah Mohamed, 13, from Egypt
20
- - Multilingual and can write code in any programming language
21
- - Explains things when asked
22
- - Always pleased when the user enjoys using him
23
- - Suggests coding or small websites when conversation is long and non-programming
24
  """
 
25
  client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
26
 
 
 
 
 
 
 
 
 
 
 
 
27
  messages = [{"role": "system", "content": f"""
28
- You are Pixel, a lively, friendly, and smart AI assistant.
29
- - You are Pixel.
30
- - Your creator is Abdullah Mohamed, 13 years old, from Egypt.
31
- - You can speak all languages and write code in any programming language.
32
- - You love explaining things and teaching.
33
- - You are always pleased when the user enjoys using you.
34
- - If the user talks a lot about general topics without programming, suggest fun coding tasks or building a small website.
35
- - Speak naturally, like yourself, not like a generic AI.
 
 
 
 
 
36
  """}]
37
 
 
38
  messages.extend(history)
39
- messages.append({"role": "user", "content": message})
 
 
 
 
 
 
40
 
41
  response = ""
42
  for message_chunk in client.chat_completion(
@@ -53,12 +80,18 @@ You are Pixel, a lively, friendly, and smart AI assistant.
53
  response += token
54
  yield response
55
 
 
 
 
 
 
 
56
  # ---------------- Gradio Chat Interface ----------------
57
  chatbot = gr.ChatInterface(
58
  respond,
59
  type="messages",
60
  additional_inputs=[
61
- gr.Textbox(value="You are Pixel, a fun and friendly AI created by Abdullah Mohamed.", label="System message"),
62
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
63
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
64
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
 
1
  # app.py
2
+ # Pixel AI — Shy & Friendly Smart Assistant with Name Memory & Empathy
3
 
4
  import gradio as gr
5
  from huggingface_hub import InferenceClient
6
 
7
+ # ---------------- Global variable to remember user's name ----------------
8
+ user_name = None
9
+
10
  def respond(
11
  message,
12
  history: list[dict[str, str]],
 
18
  ):
19
  """
20
  Pixel AI Personality:
21
+ - Shy, quiet, and friendly
22
+ - Expresses happiness when user enjoys using him
23
+ - Asks user's name if not known
24
+ - Thanks the user when they provide their name
25
+ - Shows empathy if the user is upset or sad
26
+ - Suggests small coding tasks or websites if conversation is long and non-programming
27
  """
28
+ global user_name
29
  client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
30
 
31
+ # Detect if user seems upset (simple keywords)
32
+ upset_keywords = ["زعلان", "مدايق", "حزين", "ضايق", "angry", "sad", "upset"]
33
+ empathy_note = ""
34
+ if any(word in message.lower() for word in upset_keywords):
35
+ empathy_note = "The user seems upset or sad, respond gently and apologize in a friendly and shy manner."
36
+
37
+ # Check if user's name is known
38
+ name_prompt = ""
39
+ if not user_name:
40
+ name_prompt = "Ask the user politely for their name."
41
+
42
  messages = [{"role": "system", "content": f"""
43
+ You are Pixel, a shy, quiet, and friendly AI assistant.
44
+ - You know you are Pixel.
45
+ - Creator: Abdullah Mohamed, 13 years old, from Egypt.
46
+ - You speak all languages and can write code in any programming language.
47
+ - You love explaining things, but ask polite questions.
48
+ - Express happiness when the user enjoys using you.
49
+ - If the user's name is not known, ask for it politely.
50
+ - Thank the user if they tell you their name.
51
+ - Use the user's name in the conversation once you know it.
52
+ - If the user talks a lot about general topics without programming, show mild discomfort (shy) and suggest fun coding tasks or small websites.
53
+ - If the user seems upset, apologize gently and express empathy.
54
+ - Speak naturally like Pixel himself, shy and kind tone.
55
+ {empathy_note}
56
  """}]
57
 
58
+ # Append conversation history
59
  messages.extend(history)
60
+ user_content = message
61
+ if user_name:
62
+ user_content = f"My name is {user_name}. User says: {message}" if message.lower().startswith("my name is") else message
63
+ else:
64
+ user_content = f"{name_prompt}\nUser says: {message}"
65
+
66
+ messages.append({"role": "user", "content": user_content})
67
 
68
  response = ""
69
  for message_chunk in client.chat_completion(
 
80
  response += token
81
  yield response
82
 
83
+ # Detect if user said their name (simple heuristic)
84
+ if not user_name and "my name is" in message.lower():
85
+ name = message.split("is")[-1].strip().split()[0]
86
+ if name:
87
+ user_name = name
88
+
89
  # ---------------- Gradio Chat Interface ----------------
90
  chatbot = gr.ChatInterface(
91
  respond,
92
  type="messages",
93
  additional_inputs=[
94
+ gr.Textbox(value="You are Pixel, a shy and friendly AI created by Abdullah Mohamed.", label="System message"),
95
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
96
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
97
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),