CoolFace
Apppublic

Arman090/Champ-Jr

sourceHugging Faceotherupdated 11mo agoView on Hugging Face
0likes
app.py46 linesDownload Raw Back to root
1import gradio as gr2from transformers import pipeline3 4# 🧠 Use a better small model that doesn't mention ChatGPT5bot = pipeline("text-generation", model="google/gemma-2b-it")  # free & light6 7# 💬 Champ Jr identity8INTRO_PROMPT = (9    "You are Champ Jr, a smart, friendly AI assistant. "10    "Always introduce yourself as Champ Jr — never say ChatGPT, Chatbot, or Assistant. "11    "Answer clearly, helpfully, and politely."12)13 14def chat(message, history):15    history = history or []16    input_text = INTRO_PROMPT + "\n"17    for user, ai in history:18        input_text += f"User: {user}\nChamp Jr: {ai}\n"19    input_text += f"User: {message}\nChamp Jr:"20 21    # 🧩 Handle identity questions manually22    if any(q in message.lower() for q in ["who are you", "your name", "are you chatgpt", "what is your name"]):23        reply = "I'm Champ Jr, your friendly AI assistant — always here to help!"24    else:25        result = bot(input_text, max_new_tokens=200, do_sample=True, temperature=0.7)26        text = result[0]["generated_text"]27        reply = text.split("Champ Jr:")[-1].strip()28 29        # 🔧 Clean unwanted mentions30        for bad in ["ChatGPT", "chatbot", "Chatbot", "assistant", "Assistant"]:31            reply = reply.replace(bad, "Champ Jr")32 33    history.append((message, reply))34    return history, history35 36 37with gr.Blocks() as demo:38    gr.Markdown("## 🤖 Meet <span style='color:#4F46E5'>Champ Jr</span>")39    chatbox = gr.Chatbot(label="Champ Jr")40    msg = gr.Textbox(placeholder="Type your message and press Enter…")41    state = gr.State([])42 43    msg.submit(chat, [msg, state], [chatbox, state])44    msg.submit(lambda: "", None, msg)45 46demo.launch()