cryptocalypse commited on
Commit
ce78ec6
1 Parent(s): 4e33a18

Create gen.py

Browse files
Files changed (1) hide show
  1. gen.py +155 -0
gen.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import pipeline
3
+ import sys
4
+ import sys
5
+
6
+ # Cargar el pipeline de generación de texto
7
+ pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", torch_dtype=torch.bfloat16, device_map="auto")
8
+
9
+ # Definir el prompt para generar un JSON con eventos anidados
10
+ prompt = (
11
+ "Genera un JSON que describa una serie de eventos consecutivos en un formato similar al siguiente:\n\n"
12
+ "{\n"
13
+ " \"events\": {\n"
14
+ " \"event\": {\n"
15
+ " \"event_number\": 1,\n"
16
+ " \"name\": \"conflict_start\",\n"
17
+ " \"description\": \"Tensions escalate between Iran and Israel\",\n"
18
+ " \"probability\": 70,\n"
19
+ " \"duration_days\": 30,\n"
20
+ " \"subevents\": {\n"
21
+ " \"event\": {\n"
22
+ " \"event_number\": 2,\n"
23
+ " \"name\": \"diplomatic_failure\",\n"
24
+ " \"description\": \"Diplomatic negotiations fail\",\n"
25
+ " \"probability\": 60,\n"
26
+ " \"duration_days\": 15,\n"
27
+ " \"subevents\": {\n"
28
+ " \"event\": {\n"
29
+ " \"event_number\": 3,\n"
30
+ " \"name\": \"military_clash\",\n"
31
+ " \"description\": \"Initial military clash at the border\",\n"
32
+ " \"probability\": 50,\n"
33
+ " \"duration_days\": 10,\n"
34
+ " \"subevents\": {\n"
35
+ " \"event\": [\n"
36
+ " {\n"
37
+ " \"event_number\": 4,\n"
38
+ " \"name\": \"escalation\",\n"
39
+ " \"description\": \"Conflict escalates into full-scale war\",\n"
40
+ " \"probability\": 40,\n"
41
+ " \"duration_days\": 180,\n"
42
+ " \"subevents\": {\n"
43
+ " \"event\": [\n"
44
+ " {\n"
45
+ " \"event_number\": 5,\n"
46
+ " \"name\": \"regional_involvement\",\n"
47
+ " \"description\": \"Other Middle Eastern countries get involved\",\n"
48
+ " \"probability\": 30,\n"
49
+ " \"duration_days\": 365,\n"
50
+ " \"subevents\": {\n"
51
+ " \"event\": [\n"
52
+ " {\n"
53
+ " \"event_number\": 6,\n"
54
+ " \"name\": \"ceasefire\",\n"
55
+ " \"description\": \"International powers broker a ceasefire\",\n"
56
+ " \"probability\": 20,\n"
57
+ " \"duration_days\": 30\n"
58
+ " },\n"
59
+ " {\n"
60
+ " \"event_number\": 7,\n"
61
+ " \"name\": \"prolonged_conflict\",\n"
62
+ " \"description\": \"Conflict continues for over a year\",\n"
63
+ " \"probability\": 50,\n"
64
+ " \"duration_days\": 365\n"
65
+ " }\n"
66
+ " ]\n"
67
+ " }\n"
68
+ " },\n"
69
+ " {\n"
70
+ " \"event_number\": 8,\n"
71
+ " \"name\": \"international_intervention\",\n"
72
+ " \"description\": \"UN or other international organizations intervene\",\n"
73
+ " \"probability\": 25,\n"
74
+ " \"duration_days\": 60\n"
75
+ " }\n"
76
+ " ]\n"
77
+ " }\n"
78
+ " },\n"
79
+ " {\n"
80
+ " \"event_number\": 9,\n"
81
+ " \"name\": \"containment\",\n"
82
+ " \"description\": \"Conflict is contained and doesn't escalate\",\n"
83
+ " \"probability\": 30,\n"
84
+ " \"duration_days\": 90\n"
85
+ " }\n"
86
+ " ]\n"
87
+ " }\n"
88
+ " },\n"
89
+ " \"event\": {\n"
90
+ " \"event_number\": 10,\n"
91
+ " \"name\": \"sanctions\",\n"
92
+ " \"description\": \"Increased sanctions on Iran\",\n"
93
+ " \"probability\": 70,\n"
94
+ " \"duration_days\": 180,\n"
95
+ " \"subevents\": {\n"
96
+ " \"event\": [\n"
97
+ " {\n"
98
+ " \"event_number\": 11,\n"
99
+ " \"name\": \"iran_retaliates\",\n"
100
+ " \"description\": \"Iran retaliates with cyberattacks\",\n"
101
+ " \"probability\": 40,\n"
102
+ " \"duration_days\": 60\n"
103
+ " },\n"
104
+ " {\n"
105
+ " \"event_number\": 12,\n"
106
+ " \"name\": \"israel_response\",\n"
107
+ " \"description\": \"Israel responds with targeted airstrikes\",\n"
108
+ " \"probability\": 50,\n"
109
+ " \"duration_days\": 60\n"
110
+ " }\n"
111
+ " ]\n"
112
+ " }\n"
113
+ " }\n"
114
+ " }\n"
115
+ " },\n"
116
+ " \"event\": {\n"
117
+ " \"event_number\": 13,\n"
118
+ " \"name\": \"diplomatic_success\",\n"
119
+ " \"description\": \"Successful diplomatic negotiations\",\n"
120
+ " \"probability\": 40,\n"
121
+ " \"duration_days\": 30,\n"
122
+ " \"subevents\": {\n"
123
+ " \"event\": [\n"
124
+ " {\n"
125
+ " \"event_number\": 14,\n"
126
+ " \"name\": \"peace_agreement\",\n"
127
+ " \"description\": \"Iran and Israel sign a peace agreement\",\n"
128
+ " \"probability\": 20,\n"
129
+ " \"duration_days\": 60\n"
130
+ " },\n"
131
+ " {\n"
132
+ " \"event_number\": 15,\n"
133
+ " \"name\": \"temporary_truce\",\n"
134
+ " \"description\": \"A temporary truce is established\",\n"
135
+ " \"probability\": 30,\n"
136
+ " \"duration_days\": 30\n"
137
+ " }\n"
138
+ " ]\n"
139
+ " }\n"
140
+ " }\n"
141
+ " }\n"
142
+ " }\n"
143
+ " }\n"
144
+ "}\n\n"
145
+ "Ahora, genera un JSON similar con eventos anidados, pero cambia los detalles y números para hacer que sea con el input que viene a continuacion, respondiendo solo el JSON: "
146
+ )
147
+
148
+
149
+ def generate():
150
+ # Generar el texto usando el modelo
151
+ outputs = pipe(prompt+" "+sys.argv[1], max_new_tokens=1024, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
152
+
153
+ # Imprimir la salida generada
154
+ print(outputs[0]["generated_text"])
155
+ return outputs[0]["generated_text"]