AegionX commited on
Commit
09f387d
Β·
verified Β·
1 Parent(s): bf860e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -51
app.py CHANGED
@@ -4,12 +4,19 @@ import os
4
  import json
5
  from huggingface_hub import InferenceClient
6
 
7
- #
8
  # 🧠 MEMORY SETUP (HF Spaces Safe)
 
 
9
  MEMORY_FILE = "/home/user/hoopmind_memory.json"
10
 
11
  def load_memory():
12
- if o
 
 
 
 
 
13
  return {}
14
 
15
  def save_memory(memory):
@@ -19,20 +26,36 @@ def save_memory(memory):
19
  def update_memory(user_input):
20
  memory = load_memory()
21
  lower = user_input.lower()
22
- ower:
23
- name = user_input.split("is")[-1].strip().capitalize()
24
- memory["name"] = name
25
 
26
- if "i'm injured" in lower:
 
 
 
 
 
 
 
 
 
 
27
  memory["injury"] = "yes"
28
- n lower:
 
29
  memory.pop("injury", None)
30
 
31
  save_memory(memory)
32
  return memory
33
 
 
 
 
 
 
34
 
35
- #onally supportive AI assistant. "
 
 
 
36
  "You respond like a friend, especially when someone is feeling down or frustrated."
37
  )
38
 
@@ -45,14 +68,16 @@ n lower:
45
  return_full_text=False
46
  )
47
 
48
- # πŸ”₯ FIXED: grab generated_text properly
49
  return response.generated_text.strip()
50
 
51
  except Exception as e:
52
  return f"πŸ˜“ Lil error trying to respond. Debug info: {e}"
53
 
54
 
55
- # πŸ”₯ FIXED: history=None (no white-screen crash)
 
 
 
56
  def hoopmind_chat(user_input, history=None):
57
  if history is None:
58
  history = []
@@ -60,92 +85,95 @@ def hoopmind_chat(user_input, history=None):
60
  user_input_lower = user_input.lower()
61
  memory = update_memory(user_input)
62
 
63
- # πŸ€ Basketball logic
64
  if any(kw in user_input_lower for kw in ["shooting", "dribbling", "defense", "injury", "ankle", "knee", "motivation"]):
65
  if "shooting" in user_input_lower:
66
  return random.choice([
67
- "Aiming to shoot like Steph Curry? πŸ€πŸ”₯ Focus on that wrist flick and smooth follow-through.",
68
- "Make sure your elbow stays tucked and eyes locked on the rim, trust your form and keep good hand placement for better accuracy 🎯.",
69
- "Daily reps = automatic jumper πŸ˜€πŸ’― stay locked in.",
70
- "Visualize the arc and let it fly smooth πŸ§ πŸ€.",
71
- "Patience and consistency make your shot deadly πŸ“ˆ."
72
  ])
73
 
74
  elif "dribbling" in user_input_lower:
75
  return random.choice([
76
- "Low stance, quick feet β€” that’s how you get Kyrie-level handles πŸ˜ˆπŸ’¨.",
77
- "Two-ball dribbling builds control like crazy πŸ€πŸ§ .",
78
- "Hesitations + crossovers + spins = unguardable πŸŒ€πŸ”₯.",
79
- "Master basics first then add the sauce πŸ’―.",
80
- "Cone drills daily turn you into a problem fr 😀."
81
  ])
82
 
83
  elif "defense" in user_input_lower:
84
  return random.choice([
85
- "Stay low, move your feet, clamp season πŸ›‘οΈπŸ”₯",
86
  "No easy buckets if you hustle fr πŸ˜€πŸ’―",
87
- "Slide, mirror, active hands β€” lock in 🧠"
88
  ])
89
 
90
- elif "injury" in user_input_lower or "ankle" in user_input_lower or "knee" in user_input_lower:
91
  return random.choice([
92
- "Take it easy dawg 🧊 heal up before you go beast mode again πŸ’ͺ",
93
- "Ice + stretch + chill β€” trust the process πŸ’―",
94
- "Resting ain't weak bro, it's smart πŸ™"
95
  ])
96
 
97
  elif "motivation" in user_input_lower:
98
  return random.choice([
99
- "Bro… you got this. Your grind is valid πŸ’―",
100
- "Mamba mentality dawg 🐍 keep pushing",
101
- "Every legend started where you are πŸ”₯ keep going"
102
  ])
103
 
104
- # 🏈 Football logic
105
- elif any(kw in user_input_lower for kw in ["football", "quarterback", "receiver", "linebacker", "tackle", "nfl"]):
106
  return random.choice([
107
- "Wanna drop dimes like Mahomes? Footwork + timing = elite πŸ’ͺπŸ”₯",
108
- "Receivers need clean routes + sticky hands πŸ§ πŸ’―",
109
  "Linebackers read plays like a book fr πŸ“–",
110
- "Defense wins games dawg, lock in πŸ’―",
111
- "Agility + sprints make you a menace πŸƒβ€β™‚οΈπŸ’¨"
112
  ])
113
 
114
- # πŸ‘‹ Greetings
115
- elif any(word in user_input_lower for word in ["hi", "hey", "yo", "sup", "what's up"]):
116
  return random.choice([
117
- "What’s good bro? Tryna hoop or chill?",
118
- "Wassup homie πŸ’¬ what we cookin today?",
119
- "I’m here dawg 🧠πŸ”₯ what’s the move?"
120
  ])
121
 
122
- # πŸ˜‚ Reactions
123
- elif any(word in user_input_lower for word in ["lol", "fr", "bro", "lmao", "funny"]):
124
  return random.choice([
125
  "LMAOO you goofy dawg πŸ˜‚",
126
  "BROO that’s facts πŸ’€",
127
  "🀣 you wild fr"
128
  ])
129
 
130
- # πŸ†˜ Help or confusion
131
- elif any(word in user_input_lower for word in ["idk", "help", "what can you do"]):
132
  return random.choice([
133
- "I’m your hoop buddy + hype man dawg πŸ€πŸ”₯",
134
- "Ask anything β€” hoop, life, school, whatever πŸ’―",
135
- "I’m your trainer + motivator + homie in one 🧠πŸ’ͺ"
136
  ])
137
 
138
- # 🧠 Fallback to Zephyr
139
  return alpha_chatbot_response(user_input)
140
 
141
 
142
- # πŸš€ Fixed chat UI
 
 
 
143
  chat = gr.ChatInterface(
144
  fn=hoopmind_chat,
145
  title="πŸ€ HoopMind – Your Basketball Helper AI",
146
  description="""
147
  ✨ Welcome to **HoopMind** ✨
148
- Your AI hooper brother. Talk hoops, life, school, or just chill!
149
  Drop a question below πŸ‘‡
150
  """,
151
  theme="soft",
@@ -162,3 +190,4 @@ Drop a question below πŸ‘‡
162
 
163
  chat.launch()
164
 
 
 
4
  import json
5
  from huggingface_hub import InferenceClient
6
 
7
+ # ==========================================
8
  # 🧠 MEMORY SETUP (HF Spaces Safe)
9
+ # ==========================================
10
+
11
  MEMORY_FILE = "/home/user/hoopmind_memory.json"
12
 
13
  def load_memory():
14
+ if os.path.exists(MEMORY_FILE):
15
+ try:
16
+ with open(MEMORY_FILE, "r") as f:
17
+ return json.load(f)
18
+ except:
19
+ return {}
20
  return {}
21
 
22
  def save_memory(memory):
 
26
  def update_memory(user_input):
27
  memory = load_memory()
28
  lower = user_input.lower()
 
 
 
29
 
30
+ # name detection
31
+ if "my name is" in lower or "i am" in lower:
32
+ try:
33
+ name = user_input.split("is")[-1].strip().capitalize()
34
+ if len(name) > 0:
35
+ memory["name"] = name
36
+ except:
37
+ pass
38
+
39
+ # injury tracking
40
+ if "i'm injured" in lower or "im injured" in lower:
41
  memory["injury"] = "yes"
42
+
43
+ if "i'm healed" in lower or "im healed" in lower:
44
  memory.pop("injury", None)
45
 
46
  save_memory(memory)
47
  return memory
48
 
49
+ # ==========================================
50
+ # 🧠 ZEPHYR / TEXT GENERATION FALLBACK
51
+ # ==========================================
52
+
53
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
54
 
55
+ def alpha_chatbot_response(user_input):
56
+ try:
57
+ system_prompt = (
58
+ "You are HoopMind, a friendly, motivational, athletic, emotionally supportive AI assistant. "
59
  "You respond like a friend, especially when someone is feeling down or frustrated."
60
  )
61
 
 
68
  return_full_text=False
69
  )
70
 
 
71
  return response.generated_text.strip()
72
 
73
  except Exception as e:
74
  return f"πŸ˜“ Lil error trying to respond. Debug info: {e}"
75
 
76
 
77
+ # ==========================================
78
+ # 🧠 MAIN CHAT LOGIC
79
+ # ==========================================
80
+
81
  def hoopmind_chat(user_input, history=None):
82
  if history is None:
83
  history = []
 
85
  user_input_lower = user_input.lower()
86
  memory = update_memory(user_input)
87
 
88
+ # BASKETBALL LOGIC
89
  if any(kw in user_input_lower for kw in ["shooting", "dribbling", "defense", "injury", "ankle", "knee", "motivation"]):
90
  if "shooting" in user_input_lower:
91
  return random.choice([
92
+ "Shoot like Curry bro πŸ€πŸ”₯ Lock that wrist and follow through.",
93
+ "Tuck your elbow, eyes on the rim β€” smooth release every time 🎯.",
94
+ "Daily reps = automatic jumper πŸ˜€πŸ’―.",
95
+ "Visualize the arc dawg πŸ§ πŸ€.",
96
+ "Slow and controlled forms turn deadly over time πŸ“ˆ."
97
  ])
98
 
99
  elif "dribbling" in user_input_lower:
100
  return random.choice([
101
+ "Stay low, quick feet β€” Kyrie mode activated πŸ˜ˆπŸ’¨.",
102
+ "Two-ball drills build CRAZY control πŸ€πŸ§ .",
103
+ "Mix hesitations + crossovers + spins for max sauce πŸŒ€πŸ”₯.",
104
+ "Master the basics before adding flavor πŸ’―.",
105
+ "Cone drills daily make defenders slip 😀."
106
  ])
107
 
108
  elif "defense" in user_input_lower:
109
  return random.choice([
110
+ "Stay low & move your feet, clamp season πŸ›‘οΈπŸ”₯",
111
  "No easy buckets if you hustle fr πŸ˜€πŸ’―",
112
+ "Mirror their hips and keep active hands 🧠"
113
  ])
114
 
115
+ elif any(kw in user_input_lower for kw in ["injury", "ankle", "knee"]):
116
  return random.choice([
117
+ "Take it easy dawg 🧊 heal up before going beast mode again πŸ’ͺ",
118
+ "Ice + stretch + chill β€” your body will thank you πŸ’―",
119
+ "Rest > reinjury bro πŸ™ be smart."
120
  ])
121
 
122
  elif "motivation" in user_input_lower:
123
  return random.choice([
124
+ "Bro… your grind is REAL. Keep pushing πŸ’―",
125
+ "Mamba mentality dawg 🐍 stay locked in.",
126
+ "Every legend started just like you πŸ”₯ keep going."
127
  ])
128
 
129
+ # FOOTBALL LOGIC
130
+ if any(kw in user_input_lower for kw in ["football", "quarterback", "receiver", "linebacker", "tackle", "nfl"]):
131
  return random.choice([
132
+ "Wanna throw dots like Mahomes? Footwork + timing = elite πŸ’ͺπŸ”₯",
133
+ "Receivers need crisp routes + sticky hands πŸ§ πŸ’―",
134
  "Linebackers read plays like a book fr πŸ“–",
135
+ "Defense wins games dawg, lock IN πŸ’―",
136
+ "Agility + sprints turn you into a menace πŸƒβ€β™‚οΈπŸ’¨"
137
  ])
138
 
139
+ # GREETINGS
140
+ if any(word in user_input_lower for word in ["hi", "hey", "yo", "sup", "what's up"]):
141
  return random.choice([
142
+ "What’s good bro? Hooping or chilling?",
143
+ "Wassup homie πŸ’¬ what we on today?",
144
+ "I'm here dawg 🧠πŸ”₯ let's cook."
145
  ])
146
 
147
+ # REACTIONS
148
+ if any(word in user_input_lower for word in ["lol", "fr", "bro", "lmao", "funny"]):
149
  return random.choice([
150
  "LMAOO you goofy dawg πŸ˜‚",
151
  "BROO that’s facts πŸ’€",
152
  "🀣 you wild fr"
153
  ])
154
 
155
+ # HELP OR CONFUSION
156
+ if any(word in user_input_lower for word in ["idk", "help", "what can you do"]):
157
  return random.choice([
158
+ "I’m your hoop buddy AND hype squad dawg πŸ€πŸ”₯",
159
+ "Ask anything β€” hoop, life, school, whateva πŸ’―",
160
+ "I got you: trainer + motivator + homie in one 🧠πŸ’ͺ"
161
  ])
162
 
163
+ # FALLBACK: ZEPHYR
164
  return alpha_chatbot_response(user_input)
165
 
166
 
167
+ # ==========================================
168
+ # πŸš€ GRADIO UI
169
+ # ==========================================
170
+
171
  chat = gr.ChatInterface(
172
  fn=hoopmind_chat,
173
  title="πŸ€ HoopMind – Your Basketball Helper AI",
174
  description="""
175
  ✨ Welcome to **HoopMind** ✨
176
+ Your AI hooper brother. Talk hoops, life, school, or just vibe!
177
  Drop a question below πŸ‘‡
178
  """,
179
  theme="soft",
 
190
 
191
  chat.launch()
192
 
193
+