| import gradio as gr |
| from huggingface_hub import InferenceClient |
| from transformers import AutoTokenizer, AutoModelForCausalLM |
| import torch |
|
|
| |
| |
| |
| 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 🌊.", |
| |
| |
| "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 = [] |
|
|
| |
| tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-1.3B") |
| model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-1.3B") |
| chat_history_normal = [] |
|
|
| |
| |
| |
| 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 |
|
|
| |
| |
| |
| with gr.Blocks(css=""" |
| body { font-family: 'Roboto', sans-serif; } |
| h1 { text-align: center; } |
| """) as demo: |
|
|
| |
| 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") |
| |
| gr.Markdown("Beta Features Coming Soon 🚀") |
|
|
| |
| chatbot = gr.Chatbot() |
| user_input = gr.Textbox(placeholder="Type your message here...") |
| |
| |
| 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: |
| |
| 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() |
|
|