Sanjayraju30 commited on
Commit
948b490
·
verified ·
1 Parent(s): fff8ec9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load conversational model
5
+ generator = pipeline("text-generation", model="microsoft/DialoGPT-medium")
6
+
7
+ # Template for polite brand-consistent tone
8
+ TEMPLATE = (
9
+ "You are a helpful and professional customer support agent. "
10
+ "Respond politely and concisely to the following customer complaint or question:\n\n"
11
+ "Customer: {input}\nSupport:"
12
+ )
13
+
14
+ def generate_reply(user_input):
15
+ prompt = TEMPLATE.format(input=user_input)
16
+ response = generator(prompt, max_length=100, do_sample=True, top_k=50, top_p=0.95)[0]['generated_text']
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 customer message here..."),
25
+ outputs=gr.Textbox(label="Auto-Generated Reply"),
26
+ title="🤖 Auto-Reply Generator for Customer Support",
27
+ description="Generate polite and brand-consistent replies to customer questions using AI."
28
+ )
29
+
30
+ iface.launch()