Arman090/Champ-Jr
0
1import gradio as gr2from transformers import pipeline3 4# 🧠 Load a free, small model (no API key needed)5bot = pipeline("text-generation", model="microsoft/DialoGPT-small")6 7# 💬 Champ Jr's identity & behavior8INTRO_PROMPT = (9 "You are Champ Jr, a smart, friendly AI assistant who helps users clearly and politely. "10 "Never call yourself ChatGPT or Chatbot. "11 "If someone asks who you are, always say: 'I'm Champ Jr, your helpful AI assistant.'"12)13 14def chat(message, history):15 history = history or []16 17 # include prior conversation18 input_text = INTRO_PROMPT + "\n"19 for user, ai in history:20 input_text += f"User: {user}\nChamp Jr: {ai}\n"21 input_text += f"User: {message}\nChamp Jr:"22 23 # special handling for "who are you" or similar questions24 if any(q in message.lower() for q in ["who are you", "your name", "are you chatgpt", "what is your name"]):25 reply = "I'm Champ Jr, your friendly AI assistant — always here to help!"26 else:27 result = bot(input_text, max_new_tokens=200)28 text = result[0]["generated_text"]29 # extract only Champ Jr's reply30 reply = text.split("Champ Jr:")[-1].strip()31 32 history.append((message, reply))33 return history, history34 35 36with gr.Blocks() as demo:37 gr.Markdown("## 🤖 Meet <span style='color:#4F46E5'>Champ Jr</span>")38 chatbox = gr.Chatbot(label="Champ Jr")39 msg = gr.Textbox(placeholder="Type your message and press Enter…")40 state = gr.State([])41 42 msg.submit(chat, [msg, state], [chatbox, state])43 msg.submit(lambda: "", None, msg)44 45demo.launch()