Update TextGen/router.py
Browse files- TextGen/router.py +51 -3
TextGen/router.py
CHANGED
@@ -171,6 +171,7 @@ def story(prompt: Invoke):
|
|
171 |
@app.post("/generate_level")
|
172 |
def placement(input: Rooms):
|
173 |
print(input)
|
|
|
174 |
answer={
|
175 |
"key":"value"
|
176 |
}
|
@@ -189,8 +190,8 @@ def determine_vocie_from_npc(npc,genre):
|
|
189 |
return "./voices/narator_out.wav"
|
190 |
#Dummy function for now
|
191 |
def determine_elevenLav_voice_from_npc(npc,genre):
|
192 |
-
if npc in
|
193 |
-
return
|
194 |
else:
|
195 |
if genre =="Male":
|
196 |
"bIHbv24MWmeRgasZH58o"
|
@@ -307,4 +308,51 @@ async def generate_song():
|
|
307 |
# img_byte_arr = img_byte_arr.getvalue()
|
308 |
#
|
309 |
# Return the image as a PNG response
|
310 |
-
# return Response(content=img_byte_arr, media_type="image/png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
@app.post("/generate_level")
|
172 |
def placement(input: Rooms):
|
173 |
print(input)
|
174 |
+
markdown_map=generate_map_markdown(input)
|
175 |
answer={
|
176 |
"key":"value"
|
177 |
}
|
|
|
190 |
return "./voices/narator_out.wav"
|
191 |
#Dummy function for now
|
192 |
def determine_elevenLav_voice_from_npc(npc,genre):
|
193 |
+
if npc in main_npcs_elevenlabs:
|
194 |
+
return main_npcs_elevenlabs[npc]
|
195 |
else:
|
196 |
if genre =="Male":
|
197 |
"bIHbv24MWmeRgasZH58o"
|
|
|
308 |
# img_byte_arr = img_byte_arr.getvalue()
|
309 |
#
|
310 |
# Return the image as a PNG response
|
311 |
+
# return Response(content=img_byte_arr, media_type="image/png")
|
312 |
+
|
313 |
+
def generate_map_markdown(data):
|
314 |
+
import numpy as np
|
315 |
+
|
316 |
+
# Define the room structure with walls and markers
|
317 |
+
def create_room(room_char):
|
318 |
+
return [
|
319 |
+
f"βββββ",
|
320 |
+
f"β {room_char} β",
|
321 |
+
f"βββββ"
|
322 |
+
]
|
323 |
+
|
324 |
+
# Extract rooms and rooms of interest
|
325 |
+
rooms = [eval(room) for room in data["rooms"]]
|
326 |
+
rooms_of_interest = [eval(room) for room in data["room_of_interest"]]
|
327 |
+
|
328 |
+
# Determine grid size
|
329 |
+
min_x = min(room[0] for room in rooms)
|
330 |
+
max_x = max(room[0] for room in rooms)
|
331 |
+
min_y = min(room[1] for room in rooms)
|
332 |
+
max_y = max(room[1] for room in rooms)
|
333 |
+
|
334 |
+
# Create grid with empty spaces represented by a room-like structure
|
335 |
+
map_height = (max_y - min_y + 1) * 3
|
336 |
+
map_width = (max_x - min_x + 1) * 5
|
337 |
+
grid = np.full((map_height, map_width), " ")
|
338 |
+
|
339 |
+
# Populate grid with rooms and their characteristics
|
340 |
+
for i, room in enumerate(rooms):
|
341 |
+
x, y = room
|
342 |
+
x_offset = (x - min_x) * 5
|
343 |
+
y_offset = (max_y - y) * 3
|
344 |
+
if room == (0, 0):
|
345 |
+
room_char = "X"
|
346 |
+
elif room in rooms_of_interest:
|
347 |
+
room_char = "P" if i == data["index_exit"] else "?"
|
348 |
+
else:
|
349 |
+
room_char = " "
|
350 |
+
room_structure = create_room(room_char)
|
351 |
+
for j, row in enumerate(room_structure):
|
352 |
+
grid[y_offset + j, x_offset:x_offset + 5] = list(row)
|
353 |
+
|
354 |
+
# Convert grid to a string format suitable for display
|
355 |
+
markdown_map = "\n".join("".join(row) for row in grid)
|
356 |
+
|
357 |
+
# Return the map wrapped in triple backticks for proper display in markdown
|
358 |
+
return f"```\n{markdown_map}\n```"
|