File size: 1,079 Bytes
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
import gradio as gr
from transformers import pipeline

# Load conversational model
generator = pipeline("text-generation", model="microsoft/DialoGPT-medium")

# Template for polite brand-consistent tone
TEMPLATE = (
    "You are a helpful and professional customer support agent. "
    "Respond politely and concisely to the following customer complaint or question:\n\n"
    "Customer: {input}\nSupport:"
)

def generate_reply(user_input):
    prompt = TEMPLATE.format(input=user_input)
    response = generator(prompt, max_length=100, do_sample=True, top_k=50, top_p=0.95)[0]['generated_text']
    
    # Extract only the agent's reply
    support_response = response.split("Support:")[-1].strip()
    return support_response

iface = gr.Interface(
    fn=generate_reply,
    inputs=gr.Textbox(lines=6, placeholder="Enter customer message here..."),
    outputs=gr.Textbox(label="Auto-Generated Reply"),
    title="🤖 Auto-Reply Generator for Customer Support",
    description="Generate polite and brand-consistent replies to customer questions using AI."
)

iface.launch()