File size: 861 Bytes
8c93108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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")