Spaces:
Sleeping
Sleeping
loic.ledreck
commited on
Commit
·
b7a57b8
1
Parent(s):
0108e19
feat: map
Browse files- app.py +13 -0
- helper_functions.py +5 -1
- static/index.html +48 -37
app.py
CHANGED
@@ -23,6 +23,9 @@ init_game = True
|
|
23 |
game_over_rich = False
|
24 |
game_over_bankrupt = False
|
25 |
|
|
|
|
|
|
|
26 |
# Initialize FastAPI app
|
27 |
app = FastAPI()
|
28 |
|
@@ -60,6 +63,8 @@ async def send_message(message: Message):
|
|
60 |
global init_game
|
61 |
global game_over_rich
|
62 |
global game_over_bankrupt
|
|
|
|
|
63 |
try:
|
64 |
#If we're ate the beginning of a game
|
65 |
if init_game:
|
@@ -176,6 +181,14 @@ async def send_message(message: Message):
|
|
176 |
raise e
|
177 |
raise HTTPException(status_code=500, detail=str(e))
|
178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
# Add this before the final static files mount
|
180 |
app.mount("/images", StaticFiles(directory="static/images"), name="images")
|
181 |
|
|
|
23 |
game_over_rich = False
|
24 |
game_over_bankrupt = False
|
25 |
|
26 |
+
world_graph = WorldGraph(f'original_setup/contexts/world_map.edgelist')
|
27 |
+
dico_world = world_graph.push_data_to_front()
|
28 |
+
|
29 |
# Initialize FastAPI app
|
30 |
app = FastAPI()
|
31 |
|
|
|
63 |
global init_game
|
64 |
global game_over_rich
|
65 |
global game_over_bankrupt
|
66 |
+
global dico_world
|
67 |
+
|
68 |
try:
|
69 |
#If we're ate the beginning of a game
|
70 |
if init_game:
|
|
|
181 |
raise e
|
182 |
raise HTTPException(status_code=500, detail=str(e))
|
183 |
|
184 |
+
@app.get("/api/world-data", tags=['Game'])
|
185 |
+
async def get_world_data():
|
186 |
+
global dico_world
|
187 |
+
try:
|
188 |
+
return {"world_data": dico_world}
|
189 |
+
except Exception as e:
|
190 |
+
raise HTTPException(status_code=500, detail=str(e))
|
191 |
+
|
192 |
# Add this before the final static files mount
|
193 |
app.mount("/images", StaticFiles(directory="static/images"), name="images")
|
194 |
|
helper_functions.py
CHANGED
@@ -76,7 +76,11 @@ def generate_round_context(game_number):
|
|
76 |
idea_csq = file.readlines()
|
77 |
idea_csq = choice(idea_csq)
|
78 |
idea, delta_USA, delta_country, delta_friendliness = idea_csq.split(';')
|
79 |
-
|
|
|
|
|
|
|
|
|
80 |
with open(contexts_dir + 'countries.list', 'r',encoding='utf-8') as f_countries:
|
81 |
countries = f_countries.readlines()
|
82 |
country = choice(countries).split()[0]
|
|
|
76 |
idea_csq = file.readlines()
|
77 |
idea_csq = choice(idea_csq)
|
78 |
idea, delta_USA, delta_country, delta_friendliness = idea_csq.split(';')
|
79 |
+
try:
|
80 |
+
delta_friendliness = delta_friendliness.split()[0]
|
81 |
+
except:
|
82 |
+
pass
|
83 |
+
|
84 |
with open(contexts_dir + 'countries.list', 'r',encoding='utf-8') as f_countries:
|
85 |
countries = f_countries.readlines()
|
86 |
country = choice(countries).split()[0]
|
static/index.html
CHANGED
@@ -164,9 +164,6 @@
|
|
164 |
console.log("chat ended: ", data.chat_ended);
|
165 |
if (data.chat_ended === true) {
|
166 |
endSequence(data.idea, data.idea_is_accepted);
|
167 |
-
console.log("data.idea_is_accepted", data.idea_is_accepted)
|
168 |
-
console.log("data.idea_is_accepted true", data.idea_is_accepted === true)
|
169 |
-
console.log("data.idea_is_accepted false", data.idea_is_accepted === false)
|
170 |
console.log("data.idea", data.idea)
|
171 |
}
|
172 |
//addMessageToChat(data.character_response, false);
|
@@ -280,7 +277,22 @@
|
|
280 |
}
|
281 |
|
282 |
document.addEventListener('DOMContentLoaded', function() {
|
283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
|
285 |
// Load the intro content
|
286 |
fetch('./intro.html')
|
@@ -1074,41 +1086,40 @@
|
|
1074 |
};
|
1075 |
|
1076 |
// Le dico qu'on reçoit
|
1077 |
-
const regionData = {
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
};
|
1093 |
|
1094 |
function fetchUpdateMap() {
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
"
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
};
|
1111 |
-
updateMap(regionData);
|
1112 |
}
|
1113 |
|
1114 |
function updateMap(regionData) {
|
|
|
164 |
console.log("chat ended: ", data.chat_ended);
|
165 |
if (data.chat_ended === true) {
|
166 |
endSequence(data.idea, data.idea_is_accepted);
|
|
|
|
|
|
|
167 |
console.log("data.idea", data.idea)
|
168 |
}
|
169 |
//addMessageToChat(data.character_response, false);
|
|
|
277 |
}
|
278 |
|
279 |
document.addEventListener('DOMContentLoaded', function() {
|
280 |
+
fetch('/api/world-data', {
|
281 |
+
method: 'GET',
|
282 |
+
headers: {
|
283 |
+
'Content-Type': 'application/json'
|
284 |
+
},
|
285 |
+
})
|
286 |
+
.then(response => response.json())
|
287 |
+
.then(data => {
|
288 |
+
console.log("new world map: ", data)
|
289 |
+
const regionData = data.world_data
|
290 |
+
updateMap(regionData);
|
291 |
+
})
|
292 |
+
.catch(error => {
|
293 |
+
console.error('Could not update world map:', error);
|
294 |
+
});
|
295 |
+
|
296 |
|
297 |
// Load the intro content
|
298 |
fetch('./intro.html')
|
|
|
1086 |
};
|
1087 |
|
1088 |
// Le dico qu'on reçoit
|
1089 |
+
// const regionData = {
|
1090 |
+
// "United-States": { "money": 100, "friendliness": -1 },
|
1091 |
+
// "Canada": { "money": 50, "friendliness": -1 },
|
1092 |
+
// "Mexico": { "money": 30, "friendliness": 2 },
|
1093 |
+
// "South-America": { "money": 40, "friendliness": 3 },
|
1094 |
+
// "Africa": { "money": 20, "friendliness": 1 },
|
1095 |
+
// "Europe": { "money": 80, "friendliness": 2 },
|
1096 |
+
// "Middle-East": { "money": 60, "friendliness": -2 },
|
1097 |
+
// "Russia": { "money": 70, "friendliness": -3 },
|
1098 |
+
// "China": { "money": 90, "friendliness": -1 },
|
1099 |
+
// "India": { "money": 50, "friendliness": 2 },
|
1100 |
+
// "Australia": { "money": 55, "friendliness": 1 },
|
1101 |
+
// "Pacific": { "money": 25, "friendliness": 3 },
|
1102 |
+
// "Taiwan": { "money": 65, "friendliness": 0 },
|
1103 |
+
// "Greenland": { "money": 10, "friendliness": 1 }
|
1104 |
+
// };
|
1105 |
|
1106 |
function fetchUpdateMap() {
|
1107 |
+
|
1108 |
+
fetch('/api/world-data', {
|
1109 |
+
method: 'GET',
|
1110 |
+
headers: {
|
1111 |
+
'Content-Type': 'application/json'
|
1112 |
+
},
|
1113 |
+
})
|
1114 |
+
.then(response => response.json())
|
1115 |
+
.then(data => {
|
1116 |
+
console.log("new world map: ", data)
|
1117 |
+
const regionData = data.world_data
|
1118 |
+
updateMap(regionData);
|
1119 |
+
})
|
1120 |
+
.catch(error => {
|
1121 |
+
console.error('Could not update world map:', error);
|
1122 |
+
});
|
|
|
1123 |
}
|
1124 |
|
1125 |
function updateMap(regionData) {
|