Spaces:
Sleeping
Sleeping
File size: 2,804 Bytes
5e5cf2c 392c927 5e5cf2c ff9d78a 5e5cf2c 1da682d 392c927 8b5bb08 5e5cf2c ff9d78a 8b5bb08 ff9d78a 5e5cf2c 8b5bb08 5e5cf2c ff9d78a 8b5bb08 5e5cf2c ff9d78a 5e5cf2c 8b5bb08 5e5cf2c ff9d78a 8b5bb08 ff9d78a 5e5cf2c 8b5bb08 5e5cf2c 8b5bb08 5e5cf2c ff9d78a 568bb43 8b5bb08 5e5cf2c ff9d78a 8b5bb08 ff9d78a 8b5bb08 5e5cf2c ff9d78a 8b5bb08 ff9d78a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
import json
import os
import matplotlib.pyplot as plt
import networkx as nx
from html import escape
def safe_escape(val):
return escape(str(val)) if val is not None else "N/A"
output_dir = "/tmp"
# Load data
with open(os.path.join(output_dir, "data.json"), "r", encoding="utf-8") as f:
data = json.load(f)
# Sentiment Chart
sentiment_path = os.path.join(output_dir, "sentiment_pie_chart.png")
labels = list(data.get("sentiment_overview", {}).keys())
sizes = list(data.get("sentiment_overview", {}).values())
colors = ['#4CAF50', '#FFC107', '#F44336']
fig, ax = plt.subplots()
ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140, colors=colors)
ax.axis('equal')
plt.title('Sentiment Overview')
plt.savefig(sentiment_path, bbox_inches='tight')
plt.close()
# Network Graph
network_path = os.path.join(output_dir, "network_graph.png")
G = nx.Graph()
for cluster in data.get("network_analysis", {}).get("clusters", []):
nodes = cluster["nodes"]
for i in range(len(nodes)):
G.add_node(nodes[i])
for j in range(i + 1, len(nodes)):
G.add_edge(nodes[i], nodes[j])
plt.figure(figsize=(8, 6))
pos = nx.spring_layout(G, seed=42)
node_colors = ['lightblue' if 'Trump' in node else 'salmon' for node in G.nodes()]
nx.draw(G, pos, with_labels=True, node_color=node_colors, edge_color='gray', node_size=1200, font_size=8)
plt.title("Network Influence Graph")
plt.savefig(network_path, bbox_inches='tight')
plt.close()
# Helper formatters
def bullet_list(items):
return "\n".join(f"<li>{escape(item)}<\/li>" for item in items)
def user_blocks(users):
return "\n".join(f"<p><strong>{escape(u['username'])} ({u['type']}):</strong> {escape(u['activity_summary'])}</p>" for u in users)
def cluster_blocks(clusters):
return "\n".join(f"<p><strong>{escape(c['label'])}:</strong> {escape(c['summary'])}</p>" for c in clusters)
# Load HTML template
with open("osint_dark_template.html", "r", encoding="utf-8") as tpl:
template = tpl.read()
# Fill content
html_filled = template.format(
summary=safe_escape(data.get("summary")),
topics=", ".join(escape(t) for t in data.get("top_topics", [])),
users=user_blocks(data.get("notable_users", [])),
clusters=cluster_blocks(data.get("network_analysis", {}).get("clusters", [])),
positive=data.get("sentiment_overview", {}).get("positive", 0),
neutral=data.get("sentiment_overview", {}).get("neutral", 0),
negative=data.get("sentiment_overview", {}).get("negative", 0),
flags=bullet_list(data.get("risk_flags", [])),
start=safe_escape(data.get("timestamp_range", {}).get("from")),
end=safe_escape(data.get("timestamp_range", {}).get("to"))
)
# Save HTML
with open(os.path.join(output_dir, "OSINT_Report.html"), "w", encoding="utf-8") as f:
f.write(html_filled) |