Sanjayraju30's picture
Update app.py
985bcdd verified
raw
history blame
1.38 kB
import gradio as gr
from transformers import pipeline
# βœ… Use Google's FLAN-T5 small (fast + publicly available)
generator = pipeline("text2text-generation", model="google/flan-t5-small")
# 🧠 Refined Prompt Template for Polite, Humble Tone
TEMPLATE = (
"You are a courteous, humble, and professional customer support agent. "
"Please write a polite and helpful response to this customer message:\n\n"
"{input}\n\nResponse:"
)
# πŸ” Generate Reply Function
def generate_reply(user_input):
prompt = TEMPLATE.format(input=user_input)
response = generator(prompt, max_length=100, do_sample=False)[0]["generated_text"]
return response.strip()
# πŸŽ›οΈ Gradio Interface
iface = gr.Interface(
fn=generate_reply,
inputs=gr.Textbox(lines=6, label="Customer Message", placeholder="Enter complaint or question..."),
outputs=gr.Textbox(label="Polite Support Reply"),
title="πŸ’¬ Polite Auto-Reply Generator for Customer Support",
description="Generate humble, polite, and brand-consistent replies using FLAN-T5. Ideal for CRM and helpdesk automation.",
examples=[
["I still haven't received my order and it's been 10 days."],
["Why was I charged twice for my subscription?"],
["Thanks for the quick response yesterday!"],
["My login isn't working since the update."]
]
)
iface.launch()