Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -305,30 +305,63 @@ The room layout should reflect the **user's specific input**, respecting their a
|
|
| 305 |
)
|
| 306 |
|
| 307 |
# ---- . FastAPI Endpoint ---- #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
@app.post("/design-room")
|
| 309 |
-
def design_room(request: DesignRequest):
|
| 310 |
try:
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
except Exception as e:
|
| 329 |
raise HTTPException(status_code=500, detail=str(e))
|
| 330 |
|
| 331 |
-
|
| 332 |
@app.get("/.well-known/ai-plugin.json", include_in_schema=False)
|
| 333 |
def plugin_manifest(request: Request):
|
| 334 |
base_url = str(request.base_url).rstrip("/")
|
|
@@ -338,8 +371,7 @@ def plugin_manifest(request: Request):
|
|
| 338 |
"name_for_model": "home_designer_agent",
|
| 339 |
"description_for_human": "An AI to help design home rooms with GPT-based agents.",
|
| 340 |
"description_for_model": (
|
| 341 |
-
"Use this plugin to design rooms, get blueprint prompts, "
|
| 342 |
-
"final rendering prompts, and Blender code for 3D models."
|
| 343 |
),
|
| 344 |
"auth": {"type": "none"},
|
| 345 |
"api": {
|
|
@@ -353,8 +385,9 @@ def plugin_manifest(request: Request):
|
|
| 353 |
}
|
| 354 |
return Response(content=json.dumps(manifest), media_type="application/json")
|
| 355 |
|
| 356 |
-
|
| 357 |
# For local testing
|
|
|
|
| 358 |
if __name__ == "__main__":
|
| 359 |
import uvicorn
|
| 360 |
uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
|
|
|
|
| 305 |
)
|
| 306 |
|
| 307 |
# ---- . FastAPI Endpoint ---- #
|
| 308 |
+
app = FastAPI(title="Home Designer Agent API", version="1.0")
|
| 309 |
+
|
| 310 |
+
# Request model for the design-room endpoint
|
| 311 |
+
class DesignRequest(BaseModel):
|
| 312 |
+
initial_input: str
|
| 313 |
+
|
| 314 |
@app.post("/design-room")
|
| 315 |
+
async def design_room(request: DesignRequest):
|
| 316 |
try:
|
| 317 |
+
# 1. Run InputAgent to collect user responses
|
| 318 |
+
input_result = await Runner.run(InputAgent, input=[{"role": "user", "content": request.initial_input}])
|
| 319 |
+
|
| 320 |
+
# Extract JSON from InputAgent's final output
|
| 321 |
+
json_match = re.search(r"{[\s\S]*}", input_result.final_output)
|
| 322 |
+
if not json_match:
|
| 323 |
+
raise HTTPException(status_code=400, detail="Failed to extract JSON from InputAgent output.")
|
| 324 |
+
data = json.loads(json_match.group())
|
| 325 |
+
|
| 326 |
+
# 2. Run downstream agents with structured JSON parts
|
| 327 |
+
room_result = await Runner.run(RoomContextAgent, input=[{"role": "user", "content": json.dumps({"room_context": data["room_context"]})}])
|
| 328 |
+
furnish_result = await Runner.run(FurnishingDetailsAgent, input=[{"role": "user", "content": json.dumps({"furnishing_details": data["furnishing_details"]})}])
|
| 329 |
+
aesthetic_result = await Runner.run(AestheticDirectionAgent, input=[{"role": "user", "content": json.dumps({"aesthetic_direction": data["aesthetic_direction"]})}])
|
| 330 |
+
|
| 331 |
+
# 3. Run BlueprintAgent using room_context and furnishing_details
|
| 332 |
+
blueprint_input = {
|
| 333 |
+
"room_context": data["room_context"],
|
| 334 |
+
"furnishing_details": data["furnishing_details"]
|
| 335 |
+
}
|
| 336 |
+
blueprint_result = await Runner.run(BlueprintAgent, input=[{"role": "user", "content": json.dumps(blueprint_input)}])
|
| 337 |
+
|
| 338 |
+
# 4. Run BlenderCodeAgent using blueprint prompt from BlueprintAgent
|
| 339 |
+
blender_input = {"blueprint_prompt": blueprint_result.final_output}
|
| 340 |
+
blender_result = await Runner.run(BlenderCodeAgent, input=[{"role": "user", "content": json.dumps(blender_input)}])
|
| 341 |
+
|
| 342 |
+
# 5. Run FinalRenderingAgent using blueprint layout, aesthetic direction, and blueprint image prompt
|
| 343 |
+
final_rendering_input = {
|
| 344 |
+
"blueprint_layout": blueprint_result.final_output,
|
| 345 |
+
"aesthetic_direction": aesthetic_result.final_output,
|
| 346 |
+
"blueprint_image_prompt": blueprint_result.final_output # assuming blueprint prompt is reused
|
| 347 |
}
|
| 348 |
+
final_rendering_result = await Runner.run(FinalRenderingAgent, input=[{"role": "user", "content": json.dumps(final_rendering_input)}])
|
| 349 |
+
|
| 350 |
+
# Compose final output summary
|
| 351 |
+
output = {
|
| 352 |
+
"input_summary": data,
|
| 353 |
+
"room_context": room_result.final_output,
|
| 354 |
+
"furnishing_details": furnish_result.final_output,
|
| 355 |
+
"aesthetic_direction": aesthetic_result.final_output,
|
| 356 |
+
"blueprint": blueprint_result.final_output,
|
| 357 |
+
"blender_code": blender_result.final_output,
|
| 358 |
+
"final_render_prompt": final_rendering_result.final_output,
|
| 359 |
+
}
|
| 360 |
+
return output
|
| 361 |
except Exception as e:
|
| 362 |
raise HTTPException(status_code=500, detail=str(e))
|
| 363 |
|
| 364 |
+
# Plugin Manifest Endpoint for ChatGPT Plugins
|
| 365 |
@app.get("/.well-known/ai-plugin.json", include_in_schema=False)
|
| 366 |
def plugin_manifest(request: Request):
|
| 367 |
base_url = str(request.base_url).rstrip("/")
|
|
|
|
| 371 |
"name_for_model": "home_designer_agent",
|
| 372 |
"description_for_human": "An AI to help design home rooms with GPT-based agents.",
|
| 373 |
"description_for_model": (
|
| 374 |
+
"Use this plugin to design rooms, get blueprint prompts, final rendering prompts, and Blender code for 3D models."
|
|
|
|
| 375 |
),
|
| 376 |
"auth": {"type": "none"},
|
| 377 |
"api": {
|
|
|
|
| 385 |
}
|
| 386 |
return Response(content=json.dumps(manifest), media_type="application/json")
|
| 387 |
|
| 388 |
+
# ----------------------------
|
| 389 |
# For local testing
|
| 390 |
+
# ----------------------------
|
| 391 |
if __name__ == "__main__":
|
| 392 |
import uvicorn
|
| 393 |
uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
|