Spaces:
Running
Running
Dharini Baskaran
commited on
Commit
·
2f7fddd
1
Parent(s):
fea3237
updated app.py
Browse files
app.py
CHANGED
|
@@ -53,29 +53,57 @@ cfg = write_config()
|
|
| 53 |
# MAIN PREDICTION FUNCTION
|
| 54 |
# ==================================
|
| 55 |
|
| 56 |
-
def predict(uploaded_file):
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
return None, None, "No file uploaded."
|
| 59 |
-
# uploaded_path = uploaded_file
|
| 60 |
-
# input_filename = os.path.basename(uploaded_path)
|
| 61 |
-
# print(f"✅ Image received at {uploaded_path}")
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
print(f"✅ Image saved to {uploaded_path}")
|
| 67 |
|
| 68 |
-
|
| 69 |
-
# Save uploaded image
|
| 70 |
-
# input_bytes = uploaded_file.read()
|
| 71 |
-
# img = Image.open(BytesIO(input_bytes)).convert("RGB")
|
| 72 |
-
# input_filename = uploaded_file.name
|
| 73 |
-
# uploaded_path = os.path.join(UPLOAD_DIR, input_filename)
|
| 74 |
-
# img.save(uploaded_path)
|
| 75 |
-
# print(f"✅ Image saved to {uploaded_path}")
|
| 76 |
-
|
| 77 |
# Prepare output paths
|
| 78 |
-
input_filename = uploaded_file.name
|
| 79 |
output_json_name = input_filename.replace(".png", "_result.json").replace(".jpg", "_result.json").replace(".jpeg", "_result.json")
|
| 80 |
output_image_name = input_filename.replace(".png", "_result.png").replace(".jpg", "_result.png").replace(".jpeg", "_result.png")
|
| 81 |
|
|
|
|
| 53 |
# MAIN PREDICTION FUNCTION
|
| 54 |
# ==================================
|
| 55 |
|
| 56 |
+
# def predict(uploaded_file):
|
| 57 |
+
# if uploaded_file is None:
|
| 58 |
+
# return None, None, "No file uploaded."
|
| 59 |
+
# # uploaded_path = uploaded_file
|
| 60 |
+
# # input_filename = os.path.basename(uploaded_path)
|
| 61 |
+
# # print(f"✅ Image received at {uploaded_path}")
|
| 62 |
+
|
| 63 |
+
# uploaded_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
|
| 64 |
+
# with open(uploaded_path, "wb") as f:
|
| 65 |
+
# f.write(uploaded_file.read())
|
| 66 |
+
# print(f"✅ Image saved to {uploaded_path}")
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
# # Save uploaded image
|
| 70 |
+
# # input_bytes = uploaded_file.read()
|
| 71 |
+
# # img = Image.open(BytesIO(input_bytes)).convert("RGB")
|
| 72 |
+
# # input_filename = uploaded_file.name
|
| 73 |
+
# # uploaded_path = os.path.join(UPLOAD_DIR, input_filename)
|
| 74 |
+
# # img.save(uploaded_path)
|
| 75 |
+
# # print(f"✅ Image saved to {uploaded_path}")
|
| 76 |
+
|
| 77 |
+
# # Prepare output paths
|
| 78 |
+
# input_filename = uploaded_file.name
|
| 79 |
+
# output_json_name = input_filename.replace(".png", "_result.json").replace(".jpg", "_result.json").replace(".jpeg", "_result.json")
|
| 80 |
+
# output_image_name = input_filename.replace(".png", "_result.png").replace(".jpg", "_result.png").replace(".jpeg", "_result.png")
|
| 81 |
+
|
| 82 |
+
# output_json_path = os.path.join(JSON_DIR, output_json_name)
|
| 83 |
+
# output_image_path = os.path.join(JSON_DIR, output_image_name)
|
| 84 |
+
|
| 85 |
+
# # Run model
|
| 86 |
+
# main(cfg, uploaded_path, output_json_path, output_image_path)
|
| 87 |
+
|
| 88 |
+
# # Read outputs
|
| 89 |
+
# result_img = Image.open(output_image_path) if os.path.exists(output_image_path) else None
|
| 90 |
+
# result_json = {}
|
| 91 |
+
# if os.path.exists(output_json_path):
|
| 92 |
+
# with open(output_json_path, "r") as jf:
|
| 93 |
+
# result_json = json.load(jf)
|
| 94 |
+
|
| 95 |
+
# return result_img, json.dumps(result_json, indent=2), None
|
| 96 |
+
|
| 97 |
+
def predict(uploaded_file_path):
|
| 98 |
+
if uploaded_file_path is None:
|
| 99 |
return None, None, "No file uploaded."
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
input_filename = os.path.basename(uploaded_file_path)
|
| 102 |
+
uploaded_path = os.path.join(UPLOAD_DIR, input_filename)
|
| 103 |
+
shutil.copy(uploaded_file_path, uploaded_path)
|
| 104 |
print(f"✅ Image saved to {uploaded_path}")
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
# Prepare output paths
|
|
|
|
| 107 |
output_json_name = input_filename.replace(".png", "_result.json").replace(".jpg", "_result.json").replace(".jpeg", "_result.json")
|
| 108 |
output_image_name = input_filename.replace(".png", "_result.png").replace(".jpg", "_result.png").replace(".jpeg", "_result.png")
|
| 109 |
|