Spaces:
Runtime error
Runtime error
Commit
Β·
02b756e
1
Parent(s):
55bfd03
initial commit
Browse files- gen.py +21 -128
- psychohistory.py +5 -5
gen.py
CHANGED
@@ -41,141 +41,34 @@ else:
|
|
41 |
|
42 |
# Definir el prompt para generar un JSON con eventos anidados
|
43 |
prompt = (
|
44 |
-
"
|
45 |
"{\n"
|
46 |
" \"events\": {\n"
|
47 |
" \"event\": {\n"
|
48 |
-
" \"event_number\":
|
49 |
-
" \"name\":
|
50 |
-
" \"description\":
|
51 |
-
" \"probability\":
|
52 |
-
" \"duration_days\":
|
53 |
-
" \"subevents\": {\n"
|
54 |
-
" \"event\": {\n"
|
55 |
-
" \
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"
|
59 |
-
" \
|
60 |
-
"
|
61 |
-
" \"event\": {\n"
|
62 |
-
" \"event_number\": 3,\n"
|
63 |
-
" \"name\": \"military_clash\",\n"
|
64 |
-
" \"description\": \"Initial military clash at the border\",\n"
|
65 |
-
" \"probability\": 50,\n"
|
66 |
-
" \"duration_days\": 10,\n"
|
67 |
-
" \"subevents\": {\n"
|
68 |
-
" \"event\": [\n"
|
69 |
-
" {\n"
|
70 |
-
" \"event_number\": 4,\n"
|
71 |
-
" \"name\": \"escalation\",\n"
|
72 |
-
" \"description\": \"Conflict escalates into full-scale war\",\n"
|
73 |
-
" \"probability\": 40,\n"
|
74 |
-
" \"duration_days\": 180,\n"
|
75 |
-
" \"subevents\": {\n"
|
76 |
-
" \"event\": [\n"
|
77 |
-
" {\n"
|
78 |
-
" \"event_number\": 5,\n"
|
79 |
-
" \"name\": \"regional_involvement\",\n"
|
80 |
-
" \"description\": \"Other Middle Eastern countries get involved\",\n"
|
81 |
-
" \"probability\": 30,\n"
|
82 |
-
" \"duration_days\": 365,\n"
|
83 |
-
" \"subevents\": {\n"
|
84 |
-
" \"event\": [\n"
|
85 |
-
" {\n"
|
86 |
-
" \"event_number\": 6,\n"
|
87 |
-
" \"name\": \"ceasefire\",\n"
|
88 |
-
" \"description\": \"International powers broker a ceasefire\",\n"
|
89 |
-
" \"probability\": 20,\n"
|
90 |
-
" \"duration_days\": 30\n"
|
91 |
-
" },\n"
|
92 |
-
" {\n"
|
93 |
-
" \"event_number\": 7,\n"
|
94 |
-
" \"name\": \"prolonged_conflict\",\n"
|
95 |
-
" \"description\": \"Conflict continues for over a year\",\n"
|
96 |
-
" \"probability\": 50,\n"
|
97 |
-
" \"duration_days\": 365\n"
|
98 |
-
" }\n"
|
99 |
-
" ]\n"
|
100 |
-
" }\n"
|
101 |
-
" },\n"
|
102 |
-
" {\n"
|
103 |
-
" \"event_number\": 8,\n"
|
104 |
-
" \"name\": \"international_intervention\",\n"
|
105 |
-
" \"description\": \"UN or other international organizations intervene\",\n"
|
106 |
-
" \"probability\": 25,\n"
|
107 |
-
" \"duration_days\": 60\n"
|
108 |
-
" }\n"
|
109 |
-
" ]\n"
|
110 |
-
" }\n"
|
111 |
-
" },\n"
|
112 |
-
" {\n"
|
113 |
-
" \"event_number\": 9,\n"
|
114 |
-
" \"name\": \"containment\",\n"
|
115 |
-
" \"description\": \"Conflict is contained and doesn't escalate\",\n"
|
116 |
-
" \"probability\": 30,\n"
|
117 |
-
" \"duration_days\": 90\n"
|
118 |
-
" }\n"
|
119 |
-
" ]\n"
|
120 |
-
" }\n"
|
121 |
-
" },\n"
|
122 |
-
" \"event\": {\n"
|
123 |
-
" \"event_number\": 10,\n"
|
124 |
-
" \"name\": \"sanctions\",\n"
|
125 |
-
" \"description\": \"Increased sanctions on Iran\",\n"
|
126 |
-
" \"probability\": 70,\n"
|
127 |
-
" \"duration_days\": 180,\n"
|
128 |
-
" \"subevents\": {\n"
|
129 |
-
" \"event\": [\n"
|
130 |
-
" {\n"
|
131 |
-
" \"event_number\": 11,\n"
|
132 |
-
" \"name\": \"iran_retaliates\",\n"
|
133 |
-
" \"description\": \"Iran retaliates with cyberattacks\",\n"
|
134 |
-
" \"probability\": 40,\n"
|
135 |
-
" \"duration_days\": 60\n"
|
136 |
-
" },\n"
|
137 |
-
" {\n"
|
138 |
-
" \"event_number\": 12,\n"
|
139 |
-
" \"name\": \"israel_response\",\n"
|
140 |
-
" \"description\": \"Israel responds with targeted airstrikes\",\n"
|
141 |
-
" \"probability\": 50,\n"
|
142 |
-
" \"duration_days\": 60\n"
|
143 |
-
" }\n"
|
144 |
-
" ]\n"
|
145 |
-
" }\n"
|
146 |
-
" }\n"
|
147 |
-
" }\n"
|
148 |
-
" },\n"
|
149 |
-
" \"event\": {\n"
|
150 |
-
" \"event_number\": 13,\n"
|
151 |
-
" \"name\": \"diplomatic_success\",\n"
|
152 |
-
" \"description\": \"Successful diplomatic negotiations\",\n"
|
153 |
-
" \"probability\": 40,\n"
|
154 |
-
" \"duration_days\": 30,\n"
|
155 |
-
" \"subevents\": {\n"
|
156 |
-
" \"event\": [\n"
|
157 |
-
" {\n"
|
158 |
-
" \"event_number\": 14,\n"
|
159 |
-
" \"name\": \"peace_agreement\",\n"
|
160 |
-
" \"description\": \"Iran and Israel sign a peace agreement\",\n"
|
161 |
-
" \"probability\": 20,\n"
|
162 |
-
" \"duration_days\": 60\n"
|
163 |
-
" },\n"
|
164 |
-
" {\n"
|
165 |
-
" \"event_number\": 15,\n"
|
166 |
-
" \"name\": \"temporary_truce\",\n"
|
167 |
-
" \"description\": \"A temporary truce is established\",\n"
|
168 |
-
" \"probability\": 30,\n"
|
169 |
-
" \"duration_days\": 30\n"
|
170 |
-
" }\n"
|
171 |
-
" ]\n"
|
172 |
-
" }\n"
|
173 |
-
" }\n"
|
174 |
" }\n"
|
175 |
" }\n"
|
176 |
" }\n"
|
177 |
"}\n\n"
|
178 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
)
|
180 |
|
181 |
|
|
|
41 |
|
42 |
# Definir el prompt para generar un JSON con eventos anidados
|
43 |
prompt = (
|
44 |
+
"Generate a JSON object that describes a sequence of potential events, where each event can have nested subevents. The JSON structure should adhere to the following format:\n\n"
|
45 |
"{\n"
|
46 |
" \"events\": {\n"
|
47 |
" \"event\": {\n"
|
48 |
+
" \"event_number\": <integer>,\n"
|
49 |
+
" \"name\": <string>,\n"
|
50 |
+
" \"description\": <string>,\n"
|
51 |
+
" \"probability\": <integer (0-100)>,\n"
|
52 |
+
" \"duration_days\": <integer>,\n"
|
53 |
+
" \"subevents\": { \n"
|
54 |
+
" \"event\": { \n"
|
55 |
+
" // Nested events with the same structure\n"
|
56 |
+
" } \n"
|
57 |
+
" // or\n"
|
58 |
+
" \"event\": [\n"
|
59 |
+
" // Array of nested events with the same structure\n"
|
60 |
+
" ]\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
" }\n"
|
62 |
" }\n"
|
63 |
" }\n"
|
64 |
"}\n\n"
|
65 |
+
"Ensure the generated JSON is enclosed between `<json>` and `</json>` tags. For example:\n\n"
|
66 |
+
"<json>\n"
|
67 |
+
"{ \n"
|
68 |
+
" // Your generated JSON here \n"
|
69 |
+
"}\n"
|
70 |
+
"</json>\n\n"
|
71 |
+
"Now, generate a similar JSON with nested events, but change the details and numbers to reflect the following input, responding only with the JSON enclosed within the `<json>` and `</json>` tags: "
|
72 |
)
|
73 |
|
74 |
|
psychohistory.py
CHANGED
@@ -34,7 +34,6 @@ def generate_tree(current_x, current_y, depth, max_depth, max_nodes, x_range, G,
|
|
34 |
|
35 |
def build_graph_from_json(json_data, G):
|
36 |
"""Builds a graph from JSON data."""
|
37 |
-
# data = json.loads(json_data) # No need to load JSON here
|
38 |
|
39 |
def add_event(parent_id, event_data, depth):
|
40 |
node_id = len(G.nodes)
|
@@ -52,10 +51,11 @@ def build_graph_from_json(json_data, G):
|
|
52 |
for subevent in subevents:
|
53 |
add_event(node_id, subevent, depth + 1)
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
59 |
|
60 |
|
61 |
def find_paths(G):
|
|
|
34 |
|
35 |
def build_graph_from_json(json_data, G):
|
36 |
"""Builds a graph from JSON data."""
|
|
|
37 |
|
38 |
def add_event(parent_id, event_data, depth):
|
39 |
node_id = len(G.nodes)
|
|
|
51 |
for subevent in subevents:
|
52 |
add_event(node_id, subevent, depth + 1)
|
53 |
|
54 |
+
# Iterate through all top-level events
|
55 |
+
for event_data in json_data.get('events', {}).values():
|
56 |
+
root_id = len(G.nodes)
|
57 |
+
G.add_node(root_id, pos=(0, event_data['probability'] / 100.0, event_data['event_number']), label=event_data['name'])
|
58 |
+
add_event(None, event_data, 0) # Add each event as a root node
|
59 |
|
60 |
|
61 |
def find_paths(G):
|