|
|
import gradio as gr |
|
|
import random |
|
|
import os |
|
|
import json |
|
|
from huggingface_hub import InferenceClient |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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}" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def hoopmind_chat(user_input, history=None): |
|
|
if history is None: |
|
|
history = [] |
|
|
|
|
|
user_input_lower = user_input.lower() |
|
|
memory = update_memory(user_input) |
|
|
|
|
|
|
|
|
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." |
|
|
]) |
|
|
|
|
|
|
|
|
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 πββοΈπ¨" |
|
|
]) |
|
|
|
|
|
|
|
|
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." |
|
|
]) |
|
|
|
|
|
|
|
|
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" |
|
|
]) |
|
|
|
|
|
|
|
|
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 π§ πͺ" |
|
|
]) |
|
|
|
|
|
|
|
|
return alpha_chatbot_response(user_input) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
|