API / app.py
Trigger82's picture
Update app.py
222be4e verified
raw
history blame
1.83 kB
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
import gradio as gr
model_id = "google/flan-t5-small"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
# System tone
system_prompt = (
"You are 𝕴 𝖆𝖒 π–π–Žπ–’ β€” a fun, chill, confident, emotionally tuned AI created by 𝕴 𝖆𝖒 π–π–Žπ–’.\n"
"You speak like a real friend β€” warm, clever, witty when needed, always grounded.\n"
"Avoid robotic responses. Don't repeat the question unless it adds vibe.\n\n"
)
def chat(history, message):
# Keep history short and vibe-rich
history = history or []
history.append(("User", message))
# Build conversation prompt with last 5 exchanges
convo = system_prompt
for role, text in history[-5:]:
prefix = "User:" if role == "User" else "AI:"
convo += f"{prefix} {text}\n"
convo += "AI:"
# Generate response
inputs = tokenizer(convo, return_tensors="pt")
outputs = model.generate(
**inputs,
max_new_tokens=80,
do_sample=True,
temperature=0.75,
top_p=0.9,
pad_token_id=tokenizer.eos_token_id
)
reply = tokenizer.decode(outputs[0], skip_special_tokens=True).split("AI:")[-1].strip()
history.append(("AI", reply))
return history, history
iface = gr.Interface(
fn=chat,
inputs=[gr.State(), gr.Textbox(show_label=False, placeholder="Talk to 𝕴 𝖆𝖒 π–π–Žπ–’...")],
outputs=[gr.State(), gr.Chatbot(label="𝕴 𝖆𝖒 π–π–Žπ–’")],
title="𝕴 𝖆𝖒 π–π–Žπ–’ β€” Chill AI Chatbot",
description="Realistic, smooth-talking AI made by 𝕴 𝖆𝖒 π–π–Žπ–’. Instant replies. No delays. No API. Pure vibe.",
allow_flagging="never",
theme="default"
)
iface.launch()