import gradio as gr from transformers import pipeline # Load conversational model generator = pipeline("text-generation", model="microsoft/DialoGPT-medium") # Template for polite brand-consistent tone TEMPLATE = ( "You are a helpful and professional customer support agent. " "Respond politely and concisely to the following customer complaint or question:\n\n" "Customer: {input}\nSupport:" ) def generate_reply(user_input): prompt = TEMPLATE.format(input=user_input) response = generator(prompt, max_length=100, do_sample=True, top_k=50, top_p=0.95)[0]['generated_text'] # Extract only the agent's reply support_response = response.split("Support:")[-1].strip() return support_response iface = gr.Interface( fn=generate_reply, inputs=gr.Textbox(lines=6, placeholder="Enter customer message here..."), outputs=gr.Textbox(label="Auto-Generated Reply"), title="🤖 Auto-Reply Generator for Customer Support", description="Generate polite and brand-consistent replies to customer questions using AI." ) iface.launch()