import gradio as gr from transformers import GPT2LMHeadModel, GPT2Tokenizer, pipeline # Load model and tokenizer from Hugging Face model_name = "taiy0/Rae" model = GPT2LMHeadModel.from_pretrained(model_name) tokenizer = GPT2Tokenizer.from_pretrained(model_name) # Create chatbot pipeline chatbot = pipeline("text-generation", model=model, tokenizer=tokenizer, truncation=True) # Function to generate chatbot responses def generate_response(user_input): prompt = f"<|user|> {user_input}\n<|bot|>" response = chatbot( prompt, max_length=100, do_sample=True, top_p=0.85, truncation=True )[0]["generated_text"] # Extract only the chatbot's response return response.split("<|bot|>")[-1].strip() # Create Gradio UI iface = gr.Interface( fn=generate_response, inputs=gr.Textbox(lines=2, placeholder="Type a message..."), outputs="text", title="chatbot-api", description="A chatbot fine-tuned by Aditya Naidu (Taiyo).", ) # Launch the chatbot iface.launch(share=True)