Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1472,18 +1472,21 @@ KEY INSIGHTS:
|
|
| 1472 |
return f"Analysis error: {str(e)}", None
|
| 1473 |
|
| 1474 |
def fake_detection_interface(reviews_text: str, file_upload):
|
| 1475 |
-
"""
|
| 1476 |
try:
|
| 1477 |
analyzer = get_analyzer()
|
| 1478 |
reviews = []
|
| 1479 |
metadata = {}
|
| 1480 |
|
|
|
|
| 1481 |
if file_upload is not None:
|
| 1482 |
reviews, metadata = process_file_upload(file_upload)
|
| 1483 |
if 'error' in metadata:
|
| 1484 |
return metadata['error'], None
|
| 1485 |
else:
|
| 1486 |
-
|
|
|
|
|
|
|
| 1487 |
|
| 1488 |
if not reviews:
|
| 1489 |
return "Please enter review text or upload a file", None
|
|
@@ -1496,27 +1499,29 @@ def fake_detection_interface(reviews_text: str, file_upload):
|
|
| 1496 |
if 'error' in result:
|
| 1497 |
return result['error'], None
|
| 1498 |
|
| 1499 |
-
# Create
|
| 1500 |
-
|
| 1501 |
-
|
| 1502 |
-
|
| 1503 |
-
|
| 1504 |
-
plotly.go.
|
| 1505 |
-
|
| 1506 |
-
|
| 1507 |
-
|
| 1508 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1509 |
)
|
| 1510 |
-
|
| 1511 |
-
|
| 1512 |
-
title="Fake Risk Distribution",
|
| 1513 |
-
xaxis_title="Risk Score",
|
| 1514 |
-
yaxis_title="Number of Reviews"
|
| 1515 |
-
)
|
| 1516 |
|
| 1517 |
-
#
|
| 1518 |
-
formatted_result = f"""
|
| 1519 |
-
DETECTION SUMMARY:
|
| 1520 |
Total Reviews: {result['summary']['total_reviews']}
|
| 1521 |
Suspicious Reviews: {result['summary']['suspicious_reviews']}
|
| 1522 |
Authenticity Rate: {result['summary']['authenticity_rate']:.1f}%
|
|
@@ -1530,13 +1535,13 @@ RECOMMENDATIONS:
|
|
| 1530 |
{chr(10).join(['• ' + rec for rec in result['recommendations']])}
|
| 1531 |
|
| 1532 |
HIGH RISK SAMPLES:
|
| 1533 |
-
{chr(10).join([f'{i+1}. {item["text"][:50]}... | Risk: {item["risk_score"]:.2f}
|
| 1534 |
-
|
|
|
|
| 1535 |
|
| 1536 |
return formatted_result, fig
|
| 1537 |
|
| 1538 |
except Exception as e:
|
| 1539 |
-
logger.error(f"Fake detection error: {str(e)}")
|
| 1540 |
return f"Analysis error: {str(e)}", None
|
| 1541 |
|
| 1542 |
def quality_assessment_interface(reviews_text: str, file_upload, length_weight, detail_weight,
|
|
|
|
| 1472 |
return f"Analysis error: {str(e)}", None
|
| 1473 |
|
| 1474 |
def fake_detection_interface(reviews_text: str, file_upload):
|
| 1475 |
+
"""Fixed fake detection interface"""
|
| 1476 |
try:
|
| 1477 |
analyzer = get_analyzer()
|
| 1478 |
reviews = []
|
| 1479 |
metadata = {}
|
| 1480 |
|
| 1481 |
+
# Process file upload first (priority over text input)
|
| 1482 |
if file_upload is not None:
|
| 1483 |
reviews, metadata = process_file_upload(file_upload)
|
| 1484 |
if 'error' in metadata:
|
| 1485 |
return metadata['error'], None
|
| 1486 |
else:
|
| 1487 |
+
# Only process text input if no file uploaded
|
| 1488 |
+
reviews = [line.strip() for line in reviews_text.split('\n')
|
| 1489 |
+
if line.strip() and len(line.strip()) > 10]
|
| 1490 |
|
| 1491 |
if not reviews:
|
| 1492 |
return "Please enter review text or upload a file", None
|
|
|
|
| 1499 |
if 'error' in result:
|
| 1500 |
return result['error'], None
|
| 1501 |
|
| 1502 |
+
# Create chart
|
| 1503 |
+
try:
|
| 1504 |
+
lazy_import()
|
| 1505 |
+
risk_scores = [item['risk_score'] for item in result['individual_analysis']]
|
| 1506 |
+
|
| 1507 |
+
fig = plotly.go.Figure(data=[
|
| 1508 |
+
plotly.go.Histogram(
|
| 1509 |
+
x=risk_scores,
|
| 1510 |
+
nbinsx=20,
|
| 1511 |
+
marker_color='red',
|
| 1512 |
+
opacity=0.7
|
| 1513 |
+
)
|
| 1514 |
+
])
|
| 1515 |
+
fig.update_layout(
|
| 1516 |
+
title="Fake Risk Distribution",
|
| 1517 |
+
xaxis_title="Risk Score",
|
| 1518 |
+
yaxis_title="Number of Reviews"
|
| 1519 |
)
|
| 1520 |
+
except:
|
| 1521 |
+
fig = None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1522 |
|
| 1523 |
+
# Format results
|
| 1524 |
+
formatted_result = f"""DETECTION SUMMARY:
|
|
|
|
| 1525 |
Total Reviews: {result['summary']['total_reviews']}
|
| 1526 |
Suspicious Reviews: {result['summary']['suspicious_reviews']}
|
| 1527 |
Authenticity Rate: {result['summary']['authenticity_rate']:.1f}%
|
|
|
|
| 1535 |
{chr(10).join(['• ' + rec for rec in result['recommendations']])}
|
| 1536 |
|
| 1537 |
HIGH RISK SAMPLES:
|
| 1538 |
+
{chr(10).join([f'{i+1}. {item["text"][:50]}... | Risk: {item["risk_score"]:.2f}'
|
| 1539 |
+
for i, item in enumerate([r for r in result['individual_analysis']
|
| 1540 |
+
if r['risk_score'] > 0.5][:3]) if result['individual_analysis']])}"""
|
| 1541 |
|
| 1542 |
return formatted_result, fig
|
| 1543 |
|
| 1544 |
except Exception as e:
|
|
|
|
| 1545 |
return f"Analysis error: {str(e)}", None
|
| 1546 |
|
| 1547 |
def quality_assessment_interface(reviews_text: str, file_upload, length_weight, detail_weight,
|