Update app.py
Browse files122344567239 unmodified lines247248249250251252253254255256257258259260261262263264265266267268269# --- FastAPI imports ---from fastapi import FastAPI, Request, Queryfrom fastapi import FastAPI, Request, Query, File, UploadFile, Formfrom fastapi.responses import JSONResponse
import shutil# Add interactive loop for user input with Ctrl+C to breakapp = FastAPI()
239 unmodified lines if json_obj: return JSONResponse(content=json_obj) return JSONResponse(content={"error": "No valid JSON found", "raw": response}, status_code=422)
@app.post("/ask_image")async def ask_image(user_input: str = Form(...), image: UploadFile = File(...)): if not user_input.strip(): return JSONResponse(content={"error": "user_input is required"}, status_code=400) # Save the uploaded image to a file image_path = "Taken_image.jpg" with open(image_path, "wb") as buffer: shutil.copyfileobj(image.file, buffer) # Now call the agent as usual loop = asyncio.get_event_loop() try: response = await loop.run_in_executor(None, query_agent_with_planning, user_input) except asyncio.CancelledError: return JSONResponse(content={"error": "Request was cancelled"}, status_code=499) json_obj = extract_json_from_response(response) if json_obj: return JSONResponse(content=json_obj) return JSONResponse(content={"error": "No valid JSON found", "raw": response}, status_code=422)app.py+22-2