File size: 1,384 Bytes
948b490
 
 
0330a7a
 
948b490
0330a7a
948b490
0330a7a
 
 
948b490
 
0330a7a
948b490
 
0330a7a
 
948b490
0330a7a
948b490
 
0330a7a
 
948b490
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
38
39
import gradio as gr
from transformers import pipeline

# βœ… Load FLAN-T5 model for polite, instruction-based replies
generator = pipeline("text2text-generation", model="google/flan-t5-small")

# πŸ“Œ Instruction template
TEMPLATE = (
    "You are a helpful, polite, and professional customer support agent. "
    "Reply to this customer message in a brand-consistent tone:\n\n"
    "{input}"
)

# πŸ” Reply Generator
def generate_reply(user_input):
    prompt = TEMPLATE.format(input=user_input)
    response = generator(prompt, max_length=150, 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="Auto-Generated Support Reply"),
    title="πŸ€– Auto-Reply Generator for Customer Support",
    description=(
        "Generate fast, polite, and professional replies to customer queries using Google's FLAN-T5 model. "
        "Perfect for CRM bots, helpdesk automation, and ticket response."
    ),
    examples=[
        ["I still haven't received my order and it's been 10 days."],
        ["My refund hasn't been processed yet."],
        ["Your app keeps crashing on my iPhone."],
        ["Great service, just wanted to say thanks!"]
    ]
)

iface.launch()