API / app.py
Trigger82's picture
Update app.py
9660389 verified
raw
history blame
1.28 kB
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import gradio as gr
model_id = "google/flan-t5-small" # Extremely fast and CPU-friendly
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
system_prompt = "You are 𝕴 𝖆𝖒 π–π–Žπ–’ β€” a fun, fast, emotionally tuned AI chatbot created by 𝕴 𝖆𝖒 π–π–Žπ–’. You reply quickly, like a chill and clever human friend."
def chat(history, message):
prompt = f"{system_prompt}\nUser: {message}\nAI:"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=100)
reply = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
history = history or []
history.append((message, reply))
return history, history
iface = gr.Interface(
fn=chat,
inputs=[gr.State(), gr.Textbox(placeholder="Talk to 𝕴 𝖆𝖒 π–π–Žπ–’...")],
outputs=[gr.State(), gr.Chatbot(label="𝕴 𝖆𝖒 π–π–Žπ–’ AI Chatbot")],
title="𝕴 𝖆𝖒 π–π–Žπ–’ β€” Superfast Chatbot",
description="An extremely fast and chill AI chatbot, created by 𝕴 𝖆𝖒 π–π–Žπ–’. Running on Hugging Face Spaces (CPU only).",
allow_flagging="never"
)
iface.launch()