Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,19 @@
|
|
1 |
import pandas as pd
|
2 |
from itertools import permutations
|
3 |
-
from
|
4 |
-
from
|
|
|
|
|
5 |
|
6 |
-
app =
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
class Box:
|
10 |
def __init__(self, length, width, height, quantity, box_type):
|
@@ -103,19 +112,23 @@ def pack_boxes(truck, boxes):
|
|
103 |
|
104 |
return packed_positions
|
105 |
|
106 |
-
@app.
|
107 |
-
def upload_file(
|
108 |
-
file =
|
|
|
|
|
|
|
|
|
109 |
if not file:
|
110 |
-
|
111 |
|
112 |
ext = file.filename.split('.')[-1].lower()
|
113 |
if ext == 'csv':
|
114 |
-
data = pd.read_csv(file)
|
115 |
elif ext in ['xls', 'xlsx']:
|
116 |
-
data = pd.read_excel(file)
|
117 |
else:
|
118 |
-
|
119 |
|
120 |
# Convert dimensions from CM to inches
|
121 |
data['PieceLength'] = data['PieceLength'] / 2.54
|
@@ -129,9 +142,9 @@ def upload_file():
|
|
129 |
]
|
130 |
|
131 |
# Convert truck dimensions from feet to inches
|
132 |
-
truck_length =
|
133 |
-
truck_width =
|
134 |
-
truck_height =
|
135 |
|
136 |
truck = Truck(truck_length, truck_width, truck_height)
|
137 |
|
@@ -151,7 +164,4 @@ def upload_file():
|
|
151 |
]
|
152 |
print(f"quantity {[box_data[i]['quantity'] for i in range(len(box_data))]}")
|
153 |
|
154 |
-
return
|
155 |
-
|
156 |
-
if __name__ == '__main__':
|
157 |
-
app.run(debug=True , host = "0.0.0.0" , port=8888)
|
|
|
1 |
import pandas as pd
|
2 |
from itertools import permutations
|
3 |
+
from fastapi import FastAPI, File, UploadFile, Form, HTTPException
|
4 |
+
from fastapi.middleware.cors import CORSMiddleware
|
5 |
+
from pydantic import BaseModel
|
6 |
+
from typing import List
|
7 |
|
8 |
+
app = FastAPI()
|
9 |
+
|
10 |
+
app.add_middleware(
|
11 |
+
CORSMiddleware,
|
12 |
+
allow_origins=["*"], # Allows all origins
|
13 |
+
allow_credentials=True,
|
14 |
+
allow_methods=["*"], # Allows all methods
|
15 |
+
allow_headers=["*"], # Allows all headers
|
16 |
+
)
|
17 |
|
18 |
class Box:
|
19 |
def __init__(self, length, width, height, quantity, box_type):
|
|
|
112 |
|
113 |
return packed_positions
|
114 |
|
115 |
+
@app.post("/upload/")
|
116 |
+
async def upload_file(
|
117 |
+
file: UploadFile = File(...),
|
118 |
+
length: float = Form(...),
|
119 |
+
width: float = Form(...),
|
120 |
+
height: float = Form(...),
|
121 |
+
):
|
122 |
if not file:
|
123 |
+
raise HTTPException(status_code=400, detail="No file uploaded")
|
124 |
|
125 |
ext = file.filename.split('.')[-1].lower()
|
126 |
if ext == 'csv':
|
127 |
+
data = pd.read_csv(file.file)
|
128 |
elif ext in ['xls', 'xlsx']:
|
129 |
+
data = pd.read_excel(file.file)
|
130 |
else:
|
131 |
+
raise HTTPException(status_code=400, detail="Unsupported file format")
|
132 |
|
133 |
# Convert dimensions from CM to inches
|
134 |
data['PieceLength'] = data['PieceLength'] / 2.54
|
|
|
142 |
]
|
143 |
|
144 |
# Convert truck dimensions from feet to inches
|
145 |
+
truck_length = length * 12 # Convert to inches
|
146 |
+
truck_width = width * 12 # Convert to inches
|
147 |
+
truck_height = height * 12 # Convert to inches
|
148 |
|
149 |
truck = Truck(truck_length, truck_width, truck_height)
|
150 |
|
|
|
164 |
]
|
165 |
print(f"quantity {[box_data[i]['quantity'] for i in range(len(box_data))]}")
|
166 |
|
167 |
+
return {"boxes": box_data}
|
|
|
|
|
|