Spaces:
Runtime error

T5-space / app.py
Chuxia-sys's picture
Update app.py
67d0b2f verified
Raw History Blame Contribute Delete
1.19 kB
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import torch
# =========================
# LOAD MODEL
# =========================
MODEL_NAME = "Chuxia-sys/travel-chatbot-flan-t5" # πŸ”Ή Replace with your HF repo ID
print("πŸ”„ Loading model...")
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
print("βœ… Model loaded!\n")
# =========================
# CHAT FUNCTION
# =========================
def chat_with_bot(message, history): # βœ… must accept two arguments
if not message.strip():
return "Please enter a message 😊"
inputs = tokenizer(message, return_tensors="pt")
outputs = model.generate(
**inputs,
max_new_tokens=300,
do_sample=True,
temperature=0.7,
top_p=0.9,
repetition_penalty=1.8,
no_repeat_ngram_size=3,
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Clean up duplicate lines
lines = []
for line in response.split("\n"):
if line.strip() and line not in lines:
lines.append(line)
response = "\n".join(lines)
return response