Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,6 +1,21 @@
|
|
| 1 |
from flask import Flask, render_template, request, jsonify, send_file
|
| 2 |
-
|
| 3 |
-
from services.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
from collections import Counter
|
| 6 |
import pandas as pd
|
|
|
|
| 1 |
from flask import Flask, render_template, request, jsonify, send_file
|
| 2 |
+
try:
|
| 3 |
+
from services.aggregator import collect_data
|
| 4 |
+
except Exception as e:
|
| 5 |
+
print(f"❌ FATAL: aggregator gagal load: {e}")
|
| 6 |
+
def collect_data(kw, src="all"): return [("unknown", "aggregator error")]
|
| 7 |
+
|
| 8 |
+
try:
|
| 9 |
+
from services.sentiment import predict_with_score
|
| 10 |
+
except Exception as e:
|
| 11 |
+
print(f"⚠️ sentiment gagal load: {e} — rule-based fallback")
|
| 12 |
+
def predict_with_score(texts):
|
| 13 |
+
def _rb(t):
|
| 14 |
+
pos = sum(1 for k in ['bagus','baik','senang','suka','mantap','oke','good','great'] if k in t.lower())
|
| 15 |
+
neg = sum(1 for k in ['buruk','jelek','benci','kecewa','gagal','bad','worst'] if k in t.lower())
|
| 16 |
+
label = 'Positive' if pos > neg else 'Negative' if neg > pos else 'Neutral'
|
| 17 |
+
return {'label': label, 'score': 0.5}
|
| 18 |
+
return [_rb(t) for t in texts]
|
| 19 |
|
| 20 |
from collections import Counter
|
| 21 |
import pandas as pd
|