Spaces:
Sleeping
Sleeping
Update render_report.py
Browse files- render_report.py +35 -98
render_report.py
CHANGED
|
@@ -1,24 +1,19 @@
|
|
| 1 |
|
|
|
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
import networkx as nx
|
| 6 |
|
| 7 |
-
#
|
| 8 |
output_dir = "/tmp"
|
| 9 |
|
| 10 |
-
# Load
|
| 11 |
-
with open("
|
| 12 |
data = json.load(f)
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
network_chart = os.path.join(output_dir, "network_graph.png")
|
| 17 |
-
html_output = os.path.join(output_dir, "OSINT_Report.html")
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
# Generate sentiment pie chart
|
| 22 |
labels = list(data["sentiment_overview"].keys())
|
| 23 |
sizes = list(data["sentiment_overview"].values())
|
| 24 |
colors = ['#4CAF50', '#FFC107', '#F44336']
|
|
@@ -26,11 +21,11 @@ fig, ax = plt.subplots()
|
|
| 26 |
ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140, colors=colors)
|
| 27 |
ax.axis('equal')
|
| 28 |
plt.title('Sentiment Overview')
|
| 29 |
-
|
| 30 |
-
plt.savefig(sentiment_chart, bbox_inches='tight')
|
| 31 |
plt.close()
|
| 32 |
|
| 33 |
# Generate network graph
|
|
|
|
| 34 |
G = nx.Graph()
|
| 35 |
for cluster in data["network_analysis"]["clusters"]:
|
| 36 |
nodes = cluster["nodes"]
|
|
@@ -38,102 +33,44 @@ for cluster in data["network_analysis"]["clusters"]:
|
|
| 38 |
G.add_node(nodes[i])
|
| 39 |
for j in range(i + 1, len(nodes)):
|
| 40 |
G.add_edge(nodes[i], nodes[j])
|
| 41 |
-
|
| 42 |
plt.figure(figsize=(8, 6))
|
| 43 |
pos = nx.spring_layout(G, seed=42)
|
| 44 |
node_colors = ['lightblue' if 'Trump' in node else 'salmon' for node in G.nodes()]
|
| 45 |
nx.draw(G, pos, with_labels=True, node_color=node_colors, edge_color='gray', node_size=1200, font_size=8)
|
| 46 |
plt.title("Network Influence Graph")
|
| 47 |
-
|
| 48 |
-
plt.savefig(network_chart, bbox_inches='tight')
|
| 49 |
plt.close()
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
|
| 53 |
-
<!DOCTYPE html>
|
| 54 |
-
<html lang="en">
|
| 55 |
-
<head>
|
| 56 |
-
<meta charset="UTF-8">
|
| 57 |
-
<title>OSINT Intelligence Report</title>
|
| 58 |
-
<style>
|
| 59 |
-
body {{
|
| 60 |
-
font-family: Arial, sans-serif;
|
| 61 |
-
margin: 40px;
|
| 62 |
-
background-color: #f9f9f9;
|
| 63 |
-
}}
|
| 64 |
-
h1 {{
|
| 65 |
-
color: #2c3e50;
|
| 66 |
-
text-align: center;
|
| 67 |
-
}}
|
| 68 |
-
h2 {{
|
| 69 |
-
color: #34495e;
|
| 70 |
-
border-bottom: 2px solid #ccc;
|
| 71 |
-
padding-bottom: 5px;
|
| 72 |
-
}}
|
| 73 |
-
.section {{
|
| 74 |
-
margin-bottom: 30px;
|
| 75 |
-
}}
|
| 76 |
-
.image {{
|
| 77 |
-
text-align: center;
|
| 78 |
-
margin: 20px 0;
|
| 79 |
-
}}
|
| 80 |
-
</style>
|
| 81 |
-
</head>
|
| 82 |
-
<body>
|
| 83 |
-
<h1>OSINT Intelligence Report</h1>
|
| 84 |
-
|
| 85 |
-
<div class="section">
|
| 86 |
-
<h2>Summary</h2>
|
| 87 |
-
<p>{data["summary"]}</p>
|
| 88 |
-
</div>
|
| 89 |
-
|
| 90 |
-
<div class="section">
|
| 91 |
-
<h2>Top Topics</h2>
|
| 92 |
-
<p>{', '.join(data["top_topics"])}</p>
|
| 93 |
-
</div>
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
{''.join([f"<p><strong>{u['username']} ({u['type']}):</strong> {u['activity_summary']}</p>" for u in data["notable_users"]])}
|
| 98 |
-
</div>
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
{''.join([f"<p><strong>{c['label']}:</strong> {c['summary']}</p>" for c in data["network_analysis"]["clusters"]])}
|
| 103 |
-
</div>
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
<p>Positive: {data['sentiment_overview']['positive']}%</p>
|
| 108 |
-
<p>Neutral: {data['sentiment_overview']['neutral']}%</p>
|
| 109 |
-
<p>Negative: {data['sentiment_overview']['negative']}%</p>
|
| 110 |
-
<div class="image">
|
| 111 |
-
<img src="sentiment_pie_chart.png" width="500">
|
| 112 |
-
</div>
|
| 113 |
-
</div>
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
<img src="network_graph.png" width="600">
|
| 119 |
-
</div>
|
| 120 |
-
</div>
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
<p>To: {data["timestamp_range"]["to"]}</p>
|
| 133 |
-
</div>
|
| 134 |
-
</body>
|
| 135 |
-
</html>
|
| 136 |
-
"""
|
| 137 |
|
| 138 |
-
with open(html_output, "w", encoding="utf-8") as f:
|
| 139 |
-
f.write(html_content)
|
|
|
|
| 1 |
|
| 2 |
+
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
import networkx as nx
|
| 7 |
|
| 8 |
+
# Set safe output path
|
| 9 |
output_dir = "/tmp"
|
| 10 |
|
| 11 |
+
# Load data
|
| 12 |
+
with open(os.path.join(output_dir, "data.json"), "r", encoding="utf-8") as f:
|
| 13 |
data = json.load(f)
|
| 14 |
|
| 15 |
+
# Generate sentiment chart
|
| 16 |
+
sentiment_path = os.path.join(output_dir, "sentiment_pie_chart.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
labels = list(data["sentiment_overview"].keys())
|
| 18 |
sizes = list(data["sentiment_overview"].values())
|
| 19 |
colors = ['#4CAF50', '#FFC107', '#F44336']
|
|
|
|
| 21 |
ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140, colors=colors)
|
| 22 |
ax.axis('equal')
|
| 23 |
plt.title('Sentiment Overview')
|
| 24 |
+
plt.savefig(sentiment_path, bbox_inches='tight')
|
|
|
|
| 25 |
plt.close()
|
| 26 |
|
| 27 |
# Generate network graph
|
| 28 |
+
network_path = os.path.join(output_dir, "network_graph.png")
|
| 29 |
G = nx.Graph()
|
| 30 |
for cluster in data["network_analysis"]["clusters"]:
|
| 31 |
nodes = cluster["nodes"]
|
|
|
|
| 33 |
G.add_node(nodes[i])
|
| 34 |
for j in range(i + 1, len(nodes)):
|
| 35 |
G.add_edge(nodes[i], nodes[j])
|
|
|
|
| 36 |
plt.figure(figsize=(8, 6))
|
| 37 |
pos = nx.spring_layout(G, seed=42)
|
| 38 |
node_colors = ['lightblue' if 'Trump' in node else 'salmon' for node in G.nodes()]
|
| 39 |
nx.draw(G, pos, with_labels=True, node_color=node_colors, edge_color='gray', node_size=1200, font_size=8)
|
| 40 |
plt.title("Network Influence Graph")
|
| 41 |
+
plt.savefig(network_path, bbox_inches='tight')
|
|
|
|
| 42 |
plt.close()
|
| 43 |
|
| 44 |
+
# Format data into HTML
|
| 45 |
+
from html import escape
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
def bullet_list(items):
|
| 48 |
+
return "\n".join(f"<li>{escape(item)}</li>" for item in items)
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
def user_blocks(users):
|
| 51 |
+
return "\n".join(f"<p><strong>{escape(u['username'])} ({u['type']}):</strong> {escape(u['activity_summary'])}</p>" for u in users)
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
def cluster_blocks(clusters):
|
| 54 |
+
return "\n".join(f"<p><strong>{escape(c['label'])}:</strong> {escape(c['summary'])}</p>" for c in clusters)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
# Load dark HTML template
|
| 57 |
+
with open("/osint_dark_template.html", "r", encoding="utf-8") as tpl:
|
| 58 |
+
template = tpl.read()
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
html_filled = template.format(
|
| 61 |
+
summary=escape(data["summary"]),
|
| 62 |
+
topics=", ".join(escape(topic) for topic in data["top_topics"]),
|
| 63 |
+
users=user_blocks(data["notable_users"]),
|
| 64 |
+
clusters=cluster_blocks(data["network_analysis"]["clusters"]),
|
| 65 |
+
positive=data["sentiment_overview"]["positive"],
|
| 66 |
+
neutral=data["sentiment_overview"]["neutral"],
|
| 67 |
+
negative=data["sentiment_overview"]["negative"],
|
| 68 |
+
flags=bullet_list(data["risk_flags"]),
|
| 69 |
+
start=escape(data["timestamp_range"]["from"]),
|
| 70 |
+
end=escape(data["timestamp_range"]["to"])
|
| 71 |
+
)
|
| 72 |
|
| 73 |
+
# Write final report
|
| 74 |
+
with open(os.path.join(output_dir, "OSINT_Report.html"), "w", encoding="utf-8") as f:
|
| 75 |
+
f.write(html_filled)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
|
|
|
|
|