Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ import io
|
|
10 |
import re
|
11 |
import os
|
12 |
|
13 |
-
# Embedded call center FAQs (fixed formatting: escaped quotes, consistent rows
|
14 |
csv_data = """question,answer,call_id,agent_id,timestamp,language
|
15 |
"How do I reset my password?","Go to the login page, click ""Forgot Password,"" and follow the email instructions.",12345,A001,2025-04-01 10:15:23,en
|
16 |
"What are your pricing plans?","We offer Basic ($10/month), Pro ($50/month), and Enterprise (custom).",12346,A002,2025-04-01 10:17:45,en
|
@@ -87,7 +87,7 @@ except Exception as e:
|
|
87 |
# RAG process
|
88 |
def rag_process(query, k=2):
|
89 |
if not query.strip() or len(query) < 5:
|
90 |
-
return "Invalid query. Please
|
91 |
|
92 |
start_time = time.perf_counter()
|
93 |
try:
|
@@ -141,7 +141,7 @@ def plot_metrics(metrics):
|
|
141 |
plt.close()
|
142 |
return 'rag_plot.png'
|
143 |
|
144 |
-
# Gradio interface
|
145 |
def chat_interface(query):
|
146 |
try:
|
147 |
response, retrieved_faqs, metrics = rag_process(query)
|
@@ -165,27 +165,34 @@ def chat_interface(query):
|
|
165 |
custom_css = """
|
166 |
body { background-color: #2a2a2a; color: #e0e0e0; }
|
167 |
.gr-box { background-color: #3a3a3a; border: 1px solid #4a4a4a; }
|
168 |
-
.gr-button { background-color: #1e90ff; color: white; }
|
169 |
.gr-button:hover { background-color: #1c86ee; }
|
170 |
"""
|
171 |
|
|
|
|
|
|
|
172 |
with gr.Blocks(css=custom_css) as demo:
|
173 |
gr.Markdown("# Customer Experience Bot Demo")
|
174 |
-
gr.Markdown("
|
175 |
|
|
|
176 |
with gr.Row():
|
177 |
-
|
178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
|
180 |
response_output = gr.Textbox(label="Bot Response")
|
181 |
faq_output = gr.Textbox(label="Retrieved FAQs")
|
182 |
cleanup_output = gr.Textbox(label="Data Cleanup Stats")
|
183 |
plot_output = gr.Image(label="RAG Pipeline Metrics")
|
184 |
-
|
185 |
-
submit_btn.click(
|
186 |
-
fn=chat_interface,
|
187 |
-
inputs=query_input,
|
188 |
-
outputs=[response_output, faq_output, cleanup_output, plot_output]
|
189 |
-
)
|
190 |
|
191 |
demo.launch()
|
|
|
10 |
import re
|
11 |
import os
|
12 |
|
13 |
+
# Embedded call center FAQs (fixed formatting: escaped quotes, consistent rows)
|
14 |
csv_data = """question,answer,call_id,agent_id,timestamp,language
|
15 |
"How do I reset my password?","Go to the login page, click ""Forgot Password,"" and follow the email instructions.",12345,A001,2025-04-01 10:15:23,en
|
16 |
"What are your pricing plans?","We offer Basic ($10/month), Pro ($50/month), and Enterprise (custom).",12346,A002,2025-04-01 10:17:45,en
|
|
|
87 |
# RAG process
|
88 |
def rag_process(query, k=2):
|
89 |
if not query.strip() or len(query) < 5:
|
90 |
+
return "Invalid query. Please select a question.", [], {}
|
91 |
|
92 |
start_time = time.perf_counter()
|
93 |
try:
|
|
|
141 |
plt.close()
|
142 |
return 'rag_plot.png'
|
143 |
|
144 |
+
# Gradio interface with buttons
|
145 |
def chat_interface(query):
|
146 |
try:
|
147 |
response, retrieved_faqs, metrics = rag_process(query)
|
|
|
165 |
custom_css = """
|
166 |
body { background-color: #2a2a2a; color: #e0e0e0; }
|
167 |
.gr-box { background-color: #3a3a3a; border: 1px solid #4a4a4a; }
|
168 |
+
.gr-button { background-color: #1e90ff; color: white; margin: 5px; }
|
169 |
.gr-button:hover { background-color: #1c86ee; }
|
170 |
"""
|
171 |
|
172 |
+
# Get unique questions for buttons (after cleanup)
|
173 |
+
unique_questions = faq_data['question'].tolist()
|
174 |
+
|
175 |
with gr.Blocks(css=custom_css) as demo:
|
176 |
gr.Markdown("# Customer Experience Bot Demo")
|
177 |
+
gr.Markdown("Select a question to see the bot's response, retrieved FAQs, and call center data cleanup stats.")
|
178 |
|
179 |
+
# Create buttons for each question
|
180 |
with gr.Row():
|
181 |
+
for question in unique_questions:
|
182 |
+
gr.Button(question).click(
|
183 |
+
fn=chat_interface,
|
184 |
+
inputs=gr.State(value=question),
|
185 |
+
outputs=[
|
186 |
+
gr.Textbox(label="Bot Response"),
|
187 |
+
gr.Textbox(label="Retrieved FAQs"),
|
188 |
+
gr.Textbox(label="Data Cleanup Stats"),
|
189 |
+
gr.Image(label="RAG Pipeline Metrics")
|
190 |
+
]
|
191 |
+
)
|
192 |
|
193 |
response_output = gr.Textbox(label="Bot Response")
|
194 |
faq_output = gr.Textbox(label="Retrieved FAQs")
|
195 |
cleanup_output = gr.Textbox(label="Data Cleanup Stats")
|
196 |
plot_output = gr.Image(label="RAG Pipeline Metrics")
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
demo.launch()
|