Spaces:
Sleeping
Sleeping
File size: 1,375 Bytes
948b490 985bcdd 7096535 948b490 985bcdd 948b490 985bcdd 948b490 985bcdd 948b490 985bcdd 0330a7a 948b490 985bcdd 948b490 0330a7a 985bcdd 0330a7a 1b73e6b 0330a7a 948b490 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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()
|