from fastapi import FastAPI, File, UploadFile from fastapi.responses import FileResponse import os from main import load_model, generate_mesh ## create a new FASTAPI app instance app=FastAPI() model = load_model() @app.get("/") def home(): return {"message":"Hello World"} # Define a function to handle the GET request at `/generate` @app.post("/generate") async def generate(image: UploadFile = File(...)): # Save the uploaded image to a temporary location temp_image_path = f"tmp/output/{image.filename}" with open(temp_image_path, "wb") as f: f.write(await image.read()) output_file_path = generate_mesh(image_path=temp_image_path ,output_dir='tmp/output/' ,model=model) ## return the generate text in Json reposne return FileResponse(output_file_path, media_type='application/octet-stream', filename="output.obj")