VectorV17 commited on
Commit
94b3504
·
verified ·
1 Parent(s): 69a56aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  from datetime import datetime
3
 
4
- # 1. Structured Knowledge Base for the Simplilearn MOOC FAQ Agent
5
  FAQ_KNOWLEDGE_BASE = {
6
  "refund": (
7
  "Simplilearn offers a 7-day refund policy for our MOOC and specialized educational pathways, "
@@ -24,14 +24,14 @@ FAQ_KNOWLEDGE_BASE = {
24
  )
25
  }
26
 
27
- # 2. Response Matching Logic
28
  def respond(user_message, chat_history):
29
  if not user_message.strip():
30
  return "", chat_history
31
 
32
  query = user_message.lower()
33
 
34
- # Simple, highly efficient semantic/keyword routing for CPU optimization
35
  if "refund" in query or "policy" in query:
36
  reply = FAQ_KNOWLEDGE_BASE["refund"]
37
  elif "certificate" in query or "unlock" in query:
@@ -46,7 +46,9 @@ def respond(user_message, chat_history):
46
  "grading criteria, and certificate requirements. Could you please specify your inquiry?"
47
  )
48
 
49
- chat_history.append((user_message, reply))
 
 
50
  return "", chat_history
51
 
52
  # 3. Custom CSS to mirror the provided screenshot layout and dark styling
@@ -161,7 +163,7 @@ body, .gradio-container {
161
  """
162
 
163
  # 4. Building the UI Layout
164
- with gr.Blocks(css=custom_css, title="Intelli_Agent") as demo:
165
 
166
  # Header Banner - "About Us"
167
  with gr.Row(elem_classes="about-card"):
@@ -173,7 +175,6 @@ with gr.Blocks(css=custom_css, title="Intelli_Agent") as demo:
173
  "helping learners unlock the full potential of specialized MOOC educational pathways."
174
  )
175
  with gr.Column(scale=2, min_width=200):
176
- # Dynamic matching of the exact date displayed in the reference image
177
  current_time_str = datetime.now().strftime("%dth %B %Y | time: %I:%M%p").lower()
178
  gr.HTML(f"<div class='time-stamp'>{current_time_str}</div>")
179
  gr.HTML("<div style='text-align: right; margin-top: 10px;'><button class='mode-btn'>☀️ 🌙 -> Change Mode (Day / Night)</button></div>")
@@ -183,7 +184,7 @@ with gr.Blocks(css=custom_css, title="Intelli_Agent") as demo:
183
  # Left Side Workspace: Chat Interface
184
  with gr.Column(scale=3):
185
  chatbot = gr.Chatbot(
186
- value=[(None, "Hello! I'm Lane, your Simplilearn Support Agent. How can I assist you with your courses today?")],
187
  elem_classes="chatbot-container",
188
  height=400,
189
  show_label=False
@@ -200,8 +201,7 @@ with gr.Blocks(css=custom_css, title="Intelli_Agent") as demo:
200
 
201
  # Right Side Workspace: Status Profile Panel
202
  with gr.Column(scale=1, min_width=280):
203
- with gr.Box(elem_classes="lane-card"):
204
- # Robot Emoji avatar representing the UI image icon
205
  gr.HTML("<div class='lane-avatar'>🤖</div>")
206
  gr.HTML("<div class='lane-title'>Lane <span class='lane-tag'>AI</span></div>")
207
  gr.HTML("<div class='lane-subtitle'>Your Agentic Learning Assistant</div>")
@@ -215,19 +215,17 @@ with gr.Blocks(css=custom_css, title="Intelli_Agent") as demo:
215
  )
216
 
217
  # Footer Bottom Quick Action Hint Suggestion Buttons
218
- with gr.Row(style="margin-top: 15px;"):
219
  refund_btn = gr.Button("What is the course refund policy?", elem_classes="suggestion-btn")
220
  cert_btn = gr.Button("How do I unlock my completion certificate?", elem_classes="suggestion-btn")
221
 
222
  # 5. Core Operational Bindings & App Wiring
223
- # Trigger submission via Send Button click
224
  send_button.click(
225
  fn=respond,
226
  inputs=[msg_input, chatbot],
227
  outputs=[msg_input, chatbot]
228
  )
229
 
230
- # Trigger submission via Enter keyboard key
231
  msg_input.submit(
232
  fn=respond,
233
  inputs=[msg_input, chatbot],
@@ -247,6 +245,6 @@ with gr.Blocks(css=custom_css, title="Intelli_Agent") as demo:
247
  outputs=[msg_input, chatbot]
248
  )
249
 
250
- # 6. Initialize Deployment Launch
251
  if __name__ == "__main__":
252
- demo.launch()
 
1
  import gradio as gr
2
  from datetime import datetime
3
 
4
+ # 1. Structured Knowledge Base for the Simplilearn MOOC FAQ Agent [cite: 169]
5
  FAQ_KNOWLEDGE_BASE = {
6
  "refund": (
7
  "Simplilearn offers a 7-day refund policy for our MOOC and specialized educational pathways, "
 
24
  )
25
  }
26
 
27
+ # 2. Response Matching Logic Updated for Modern Chatbot Format
28
  def respond(user_message, chat_history):
29
  if not user_message.strip():
30
  return "", chat_history
31
 
32
  query = user_message.lower()
33
 
34
+ # Simple, highly efficient semantic/keyword routing for CPU optimization [cite: 149, 150]
35
  if "refund" in query or "policy" in query:
36
  reply = FAQ_KNOWLEDGE_BASE["refund"]
37
  elif "certificate" in query or "unlock" in query:
 
46
  "grading criteria, and certificate requirements. Could you please specify your inquiry?"
47
  )
48
 
49
+ # Append utilizing the correct role/content dictionary format
50
+ chat_history.append({"role": "user", "content": user_message})
51
+ chat_history.append({"role": "assistant", "content": reply})
52
  return "", chat_history
53
 
54
  # 3. Custom CSS to mirror the provided screenshot layout and dark styling
 
163
  """
164
 
165
  # 4. Building the UI Layout
166
+ with gr.Blocks(title="Intelli_Agent") as demo:
167
 
168
  # Header Banner - "About Us"
169
  with gr.Row(elem_classes="about-card"):
 
175
  "helping learners unlock the full potential of specialized MOOC educational pathways."
176
  )
177
  with gr.Column(scale=2, min_width=200):
 
178
  current_time_str = datetime.now().strftime("%dth %B %Y | time: %I:%M%p").lower()
179
  gr.HTML(f"<div class='time-stamp'>{current_time_str}</div>")
180
  gr.HTML("<div style='text-align: right; margin-top: 10px;'><button class='mode-btn'>☀️ 🌙 -> Change Mode (Day / Night)</button></div>")
 
184
  # Left Side Workspace: Chat Interface
185
  with gr.Column(scale=3):
186
  chatbot = gr.Chatbot(
187
+ value=[{"role": "assistant", "content": "Hello! I'm Lane, your Simplilearn Support Agent. How can I assist you with your courses today?"}],
188
  elem_classes="chatbot-container",
189
  height=400,
190
  show_label=False
 
201
 
202
  # Right Side Workspace: Status Profile Panel
203
  with gr.Column(scale=1, min_width=280):
204
+ with gr.Group(elem_classes="lane-card"):
 
205
  gr.HTML("<div class='lane-avatar'>🤖</div>")
206
  gr.HTML("<div class='lane-title'>Lane <span class='lane-tag'>AI</span></div>")
207
  gr.HTML("<div class='lane-subtitle'>Your Agentic Learning Assistant</div>")
 
215
  )
216
 
217
  # Footer Bottom Quick Action Hint Suggestion Buttons
218
+ with gr.Row():
219
  refund_btn = gr.Button("What is the course refund policy?", elem_classes="suggestion-btn")
220
  cert_btn = gr.Button("How do I unlock my completion certificate?", elem_classes="suggestion-btn")
221
 
222
  # 5. Core Operational Bindings & App Wiring
 
223
  send_button.click(
224
  fn=respond,
225
  inputs=[msg_input, chatbot],
226
  outputs=[msg_input, chatbot]
227
  )
228
 
 
229
  msg_input.submit(
230
  fn=respond,
231
  inputs=[msg_input, chatbot],
 
245
  outputs=[msg_input, chatbot]
246
  )
247
 
248
+ # 6. Initialize Deployment Launch with Custom CSS passed directly here to support Gradio 6.0+
249
  if __name__ == "__main__":
250
+ demo.launch(css=custom_css)