File size: 6,450 Bytes
cf90060 a0f2e51 2256987 9d258df 962624f cc1208e 09f387d 5c2d250 09f387d 5c2d250 2256987 09f387d 824ce88 2256987 5c2d250 09f387d 2256987 09f387d 2256987 5c2d250 2256987 09f387d 5c2d250 09f387d 962624f 5c2d250 962624f 5c2d250 962624f 327497b 962624f 327497b 5c2d250 eb6f1a4 5c2d250 09f387d 5c2d250 b46ffab 207c75a eaf0f8f a0f2e51 09f387d ea73b55 eb6f1a4 09f387d eb6f1a4 5c2d250 ea73b55 eb6f1a4 09f387d eb6f1a4 5c2d250 ea73b55 eb6f1a4 09f387d 5c2d250 09f387d eb6f1a4 5c2d250 09f387d eb6f1a4 09f387d eb6f1a4 5c2d250 ea73b55 eb6f1a4 09f387d eb6f1a4 5c2d250 09f387d eb6f1a4 09f387d 5c2d250 09f387d eb6f1a4 6ee6c05 09f387d eb6f1a4 09f387d eb6f1a4 5c2d250 09f387d eb6f1a4 5c2d250 eb6f1a4 5c2d250 eb6f1a4 5c2d250 09f387d eb6f1a4 09f387d eb6f1a4 5c2d250 09f387d eb6f1a4 5c2d250 09f387d a1675b7 a0f2e51 ea697ac 8cd1346 eb6f1a4 09f387d 5c2d250 8cd1346 a0f2e51 9d258df ea697ac 7914ad6 df89f1a 6ee6c05 39748b8 a0f2e51 8cd1346 5c2d250 09f387d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
import gradio as gr
import random
import os
import json
from huggingface_hub import InferenceClient
# ==========================================
# π§ MEMORY SETUP (HF Spaces Safe)
# ==========================================
MEMORY_FILE = "/home/user/hoopmind_memory.json"
def load_memory():
if os.path.exists(MEMORY_FILE):
try:
with open(MEMORY_FILE, "r") as f:
return json.load(f)
except:
return {}
return {}
def save_memory(memory):
with open(MEMORY_FILE, "w") as f:
json.dump(memory, f)
def update_memory(user_input):
memory = load_memory()
lower = user_input.lower()
# name detection
if "my name is" in lower or "i am" in lower:
try:
name = user_input.split("is")[-1].strip().capitalize()
if len(name) > 0:
memory["name"] = name
except:
pass
# injury tracking
if "i'm injured" in lower or "im injured" in lower:
memory["injury"] = "yes"
if "i'm healed" in lower or "im healed" in lower:
memory.pop("injury", None)
save_memory(memory)
return memory
# ==========================================
# π§ ZEPHYR / TEXT GENERATION FALLBACK
# ==========================================
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
def alpha_chatbot_response(user_input):
try:
system_prompt = (
"You are HoopMind, a friendly, motivational, athletic, emotionally supportive AI assistant. "
"You respond like a friend, especially when someone is feeling down or frustrated."
)
prompt = f"<|system|>\n{system_prompt}\n<|user|>\n{user_input}\n<|assistant|>"
response = client.text_generation(
prompt,
max_new_tokens=200,
temperature=0.7,
return_full_text=False
)
return response.generated_text.strip()
except Exception as e:
return f"π Lil error trying to respond. Debug info: {e}"
# ==========================================
# π§ MAIN CHAT LOGIC
# ==========================================
def hoopmind_chat(user_input, history=None):
if history is None:
history = []
user_input_lower = user_input.lower()
memory = update_memory(user_input)
# BASKETBALL LOGIC
if any(kw in user_input_lower for kw in ["shooting", "dribbling", "defense", "injury", "ankle", "knee", "motivation"]):
if "shooting" in user_input_lower:
return random.choice([
"Shoot like Curry bro ππ₯ Lock that wrist and follow through.",
"Tuck your elbow, eyes on the rim β smooth release every time π―.",
"Daily reps = automatic jumper π€π―.",
"Visualize the arc dawg π§ π.",
"Slow and controlled forms turn deadly over time π."
])
elif "dribbling" in user_input_lower:
return random.choice([
"Stay low, quick feet β Kyrie mode activated ππ¨.",
"Two-ball drills build CRAZY control ππ§ .",
"Mix hesitations + crossovers + spins for max sauce ππ₯.",
"Master the basics before adding flavor π―.",
"Cone drills daily make defenders slip π€."
])
elif "defense" in user_input_lower:
return random.choice([
"Stay low & move your feet, clamp season π‘οΈπ₯",
"No easy buckets if you hustle fr π€π―",
"Mirror their hips and keep active hands π§ "
])
elif any(kw in user_input_lower for kw in ["injury", "ankle", "knee"]):
return random.choice([
"Take it easy dawg π§ heal up before going beast mode again πͺ",
"Ice + stretch + chill β your body will thank you π―",
"Rest > reinjury bro π be smart."
])
elif "motivation" in user_input_lower:
return random.choice([
"Broβ¦ your grind is REAL. Keep pushing π―",
"Mamba mentality dawg π stay locked in.",
"Every legend started just like you π₯ keep going."
])
# FOOTBALL LOGIC
if any(kw in user_input_lower for kw in ["football", "quarterback", "receiver", "linebacker", "tackle", "nfl"]):
return random.choice([
"Wanna throw dots like Mahomes? Footwork + timing = elite πͺπ₯",
"Receivers need crisp routes + sticky hands π§ π―",
"Linebackers read plays like a book fr π",
"Defense wins games dawg, lock IN π―",
"Agility + sprints turn you into a menace πββοΈπ¨"
])
# GREETINGS
if any(word in user_input_lower for word in ["hi", "hey", "yo", "sup", "what's up"]):
return random.choice([
"Whatβs good bro? Hooping or chilling?",
"Wassup homie π¬ what we on today?",
"I'm here dawg π§ π₯ let's cook."
])
# REACTIONS
if any(word in user_input_lower for word in ["lol", "fr", "bro", "lmao", "funny"]):
return random.choice([
"LMAOO you goofy dawg π",
"BROO thatβs facts π",
"π€£ you wild fr"
])
# HELP OR CONFUSION
if any(word in user_input_lower for word in ["idk", "help", "what can you do"]):
return random.choice([
"Iβm your hoop buddy AND hype squad dawg ππ₯",
"Ask anything β hoop, life, school, whateva π―",
"I got you: trainer + motivator + homie in one π§ πͺ"
])
# FALLBACK: ZEPHYR
return alpha_chatbot_response(user_input)
# ==========================================
# π GRADIO UI
# ==========================================
chat = gr.ChatInterface(
fn=hoopmind_chat,
title="π HoopMind β Your Basketball Helper AI",
description="""
β¨ Welcome to **HoopMind** β¨
Your AI hooper brother. Talk hoops, life, school, or just vibe!
Drop a question below π
""",
theme="soft",
examples=[
"How do I get better at shooting?",
"Hey I'm injured right now",
"What's up bro?",
"Give me motivation",
"Dribbling tips?",
"Math help please?",
"What's the capital of France?"
]
)
chat.launch()
|