AegionX commited on
Commit
5c2d250
Β·
verified Β·
1 Parent(s): ea697ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -52
app.py CHANGED
@@ -4,11 +4,11 @@ import os
4
  import json
5
  from huggingface_hub import InferenceClient
6
 
7
- # 🧠 Load Zephyr model with your Hugging Face token if needed
8
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
 
10
- # 🧠 MEMORY SETUP
11
- MEMORY_FILE = "hoopmind_memory.json"
12
 
13
  def load_memory():
14
  if os.path.exists(MEMORY_FILE):
@@ -22,118 +22,141 @@ def save_memory(memory):
22
 
23
  def update_memory(user_input):
24
  memory = load_memory()
25
- if "my name is" in user_input.lower():
 
 
26
  name = user_input.split("is")[-1].strip().capitalize()
27
  memory["name"] = name
28
- if "i'm injured" in user_input.lower():
 
29
  memory["injury"] = "yes"
30
- if "forget my injury" in user_input.lower():
 
31
  memory.pop("injury", None)
 
32
  save_memory(memory)
33
  return memory
34
 
35
- # πŸ’¬ Zephyr-based fallback with emotion and safe execution
 
36
  def alpha_chatbot_response(user_input):
37
  try:
38
  system_prompt = (
39
  "You are a helpful, smart, and emotionally supportive AI assistant. "
40
  "You respond like a friend, especially when someone is feeling down or frustrated."
41
  )
 
42
  prompt = f"<|system|>\n{system_prompt}\n<|user|>\n{user_input}\n<|assistant|>"
 
43
  response = client.text_generation(
44
  prompt,
45
  max_new_tokens=200,
46
  temperature=0.7,
47
  return_full_text=False
48
  )
49
- return response.strip()
 
 
 
50
  except Exception as e:
51
- return f"πŸ˜“ Lil error happened trying to respond. Debug info: {e}"
 
 
 
 
 
 
52
 
53
- # 🧠 HOOPMIND CHAT FUNCTION
54
- def hoopmind_chat(user_input, history=[]):
55
  user_input_lower = user_input.lower()
56
  memory = update_memory(user_input)
57
 
 
58
  if any(kw in user_input_lower for kw in ["shooting", "dribbling", "defense", "injury", "ankle", "knee", "motivation"]):
59
  if "shooting" in user_input_lower:
60
  return random.choice([
61
- "Aiming to shoot like Steph Curry? πŸ€πŸ”₯ Focus on perfecting that wrist flick and smooth follow-through for consistent results.",
62
- "Ensure your shooting form is clean β€” maintain balance, proper elbow alignment, and follow through every time β›ΉοΈβ€β™‚οΈπŸ“ˆ.",
63
- "Daily catch-and-shoot reps build muscle memory and confidence. Trust your preparation 😀πŸ’ͺ.",
64
- "Visualize the arc, keep your eyes on the rim, and follow through naturally πŸŽ―πŸ‘οΈ.",
65
- "Be patient with progress β€” your shot becomes automatic when you stay disciplined πŸ“ŠπŸ’―."
66
-
67
  ])
 
68
  elif "dribbling" in user_input_lower:
69
  return random.choice([
70
- "Want elite handles? πŸ˜ˆπŸ’¨ Consistent cone drills will drastically improve your control and agility.",
71
- "Two-ball dribbling is excellent for hand coordination and rhythm β€” keep practicing πŸ€πŸ§ .",
72
- "To dribble like Kyrie Irving, maintain a low stance, stay light on your feet, and read your defender closely πŸ”₯πŸ•Ί.",
73
- "Incorporate hesitation moves, crossovers, and spins to diversify your skill set πŸŒ€πŸ’―.",
74
- "Master the fundamentals before adding flair. A strong foundation leads to long-term success πŸ”πŸ‘Ÿ."
75
-
76
  ])
 
77
  elif "defense" in user_input_lower:
78
  return random.choice([
79
- "Stay low, move your feet, and clamp up dawg πŸ›‘οΈ",
80
- "No easy buckets if you got hustle πŸ˜€πŸ’―",
81
- "Mirror drill and shuffle steps will get you right 🧠"
82
  ])
 
83
  elif "injury" in user_input_lower or "ankle" in user_input_lower or "knee" in user_input_lower:
84
  return random.choice([
85
- "Dawg take it easy 🧊 Let that ankle/knee rest up before goin’ beast mode again πŸ’ͺ",
86
- "Stretch, ice, chill β€” and bounce back better πŸ’―",
87
- "You ain’t weak for resting, you smart fr πŸ™ I'm sorry to hear you’re hurt tho πŸ’”"
88
  ])
 
89
  elif "motivation" in user_input_lower:
90
  return random.choice([
91
- "Bro... you got this. Your grind is valid πŸ’― Stay locked in 🧠",
92
- "Mamba mentality dawg πŸπŸ’œ Never stop hoopin’",
93
- "Every legend started where you at right now πŸ”₯"
94
  ])
95
-
 
96
  elif any(kw in user_input_lower for kw in ["football", "quarterback", "receiver", "linebacker", "tackle", "nfl"]):
97
  return random.choice([
98
- "Wanna throw dimes like Mahomes? Work on that footwork and accuracy 🧠πŸ”₯",
99
- "Bro if you play receiver β€” route running and hands gotta be πŸ”›πŸ”",
100
- "Defense wins championships, dawg πŸ’― get those tackling drills tight",
101
- "Linebackers gotta read plays like a book πŸ“– β€” keep that IQ up 🧠",
102
- "Conditioning is key in football too, sprints and agility drills go hard πŸƒβ€β™‚οΈπŸ’¨",
103
  ])
104
 
 
105
  elif any(word in user_input_lower for word in ["hi", "hey", "yo", "sup", "what's up"]):
106
  return random.choice([
107
- "What's up bro? Want to try to get better at basketball or you want to just chill?",
108
- "What's up homie πŸ’¬ you tryna train or chill?",
109
- "I'm hereee πŸ§ πŸ’― What’s the move today?"
110
  ])
111
-
 
112
  elif any(word in user_input_lower for word in ["lol", "fr", "bro", "lmao", "funny"]):
113
  return random.choice([
114
- "LMAOOO you wild dawg πŸ˜‚",
115
  "BROO that’s facts πŸ’€",
116
- "🀣 you goofy fr"
117
  ])
118
-
 
119
  elif any(word in user_input_lower for word in ["idk", "help", "what can you do"]):
120
  return random.choice([
121
- "I’m your hoop buddy πŸ€ but we can talk anything dawg πŸ’―",
122
- "Ask me hoop stuff, motivation, or just vibe like bros 😀",
123
- "I’m your personal trainer + hype man + homie rolled in one 🧠πŸ”₯"
124
  ])
125
-
126
- # Fallback: use Zephyr for everything else (math, life, school, ANYTHING)
127
  return alpha_chatbot_response(user_input)
128
 
129
- # πŸš€ CHAT INTERFACE
 
130
  chat = gr.ChatInterface(
131
  fn=hoopmind_chat,
132
  title="πŸ€ HoopMind – Your Basketball Helper AI",
133
  description="""
134
  ✨ Welcome to **HoopMind** ✨
135
  Your AI hooper brother. Talk hoops, life, school, or just chill!
136
- Drop a question or say what's up πŸ‘‡
137
  """,
138
  theme="soft",
139
  examples=[
@@ -148,3 +171,4 @@ Drop a question or say what's up πŸ‘‡
148
  )
149
 
150
  chat.launch()
 
 
4
  import json
5
  from huggingface_hub import InferenceClient
6
 
7
+ # 🧠 Load Zephyr model
8
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
 
10
+ # 🧠 MEMORY SETUP (HF Spaces Safe)
11
+ MEMORY_FILE = "/home/user/hoopmind_memory.json"
12
 
13
  def load_memory():
14
  if os.path.exists(MEMORY_FILE):
 
22
 
23
  def update_memory(user_input):
24
  memory = load_memory()
25
+ lower = user_input.lower()
26
+
27
+ if "my name is" in lower:
28
  name = user_input.split("is")[-1].strip().capitalize()
29
  memory["name"] = name
30
+
31
+ if "i'm injured" in lower:
32
  memory["injury"] = "yes"
33
+
34
+ if "forget my injury" in lower:
35
  memory.pop("injury", None)
36
+
37
  save_memory(memory)
38
  return memory
39
 
40
+
41
+ # πŸ”₯ FIXED: Zephyr fallback
42
  def alpha_chatbot_response(user_input):
43
  try:
44
  system_prompt = (
45
  "You are a helpful, smart, and emotionally supportive AI assistant. "
46
  "You respond like a friend, especially when someone is feeling down or frustrated."
47
  )
48
+
49
  prompt = f"<|system|>\n{system_prompt}\n<|user|>\n{user_input}\n<|assistant|>"
50
+
51
  response = client.text_generation(
52
  prompt,
53
  max_new_tokens=200,
54
  temperature=0.7,
55
  return_full_text=False
56
  )
57
+
58
+ # πŸ”₯ FIXED: grab generated_text properly
59
+ return response.generated_text.strip()
60
+
61
  except Exception as e:
62
+ return f"πŸ˜“ Lil error trying to respond. Debug info: {e}"
63
+
64
+
65
+ # πŸ”₯ FIXED: history=None (no white-screen crash)
66
+ def hoopmind_chat(user_input, history=None):
67
+ if history is None:
68
+ history = []
69
 
 
 
70
  user_input_lower = user_input.lower()
71
  memory = update_memory(user_input)
72
 
73
+ # πŸ€ Basketball logic
74
  if any(kw in user_input_lower for kw in ["shooting", "dribbling", "defense", "injury", "ankle", "knee", "motivation"]):
75
  if "shooting" in user_input_lower:
76
  return random.choice([
77
+ "Aiming to shoot like Steph Curry? πŸ€πŸ”₯ Focus on that wrist flick and smooth follow-through.",
78
+ "Make sure your elbow stays tucked and eyes locked on the rim, trust your form dawg 🎯.",
79
+ "Daily reps = automatic jumper πŸ˜€πŸ’― stay locked in.",
80
+ "Visualize the arc and let it fly smooth πŸ§ πŸ€.",
81
+ "Patience and consistency make your shot deadly πŸ“ˆ."
 
82
  ])
83
+
84
  elif "dribbling" in user_input_lower:
85
  return random.choice([
86
+ "Low stance, quick feet β€” that’s how you get Kyrie-level handles πŸ˜ˆπŸ’¨.",
87
+ "Two-ball dribbling builds control like crazy πŸ€πŸ§ .",
88
+ "Hesitations + crossovers + spins = unguardable πŸŒ€πŸ”₯.",
89
+ "Master basics first then add the sauce πŸ’―.",
90
+ "Cone drills daily turn you into a problem fr 😀."
 
91
  ])
92
+
93
  elif "defense" in user_input_lower:
94
  return random.choice([
95
+ "Stay low, move your feet, clamp season πŸ›‘οΈπŸ”₯",
96
+ "No easy buckets if you hustle fr πŸ˜€πŸ’―",
97
+ "Slide, mirror, active hands β€” lock in 🧠"
98
  ])
99
+
100
  elif "injury" in user_input_lower or "ankle" in user_input_lower or "knee" in user_input_lower:
101
  return random.choice([
102
+ "Take it easy dawg 🧊 heal up before you go beast mode again πŸ’ͺ",
103
+ "Ice + stretch + chill β€” trust the process πŸ’―",
104
+ "Resting ain't weak bro, it's smart πŸ™"
105
  ])
106
+
107
  elif "motivation" in user_input_lower:
108
  return random.choice([
109
+ "Bro… you got this. Your grind is valid πŸ’―",
110
+ "Mamba mentality dawg 🐍 keep pushing",
111
+ "Every legend started where you are πŸ”₯ keep going"
112
  ])
113
+
114
+ # 🏈 Football logic
115
  elif any(kw in user_input_lower for kw in ["football", "quarterback", "receiver", "linebacker", "tackle", "nfl"]):
116
  return random.choice([
117
+ "Wanna drop dimes like Mahomes? Footwork + timing = elite πŸ’ͺπŸ”₯",
118
+ "Receivers need clean routes + sticky hands πŸ§ πŸ’―",
119
+ "Linebackers read plays like a book fr πŸ“–",
120
+ "Defense wins games dawg, lock in πŸ’―",
121
+ "Agility + sprints make you a menace πŸƒβ€β™‚οΈπŸ’¨"
122
  ])
123
 
124
+ # πŸ‘‹ Greetings
125
  elif any(word in user_input_lower for word in ["hi", "hey", "yo", "sup", "what's up"]):
126
  return random.choice([
127
+ "What’s good bro? Tryna hoop or chill?",
128
+ "Wassup homie πŸ’¬ what we cookin today?",
129
+ "I’m here dawg 🧠πŸ”₯ what’s the move?"
130
  ])
131
+
132
+ # πŸ˜‚ Reactions
133
  elif any(word in user_input_lower for word in ["lol", "fr", "bro", "lmao", "funny"]):
134
  return random.choice([
135
+ "LMAOO you goofy dawg πŸ˜‚",
136
  "BROO that’s facts πŸ’€",
137
+ "🀣 you wild fr"
138
  ])
139
+
140
+ # πŸ†˜ Help or confusion
141
  elif any(word in user_input_lower for word in ["idk", "help", "what can you do"]):
142
  return random.choice([
143
+ "I’m your hoop buddy + hype man dawg πŸ€πŸ”₯",
144
+ "Ask anything β€” hoop, life, school, whatever πŸ’―",
145
+ "I’m your trainer + motivator + homie in one 🧠πŸ’ͺ"
146
  ])
147
+
148
+ # 🧠 Fallback to Zephyr
149
  return alpha_chatbot_response(user_input)
150
 
151
+
152
+ # πŸš€ Fixed chat UI
153
  chat = gr.ChatInterface(
154
  fn=hoopmind_chat,
155
  title="πŸ€ HoopMind – Your Basketball Helper AI",
156
  description="""
157
  ✨ Welcome to **HoopMind** ✨
158
  Your AI hooper brother. Talk hoops, life, school, or just chill!
159
+ Drop a question below πŸ‘‡
160
  """,
161
  theme="soft",
162
  examples=[
 
171
  )
172
 
173
  chat.launch()
174
+