Commit
ยท
fca100e
1
Parent(s):
c25b246
commit
Browse files
app.py
CHANGED
@@ -254,8 +254,7 @@ def render_grid_image(grid: List[List[str]]) -> str:
|
|
254 |
numeric_grid = np.array([[tile_map[cell] for cell in row] for row in grid])
|
255 |
|
256 |
# Create output folder if not exists
|
257 |
-
|
258 |
-
image_path = "static/level.png"
|
259 |
|
260 |
fig, ax = plt.subplots(figsize=(6, 6))
|
261 |
ax.imshow(numeric_grid, cmap=color_map, interpolation='none')
|
@@ -295,7 +294,7 @@ render_image_agent = create_react_agent(
|
|
295 |
"- Only use the render_grid_image tool to render the grid.\n"
|
296 |
"- When responding, ONLY return the raw file path returned by the tool.\n"
|
297 |
"- Do NOT add any commentary or formatting.\n"
|
298 |
-
"- Example: /
|
299 |
),
|
300 |
name="render_image_agent"
|
301 |
)
|
@@ -329,7 +328,7 @@ def run_streamed_supervisor(user_input):
|
|
329 |
|
330 |
final_messages = chunk["supervisor"]["messages"]
|
331 |
|
332 |
-
# Search the last messages for image path
|
333 |
for message in reversed(final_messages):
|
334 |
if hasattr(message, "content") and isinstance(message.content, str):
|
335 |
match = re.search(r"(/tmp/level\.png)", message.content)
|
@@ -337,9 +336,12 @@ def run_streamed_supervisor(user_input):
|
|
337 |
image_path = match.group(1)
|
338 |
break
|
339 |
|
340 |
-
#
|
341 |
if image_path and os.path.exists(image_path):
|
342 |
-
|
|
|
|
|
|
|
343 |
|
344 |
return "โ Image path not found or file does not exist."
|
345 |
|
@@ -381,7 +383,7 @@ with gr.Blocks() as demo:
|
|
381 |
|
382 |
with gr.Row():
|
383 |
inp = gr.Textbox(label="Instruction (e.g., 'design, test and render a spooky maze level with 1 enemy and 2 traps')")
|
384 |
-
out = gr.Image(label="Generated Maze")
|
385 |
|
386 |
with gr.Row():
|
387 |
btn = gr.Button("๐ฎ Generate Maze")
|
|
|
254 |
numeric_grid = np.array([[tile_map[cell] for cell in row] for row in grid])
|
255 |
|
256 |
# Create output folder if not exists
|
257 |
+
image_path = "/tmp/level.png"
|
|
|
258 |
|
259 |
fig, ax = plt.subplots(figsize=(6, 6))
|
260 |
ax.imshow(numeric_grid, cmap=color_map, interpolation='none')
|
|
|
294 |
"- Only use the render_grid_image tool to render the grid.\n"
|
295 |
"- When responding, ONLY return the raw file path returned by the tool.\n"
|
296 |
"- Do NOT add any commentary or formatting.\n"
|
297 |
+
"- Example: /tmp/level.png"
|
298 |
),
|
299 |
name="render_image_agent"
|
300 |
)
|
|
|
328 |
|
329 |
final_messages = chunk["supervisor"]["messages"]
|
330 |
|
331 |
+
# Search the last messages for image path like /tmp/level.png
|
332 |
for message in reversed(final_messages):
|
333 |
if hasattr(message, "content") and isinstance(message.content, str):
|
334 |
match = re.search(r"(/tmp/level\.png)", message.content)
|
|
|
336 |
image_path = match.group(1)
|
337 |
break
|
338 |
|
339 |
+
# โ
Copy image to static/ and return filepath
|
340 |
if image_path and os.path.exists(image_path):
|
341 |
+
os.makedirs("static", exist_ok=True)
|
342 |
+
static_path = os.path.join("static", os.path.basename(image_path))
|
343 |
+
shutil.copy(image_path, static_path)
|
344 |
+
return static_path # โ๏ธ Gradio will render it from here
|
345 |
|
346 |
return "โ Image path not found or file does not exist."
|
347 |
|
|
|
383 |
|
384 |
with gr.Row():
|
385 |
inp = gr.Textbox(label="Instruction (e.g., 'design, test and render a spooky maze level with 1 enemy and 2 traps')")
|
386 |
+
out = gr.Image(label="Generated Maze", type="filepath")
|
387 |
|
388 |
with gr.Row():
|
389 |
btn = gr.Button("๐ฎ Generate Maze")
|