Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -47,6 +47,31 @@ try:
|
|
| 47 |
except Exception:
|
| 48 |
def detect_fake_news(x): return []
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
app = Flask(__name__)
|
| 51 |
CONF_THRESHOLD = 0.60
|
| 52 |
|
|
@@ -384,7 +409,7 @@ def analyze():
|
|
| 384 |
bot_bert=detect_bot_bert(texts); fake_news=detect_fake_news(texts)
|
| 385 |
export=build_export_data(result_data,keyword,source,conf_stats_data,cross_data,trend)
|
| 386 |
save_export_csv(export)
|
| 387 |
-
return jsonify({"data":result_data,"top_words":top_words,"topics":topics,"insight":insight,"clusters":clusters,"hoax":hoax,"network":network,"bot_network":bot_network,"trend":trend,"bot_bert":bot_bert,"fake_news":fake_news,"gnn":gnn,"conf_stats":conf_stats_data,"cross_platform":cross_data,"export_summary":export["summary"]})
|
| 388 |
except Exception as e:
|
| 389 |
print(f"ERROR /analyze: {e}"); return jsonify({"error":str(e),"data":[]}),500
|
| 390 |
|
|
|
|
| 47 |
except Exception:
|
| 48 |
def detect_fake_news(x): return []
|
| 49 |
|
| 50 |
+
# ── New NLP Services ──
|
| 51 |
+
try:
|
| 52 |
+
from services.absa import analyze_absa
|
| 53 |
+
except Exception as e:
|
| 54 |
+
print(f"⚠️ ABSA not available: {e}")
|
| 55 |
+
def analyze_absa(x): return {'top_aspects':[],'aggregate':{},'aspect_sentiment_map':{}}
|
| 56 |
+
|
| 57 |
+
try:
|
| 58 |
+
from services.ner import analyze_ner
|
| 59 |
+
except Exception as e:
|
| 60 |
+
print(f"⚠️ NER not available: {e}")
|
| 61 |
+
def analyze_ner(x): return {'top_entities':[],'entities_by_type':{}}
|
| 62 |
+
|
| 63 |
+
try:
|
| 64 |
+
from services.advanced_nlp import (
|
| 65 |
+
analyze_stance, analyze_emotions,
|
| 66 |
+
extract_keywords, summarize_by_platform
|
| 67 |
+
)
|
| 68 |
+
except Exception as e:
|
| 69 |
+
print(f"⚠️ Advanced NLP not available: {e}")
|
| 70 |
+
def analyze_stance(x, t=None): return {'counts':{},'dominant':'Neutral','favor_pct':0,'against_pct':0,'neutral_pct':0}
|
| 71 |
+
def analyze_emotions(x): return {'distribution':{},'dominant':'neutral','emotional_pct':0}
|
| 72 |
+
def extract_keywords(x, n=20): return []
|
| 73 |
+
def summarize_by_platform(x): return {}
|
| 74 |
+
|
| 75 |
app = Flask(__name__)
|
| 76 |
CONF_THRESHOLD = 0.60
|
| 77 |
|
|
|
|
| 409 |
bot_bert=detect_bot_bert(texts); fake_news=detect_fake_news(texts)
|
| 410 |
export=build_export_data(result_data,keyword,source,conf_stats_data,cross_data,trend)
|
| 411 |
save_export_csv(export)
|
| 412 |
+
return jsonify({"data":result_data,"top_words":top_words,"topics":topics,"insight":insight,"clusters":clusters,"hoax":hoax,"network":network,"bot_network":bot_network,"trend":trend,"bot_bert":bot_bert,"fake_news":fake_news,"gnn":gnn,"conf_stats":conf_stats_data,"cross_platform":cross_data,"export_summary":export["summary"],"absa":absa_result,"ner":ner_result,"stance":stance_result,"emotions":emotion_result,"keywords":keywords_result,"summaries":summaries})
|
| 413 |
except Exception as e:
|
| 414 |
print(f"ERROR /analyze: {e}"); return jsonify({"error":str(e),"data":[]}),500
|
| 415 |
|