Spaces:
Sleeping
Sleeping
Create app.py
Browse files
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 = "
|
| 273 |
confidence_color = "high"
|
| 274 |
elif confidence >= 0.6:
|
| 275 |
-
confidence_level = "
|
| 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 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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="
|
| 326 |
title="Fallacy Finder",
|
| 327 |
css="""
|
| 328 |
.gradio-container {
|
| 329 |
max-width: 900px !important;
|
| 330 |
}
|
| 331 |
.high-confidence {
|
| 332 |
-
border-left: 4px solid #
|
| 333 |
}
|
| 334 |
.medium-confidence {
|
| 335 |
-
border-left: 4px solid #
|
| 336 |
}
|
| 337 |
.low-confidence {
|
| 338 |
-
border-left: 4px solid #
|
| 339 |
}
|
| 340 |
"""
|
| 341 |
) as demo:
|
| 342 |
|
| 343 |
gr.Markdown(
|
| 344 |
"""
|
| 345 |
-
# π Fallacy Finder
|
| 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
|
| 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 |
|