Sathvika-Alla commited on
Commit
edba66d
·
verified ·
1 Parent(s): c680830

imporved faq formatting

Browse files
Files changed (1) hide show
  1. chatbot-gradio.py +36 -0
chatbot-gradio.py CHANGED
@@ -340,6 +340,39 @@ minimal_css = """
340
  """
341
  panel_visible = False
342
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343
  async def get_chatbot_examples():
344
  """Fetch FAQs and format them as Gradio chatbot examples"""
345
  try:
@@ -353,6 +386,8 @@ async def get_chatbot_examples():
353
  # Format as Gradio examples
354
  examples = []
355
  for faq in faqs:
 
 
356
  examples.append({
357
  "text": faq,
358
  "display_text": faq
@@ -363,6 +398,7 @@ async def get_chatbot_examples():
363
  logger.error(f"Failed to load FAQ examples: {str(e)}")
364
  return []
365
 
 
366
  def get_examples_sync():
367
  try:
368
  loop = asyncio.get_event_loop()
 
340
  """
341
  panel_visible = False
342
 
343
+ def format_faq_question(question):
344
+ """Format FAQ questions with proper capitalization and punctuation"""
345
+ # Remove extra whitespace
346
+ question = question.strip()
347
+
348
+ # Capitalize first letter
349
+ if question:
350
+ question = question[0].upper() + question[1:]
351
+
352
+ # Handle specific terms that should be capitalized
353
+ replacements = {
354
+ 'ma ': 'mA ', # milliamps
355
+ 'haloled': 'Haloled',
356
+ 'boa ': 'BOA ',
357
+ 'eur': 'EUR',
358
+ 'v ': 'V ', # volts
359
+ 'dali': 'DALI',
360
+ 'ip': 'IP'
361
+ }
362
+
363
+ for old, new in replacements.items():
364
+ question = question.replace(old, new)
365
+
366
+ # Add question mark if it's a question and doesn't end with punctuation
367
+ question_words = ['what', 'which', 'how', 'where', 'when', 'why', 'can', 'do', 'does']
368
+ if any(question.lower().startswith(word) for word in question_words):
369
+ if not question.endswith(('?', '.', '!')):
370
+ question += '?'
371
+
372
+ return question
373
+
374
+ panel_visible = False
375
+
376
  async def get_chatbot_examples():
377
  """Fetch FAQs and format them as Gradio chatbot examples"""
378
  try:
 
386
  # Format as Gradio examples
387
  examples = []
388
  for faq in faqs:
389
+ faq = format_faq_question(faq)
390
+ print(faq)
391
  examples.append({
392
  "text": faq,
393
  "display_text": faq
 
398
  logger.error(f"Failed to load FAQ examples: {str(e)}")
399
  return []
400
 
401
+
402
  def get_examples_sync():
403
  try:
404
  loop = asyncio.get_event_loop()