Spaces:
Running
Running
output csv
Browse files
main.py
CHANGED
@@ -131,8 +131,8 @@ async def predict(file: UploadFile = File(...)):
|
|
131 |
timestamp = int(time.time())
|
132 |
input_file_path = os.path.join(current_dir, "uploads", f"input_{timestamp}.csv")
|
133 |
|
134 |
-
#
|
135 |
-
output_file_path = os.path.join(current_dir, "outputs", f"output_{timestamp}.
|
136 |
|
137 |
try:
|
138 |
with open(input_file_path, "wb") as buffer:
|
@@ -164,14 +164,18 @@ async def predict(file: UploadFile = File(...)):
|
|
164 |
output_df.loc[:, COL_STANDARD_SUBJECT] = df_predicted[COL_STANDARD_SUBJECT]
|
165 |
output_df.loc[:, COL_STANDARD_NAME] = df_predicted[COL_STANDARD_NAME]
|
166 |
|
167 |
-
# Save
|
168 |
-
output_df.
|
169 |
|
170 |
-
# Return the
|
171 |
return FileResponse(
|
172 |
path=output_file_path,
|
173 |
-
filename=f"output_{Path(file.filename).stem}.
|
174 |
-
media_type="
|
|
|
|
|
|
|
|
|
175 |
)
|
176 |
|
177 |
except Exception as e:
|
|
|
131 |
timestamp = int(time.time())
|
132 |
input_file_path = os.path.join(current_dir, "uploads", f"input_{timestamp}.csv")
|
133 |
|
134 |
+
# Use CSV format with correct extension
|
135 |
+
output_file_path = os.path.join(current_dir, "outputs", f"output_{timestamp}.csv")
|
136 |
|
137 |
try:
|
138 |
with open(input_file_path, "wb") as buffer:
|
|
|
164 |
output_df.loc[:, COL_STANDARD_SUBJECT] = df_predicted[COL_STANDARD_SUBJECT]
|
165 |
output_df.loc[:, COL_STANDARD_NAME] = df_predicted[COL_STANDARD_NAME]
|
166 |
|
167 |
+
# Save with Shift-JIS encoding for Japanese Excel compatibility
|
168 |
+
output_df.to_csv(output_file_path, index=False, encoding="utf_8_sig")
|
169 |
|
170 |
+
# Return the file as a download with correct content type and headers
|
171 |
return FileResponse(
|
172 |
path=output_file_path,
|
173 |
+
filename=f"output_{Path(file.filename).stem}.csv",
|
174 |
+
media_type="text/csv",
|
175 |
+
headers={
|
176 |
+
"Content-Disposition": f'attachment; filename="output_{Path(file.filename).stem}.csv"',
|
177 |
+
"Content-Type": "application/x-www-form-urlencoded",
|
178 |
+
},
|
179 |
)
|
180 |
|
181 |
except Exception as e:
|