Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,38 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load
|
5 |
-
generator = pipeline("
|
6 |
|
7 |
-
#
|
8 |
TEMPLATE = (
|
9 |
-
"You are a helpful and professional customer support agent. "
|
10 |
-
"
|
11 |
-
"
|
12 |
)
|
13 |
|
|
|
14 |
def generate_reply(user_input):
|
15 |
prompt = TEMPLATE.format(input=user_input)
|
16 |
-
response = generator(prompt, max_length=
|
17 |
-
|
18 |
-
# Extract only the agent's reply
|
19 |
-
support_response = response.split("Support:")[-1].strip()
|
20 |
-
return support_response
|
21 |
|
|
|
22 |
iface = gr.Interface(
|
23 |
fn=generate_reply,
|
24 |
-
inputs=gr.Textbox(lines=6, placeholder="Enter
|
25 |
-
outputs=gr.Textbox(label="Auto-Generated Reply"),
|
26 |
title="π€ Auto-Reply Generator for Customer Support",
|
27 |
-
description=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
)
|
29 |
|
30 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# β
Load FLAN-T5 model for polite, instruction-based replies
|
5 |
+
generator = pipeline("text2text-generation", model="google/flan-t5-small")
|
6 |
|
7 |
+
# π Instruction template
|
8 |
TEMPLATE = (
|
9 |
+
"You are a helpful, polite, and professional customer support agent. "
|
10 |
+
"Reply to this customer message in a brand-consistent tone:\n\n"
|
11 |
+
"{input}"
|
12 |
)
|
13 |
|
14 |
+
# π Reply Generator
|
15 |
def generate_reply(user_input):
|
16 |
prompt = TEMPLATE.format(input=user_input)
|
17 |
+
response = generator(prompt, max_length=150, do_sample=False)[0]["generated_text"]
|
18 |
+
return response.strip()
|
|
|
|
|
|
|
19 |
|
20 |
+
# ποΈ Gradio Interface
|
21 |
iface = gr.Interface(
|
22 |
fn=generate_reply,
|
23 |
+
inputs=gr.Textbox(lines=6, label="Customer Message", placeholder="Enter complaint or question..."),
|
24 |
+
outputs=gr.Textbox(label="Auto-Generated Support Reply"),
|
25 |
title="π€ Auto-Reply Generator for Customer Support",
|
26 |
+
description=(
|
27 |
+
"Generate fast, polite, and professional replies to customer queries using Google's FLAN-T5 model. "
|
28 |
+
"Perfect for CRM bots, helpdesk automation, and ticket response."
|
29 |
+
),
|
30 |
+
examples=[
|
31 |
+
["I still haven't received my order and it's been 10 days."],
|
32 |
+
["My refund hasn't been processed yet."],
|
33 |
+
["Your app keeps crashing on my iPhone."],
|
34 |
+
["Great service, just wanted to say thanks!"]
|
35 |
+
]
|
36 |
)
|
37 |
|
38 |
iface.launch()
|