SamanthaStorm commited on
Commit
0f140ee
Β·
verified Β·
1 Parent(s): 2a840d3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -30
app.py CHANGED
@@ -267,28 +267,40 @@ class FallacyFinder:
267
  # Format confidence as percentage
268
  confidence_percent = f"{confidence * 100:.1f}%"
269
 
270
- # Determine confidence level
271
  if confidence >= 0.8:
272
- confidence_level = "πŸ”΄ High Confidence"
273
  confidence_color = "high"
274
  elif confidence >= 0.6:
275
- confidence_level = "🟑 Medium Confidence"
276
  confidence_color = "medium"
277
  else:
278
  confidence_level = "🟒 Low Confidence"
279
  confidence_color = "low"
280
 
281
- # Format the main result
282
  if predicted_label == 'no_fallacy':
283
- result = f"βœ… **No Fallacy Detected**\n\n{confidence_level} ({confidence_percent})"
284
- icon = "βœ…"
285
  else:
286
- result = f"⚠️ **{fallacy_name}**\n\n{confidence_level} ({confidence_percent})"
287
- icon = "⚠️"
288
-
289
- # Add detected patterns for debugging
290
- if patterns:
291
- result += f"\n\n**Debug Info:** {patterns[0] if patterns else 'No patterns'}"
 
 
 
 
 
 
 
 
 
 
 
 
 
292
 
293
  # Format the explanation
294
  explanation = f"**What this means:**\n{description}"
@@ -322,33 +334,31 @@ def analyze_fallacy(message):
322
 
323
  # Create the Gradio interface
324
  with gr.Blocks(
325
- theme=gr.themes.Soft(primary_hue="red", secondary_hue="orange"),
326
  title="Fallacy Finder",
327
  css="""
328
  .gradio-container {
329
  max-width: 900px !important;
330
  }
331
  .high-confidence {
332
- border-left: 4px solid #ef4444;
333
  }
334
  .medium-confidence {
335
- border-left: 4px solid #eab308;
336
  }
337
  .low-confidence {
338
- border-left: 4px solid #22c55e;
339
  }
340
  """
341
  ) as demo:
342
 
343
  gr.Markdown(
344
  """
345
- # πŸ” Fallacy Finder (Debug Mode)
346
 
347
  Analyze messages for logical fallacies and argumentative patterns. Enter any statement, argument, or message to identify potential fallacies and get suggestions for better communication.
348
 
349
  **Detects 15+ types of fallacies** including ad hominem, strawman, whataboutism, gaslighting, and more.
350
-
351
- **πŸ› Debug Mode Active:** Check the console logs and fallacy_finder.log file for detailed analysis patterns.
352
  """
353
  )
354
 
@@ -419,9 +429,9 @@ with gr.Blocks(
419
  # Information section
420
  gr.Markdown(
421
  """
422
- ## 🎯 How It Works
423
 
424
- This tool analyzes text for common logical fallacies and argumentative patterns that can harm productive communication. It looks for:
425
 
426
  - **Personal attacks** instead of addressing arguments
427
  - **Misrepresentations** of opposing viewpoints
@@ -435,15 +445,7 @@ with gr.Blocks(
435
  βœ… **Address the actual position being argued**
436
  βœ… **Use evidence and logical reasoning**
437
  βœ… **Acknowledge valid points from the other side**
438
- βœ… **Stay on topic and address concerns directly**
439
-
440
- ### πŸ› Debug Information
441
-
442
- Check the console output or `fallacy_finder.log` file to see:
443
- - Whether the trained model or rule-based system was used
444
- - Specific patterns detected by rules
445
- - Model prediction scores for all fallacy types
446
- - Step-by-step analysis process
447
  """
448
  )
449
 
 
267
  # Format confidence as percentage
268
  confidence_percent = f"{confidence * 100:.1f}%"
269
 
270
+ # Determine confidence level and colors
271
  if confidence >= 0.8:
272
+ confidence_level = "πŸ”΅ High Confidence"
273
  confidence_color = "high"
274
  elif confidence >= 0.6:
275
+ confidence_level = "🟣 Medium Confidence"
276
  confidence_color = "medium"
277
  else:
278
  confidence_level = "🟒 Low Confidence"
279
  confidence_color = "low"
280
 
281
+ # Format the main result with better structure
282
  if predicted_label == 'no_fallacy':
283
+ result = f"βœ… **No Fallacy Detected**\n\n**Confidence:** {confidence_level} ({confidence_percent})"
 
284
  else:
285
+ result = f"⚠️ **{fallacy_name}**\n\n**Confidence:** {confidence_level} ({confidence_percent})"
286
+
287
+ # Add top predictions in a clean list format
288
+ if patterns and patterns[0].startswith('model_prediction'):
289
+ # Extract top 3 predictions from debug info
290
+ try:
291
+ import ast
292
+ debug_str = patterns[0].replace('model_prediction: top_3: ', '')
293
+ top_predictions = ast.literal_eval(debug_str)
294
+
295
+ result += f"\n\n**Top Predictions:**"
296
+ for i, (fallacy, score) in enumerate(top_predictions, 1):
297
+ fallacy_display = self.fallacy_labels.get(fallacy, fallacy.replace('_', ' ').title())
298
+ percentage = f"{float(score) * 100:.1f}%"
299
+ result += f"\n{i}. {fallacy_display}: {percentage}"
300
+
301
+ except:
302
+ # Fallback if parsing fails
303
+ result += f"\n\n**Debug Info:** Model prediction analysis available in logs"
304
 
305
  # Format the explanation
306
  explanation = f"**What this means:**\n{description}"
 
334
 
335
  # Create the Gradio interface
336
  with gr.Blocks(
337
+ theme=gr.themes.Soft(primary_hue="blue", secondary_hue="indigo"),
338
  title="Fallacy Finder",
339
  css="""
340
  .gradio-container {
341
  max-width: 900px !important;
342
  }
343
  .high-confidence {
344
+ border-left: 4px solid #3b82f6;
345
  }
346
  .medium-confidence {
347
+ border-left: 4px solid #8b5cf6;
348
  }
349
  .low-confidence {
350
+ border-left: 4px solid #10b981;
351
  }
352
  """
353
  ) as demo:
354
 
355
  gr.Markdown(
356
  """
357
+ # πŸ” Fallacy Finder
358
 
359
  Analyze messages for logical fallacies and argumentative patterns. Enter any statement, argument, or message to identify potential fallacies and get suggestions for better communication.
360
 
361
  **Detects 15+ types of fallacies** including ad hominem, strawman, whataboutism, gaslighting, and more.
 
 
362
  """
363
  )
364
 
 
429
  # Information section
430
  gr.Markdown(
431
  """
432
+ ### 🎯 How It Works
433
 
434
+ This tool uses an AI model trained to detect logical fallacies and argumentative patterns that can harm productive communication. It analyzes:
435
 
436
  - **Personal attacks** instead of addressing arguments
437
  - **Misrepresentations** of opposing viewpoints
 
445
  βœ… **Address the actual position being argued**
446
  βœ… **Use evidence and logical reasoning**
447
  βœ… **Acknowledge valid points from the other side**
448
+ βœ… **Stay on topic and address concerns directly**
 
 
 
 
 
 
 
 
449
  """
450
  )
451