import torch from transformers import AutoTokenizer, AutoModelForSeq2SeqLM import gradio as gr # Load model from Hugging Face Hub model_name = "Sarthak279/chatbot" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForSeq2SeqLM.from_pretrained(model_name) # Set device device = torch.device("cuda" if torch.cuda.is_available() else "cpu") model.to(device) model.eval() def clean_text(text): return text.strip() def chatbot(query): query = clean_text(query) input_ids = tokenizer(query, return_tensors="pt", max_length=250, truncation=True).to(device) with torch.no_grad(): outputs = model.generate( input_ids["input_ids"], max_length=250, num_beams=5, early_stopping=True ) return tokenizer.decode(outputs[0], skip_special_tokens=True) # Gradio app with visible title + toggle button with gr.Blocks(css=""" .chat-btn { position: fixed; bottom: 30px; right: 30px; background: #0d6efd; color: white; border: none; border-radius: 50%; width: 60px; height: 60px; font-size: 28px; box-shadow: 0 4px 10px rgba(0,0,0,0.3); cursor: pointer; z-index: 999; } .title-text { font-size: 1.8em; font-weight: bold; text-align: center; margin-top: 2rem; color: #0d6efd; } """) as demo: is_open = gr.State(False) gr.HTML('