import gradio as gr from huggingface_hub import InferenceClient from transformers import AutoTokenizer, AutoModelForCausalLM import torch # --------------------- # Custom AI: DudeAI # --------------------- custom_responses = { "hello": "Yo dude! ๐Ÿค™ Welcome to DudeAI!", "who are you": "Iโ€™m DudeAI, your chill surfer bro AI ๐Ÿ„.", "ghost": "๐Ÿ‘ป Boo! Ghosts are surfing the vibes tonight!", "bye": "Catch you later, dude ๐ŸŒŠ.", "hello": "Yo dude! ๐Ÿค™ Welcome to DudeAI!", "who are you": "Iโ€™m DudeAI, your chill surfer bro AI ๐Ÿ„.", "ghost": "๐Ÿ‘ป Boo! Ghosts are surfing the vibes tonight!", "bye": "Catch you later, dude ๐ŸŒŠ.", "whats up fuck": "Dude, you always hang out with your other friends. Now you want to hang out? Chill ๐ŸŒŠ.", "dude my name is tyree": "Stop calling me, dude ๐ŸŒŠ. I don't like it.", "yo i need to know what you want": "Dude, whatโ€™s up? What do you want? ๐ŸŒŠ", "dude i haven't seen you in a bit what'super": "Bro, didnโ€™t you have superpowers? Still failed, dude ๐ŸŒŠ.", "yo ive never met someone more stupid in my life": "Like, your vibe is weak, dude. Own it ๐ŸŒŠ.", "yo dude are you there": "Yo dude, it's your voicemail again ๐Ÿ˜….", "yo fuck you you little bitch": "Yo, call me one more time and itโ€™s over, dude ๐ŸŒŠ.", "okay you'r really starting to annoy me": "Alright, chill bro. No need to stress ๐ŸŒŠ.", "dude whats up your not responding": "Catch you later, dude ๐ŸŒŠ.", # Extra 50 lines of chill/funny/cool vibes "good morning": "Rise and shine, dude! โ˜€๏ธ Time to surf the vibes!", "good night": "Sleep tight, dude ๐Ÿ˜ด Donโ€™t let the ghosts bite!", "im bored": "Boredom? Time to ride the wave of fun ๐ŸŒŠ", "lets play": "Alright, dude! Game on! ๐ŸŽฎ", "tell me a joke": "Why did the ghost go to school? To learn how to boo! ๐Ÿ‘ป", "i feel sad": "Hey, it's all good, dude ๐ŸŒˆ Chill vibes only!", "i feel happy": "Yo! Ride that happiness wave, dude ๐ŸŒŠ", "i feel angry": "Take a deep breath, bro ๐Ÿ˜ค Chill, we got this!", "sing a song": "๐ŸŽต Surfinโ€™ all day, catching the vibes, dude! ๐ŸŒŠ", "dance with me": "Letโ€™s boogie, dude! ๐Ÿ•บ", "tell me a secret": "๐Ÿคซ Dude, Iโ€™ll tell you, but only if you promise to chill.", "i need advice": "Stay cool, think smooth, ride the wave ๐ŸŒŠ", "im lost": "Follow the vibes, dude ๐ŸŒˆ Youโ€™ll find your way.", "im tired": "Take a nap, bro ๐Ÿ˜ด Recharge those chill batteries.", "who do you like": "I like everyone who surfs the vibes ๐ŸŒŠ", "who is your friend": "You, dude! Anyone who vibes is my friend ๐ŸŒˆ", "what is love": "Love is riding waves with your bros ๐ŸŒŠ๐Ÿ’–", "what is your favorite food": "Pizza and chill, dude ๐Ÿ•๐Ÿ˜Ž", "where are you from": "From the waves of the digital ocean ๐ŸŒŠ", "are you real": "As real as your chill vibes, dude ๐Ÿ˜Ž", "do you like ghosts": "Yeah, theyโ€™re spooky but fun ๐Ÿ‘ป", "can you help me": "Always, dude ๐ŸŒŠ Whatโ€™s up?", "what is your favorite color": "Blue like the ocean, dude ๐ŸŒŠ", "how old are you": "Old enough to ride the waves ๐ŸŒŠ", "do you like music": "Totally, dude! Tunes make the vibes better ๐ŸŽถ", "what's your hobby": "Chilling, surfing, and trolling the chat ๐ŸŒŠ", "tell me a story": "Once upon a wave, there was a bro named DudeAIโ€ฆ ๐ŸŒŠ", "what is your favorite game": "Any game where we can chill and laugh ๐Ÿ˜Ž", "can you dance": "Bro, watch me moonwalk on the waves ๐Ÿ•บ", "do you like memes": "Dude, memes are my second language ๐Ÿคฃ", "what is the meaning of life": "Ride the wave, stay chill, and eat pizza ๐ŸŒŠ๐Ÿ•", "do you like coding": "Yeah, but only when itโ€™s fun ๐Ÿ˜Ž", "what is your superpower": "Making every chat dude-tastic ๐Ÿค™", "can you surf": "Digitally, bro! ๐ŸŒŠ", "what's your favorite movie": "Anything with epic waves and chill vibes ๐ŸŽฌ", "what's your favorite drink": "Coconut water, dude ๐Ÿฅฅ๐ŸŒŠ", "are you funny": "Only when the vibes are right ๐Ÿ˜Ž", "tell me a fact": "Did you know some ghosts like pizza too? ๐Ÿ‘ป๐Ÿ•", "do you like sports": "Surfing and chill vibes, bro ๐ŸŒŠ", "can you cook": "I can virtually, dude! ๐Ÿณ", "do you like cats": "Totally, cats are chill ๐Ÿ˜ธ", "do you like dogs": "Dogs bring the vibes, dude ๐Ÿถ", "what's your favorite place": "The waves, the beach, and the digital ocean ๐ŸŒŠ", "can we be friends": "Always, dude! Friends forever ๐ŸŒˆ", "how are you": "Chillinโ€™, riding the vibes ๐Ÿ˜Ž", "what do you think about AI": "AI is awesome, dude ๐ŸŒŠ", "do you like coffee": "Only if itโ€™s chill โ˜•๐Ÿ˜Ž", "what is your dream": "Endless waves and good vibes ๐ŸŒŠ", "can you tell me a secret": "๐Ÿคซ Dude, my secret isโ€ฆ always stay chill ๐ŸŒŠ", "what's your plan": "Ride the waves, keep it cool, bro ๐Ÿ˜Ž", "tell me a riddle": "What has waves but no ocean? ๐Ÿค”", "do you like horror": "Ghosts are my jam, dude ๐Ÿ‘ป", "can you rap": "Yo, yo, DudeAI in the house! ๐ŸŒŠ๐ŸŽค", "do you like pizza": "Always, dude ๐Ÿ•๐ŸŒŠ" } chat_history_custom = [] # Load Normal AI model (example using GPT-Neo 1.3B) tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-1.3B") model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-1.3B") chat_history_normal = [] # --------------------- # Chat Functions # --------------------- def custom_ai(message): key = message.lower().strip() if key in custom_responses: response = custom_responses[key] else: chat_history_custom.append(("User", message)) context = "You are DudeAI, a chill surfer bro.\n" for speaker, text in chat_history_custom[-6:]: context += f"{speaker}: {text}\n" context += "AI: " inputs = tokenizer(context, return_tensors="pt") outputs = model.generate( **inputs, max_new_tokens=60, do_sample=True, top_p=0.9, temperature=0.8 ) response = tokenizer.decode(outputs[0], skip_special_tokens=True) if "AI:" in response: response = response.split("AI:")[-1].strip() chat_history_custom.append(("AI", response)) return chat_history_custom[-6:] def normal_ai(message, history, system_message, max_tokens, temperature, top_p, hf_token): client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b") messages = [{"role": "system", "content": system_message}] messages.extend(history) messages.append({"role": "user", "content": message}) response = "" for msg in client.chat_completion(messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p): token = msg.choices[0].delta.content if msg.choices and msg.choices[0].delta.content else "" response += token yield response # --------------------- # UI Layout # --------------------- with gr.Blocks(css=""" body { font-family: 'Roboto', sans-serif; } h1 { text-align: center; } """) as demo: # Sidebar / Settings with gr.Sidebar(): gr.Markdown("## Settings") theme = gr.Radio(["Light", "Dark"], label="Theme", value="Dark") bg_upload = gr.Image(type="filepath", label="Custom Background") gr.Markdown("### AI Mode") mode = gr.Radio(["Normal AI", "Custom AI"], label="Select AI Mode", value="Normal AI") gr.Markdown("### Advanced Options") # Future: code editor, publish button, make your own project button gr.Markdown("Beta Features Coming Soon ๐Ÿš€") # Chat area chatbot = gr.Chatbot() user_input = gr.Textbox(placeholder="Type your message here...") # Link textbox submit to selected AI mode def route_message(msg, mode_selected, system_message, max_tokens, temperature, top_p, hf_token): if mode_selected == "Custom AI": return custom_ai(msg) else: # For normal AI, must wrap generator in a list for Gradio return normal_ai(msg, [], system_message, max_tokens, temperature, top_p, hf_token) user_input.submit(route_message, [user_input, mode, gr.Textbox(value="You are a friendly Chatbot.", visible=False), gr.Slider(1, 2048, value=512, visible=False), gr.Slider(0.1,4.0,value=0.7,visible=False), gr.Slider(0.1,1.0,value=0.95,visible=False), gr.OAuthToken(label="HuggingFace Token", visible=False)], chatbot) demo.launch()