Spaces:
Sleeping
Sleeping
Dharini Baskaran
commited on
Commit
·
b09ff42
1
Parent(s):
cb62968
working locally end2end
Browse files- app.py +10 -54
- rcnn_model/scripts/rcnn_run.py +3 -1
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -23,6 +23,8 @@ OUTPUT_DIR = "/tmp/output/"
|
|
| 23 |
MODEL_DIR = os.path.join(BASE_DIR, "rcnn_model", "scripts")
|
| 24 |
logo_path = os.path.join(BASE_DIR, "public", "logo.png")
|
| 25 |
model_path = os.path.join(OUTPUT_DIR, "model_final.pth")
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Google Drive model
|
| 28 |
GOOGLE_DRIVE_FILE_ID = "1yr64AOgaYZPTcQzG6cxG6lWBENHR9qjW"
|
|
@@ -53,61 +55,14 @@ cfg = write_config()
|
|
| 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 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
uploaded_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
|
| 106 |
-
with open(uploaded_path, "wb") as f:
|
| 107 |
-
f.write(uploaded_file.read())
|
| 108 |
-
print(f"✅ Image saved to {uploaded_path}")
|
| 109 |
-
|
| 110 |
-
input_filename = uploaded_file.name
|
| 111 |
|
| 112 |
# Prepare output paths
|
| 113 |
output_json_name = input_filename.replace(".png", "_result.json").replace(".jpg", "_result.json").replace(".jpeg", "_result.json")
|
|
@@ -116,8 +71,9 @@ def predict(uploaded_file_path):
|
|
| 116 |
output_json_path = os.path.join(JSON_DIR, output_json_name)
|
| 117 |
output_image_path = os.path.join(JSON_DIR, output_image_name)
|
| 118 |
|
|
|
|
| 119 |
# Run model
|
| 120 |
-
main(cfg,
|
| 121 |
|
| 122 |
# Read outputs
|
| 123 |
result_img = Image.open(output_image_path) if os.path.exists(output_image_path) else None
|
|
@@ -137,8 +93,8 @@ with gr.Blocks() as demo:
|
|
| 137 |
|
| 138 |
with gr.Row():
|
| 139 |
with gr.Column():
|
| 140 |
-
|
| 141 |
-
uploaded_file = gr.File(label="Upload your Floorplan Image", type="file")
|
| 142 |
run_button = gr.Button("Run Vectorizer 🔥")
|
| 143 |
|
| 144 |
with gr.Column():
|
|
|
|
| 23 |
MODEL_DIR = os.path.join(BASE_DIR, "rcnn_model", "scripts")
|
| 24 |
logo_path = os.path.join(BASE_DIR, "public", "logo.png")
|
| 25 |
model_path = os.path.join(OUTPUT_DIR, "model_final.pth")
|
| 26 |
+
# changine the model directory to the tmp directory
|
| 27 |
+
# model_path = os.path.join(OUTPUT_DIR, "model_final.pth")
|
| 28 |
|
| 29 |
# Google Drive model
|
| 30 |
GOOGLE_DRIVE_FILE_ID = "1yr64AOgaYZPTcQzG6cxG6lWBENHR9qjW"
|
|
|
|
| 55 |
# MAIN PREDICTION FUNCTION
|
| 56 |
# ==================================
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
def predict(uploaded_file_path):
|
| 59 |
+
print("Inside Predict:" + uploaded_file_path)
|
| 60 |
if uploaded_file_path is None:
|
| 61 |
return None, None, "No file uploaded."
|
| 62 |
|
| 63 |
+
uploaded_path = os.path.join(UPLOAD_DIR, "input_image.png")
|
| 64 |
+
print("Saved uploaded image to:", uploaded_path)
|
| 65 |
+
input_filename = "input_image.png"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# Prepare output paths
|
| 68 |
output_json_name = input_filename.replace(".png", "_result.json").replace(".jpg", "_result.json").replace(".jpeg", "_result.json")
|
|
|
|
| 71 |
output_json_path = os.path.join(JSON_DIR, output_json_name)
|
| 72 |
output_image_path = os.path.join(JSON_DIR, output_image_name)
|
| 73 |
|
| 74 |
+
# print(f"Before calling main in app.py: {uploaded_file.name}")
|
| 75 |
# Run model
|
| 76 |
+
main(cfg, uploaded_file_path, output_json_name, output_image_name)
|
| 77 |
|
| 78 |
# Read outputs
|
| 79 |
result_img = Image.open(output_image_path) if os.path.exists(output_image_path) else None
|
|
|
|
| 93 |
|
| 94 |
with gr.Row():
|
| 95 |
with gr.Column():
|
| 96 |
+
uploaded_file = gr.File(label="Upload your Floorplan Image", type="filepath")
|
| 97 |
+
# uploaded_file = gr.File(label="Upload your Floorplan Image", type="file")
|
| 98 |
run_button = gr.Button("Run Vectorizer 🔥")
|
| 99 |
|
| 100 |
with gr.Column():
|
rcnn_model/scripts/rcnn_run.py
CHANGED
|
@@ -29,7 +29,8 @@ sample_data_directory = "rcnn_model/sample/"
|
|
| 29 |
|
| 30 |
def main(cfg,img_source_path, coco_dest_filename, val_img_dest_filename):
|
| 31 |
os.chdir(str(from_root()))
|
| 32 |
-
|
|
|
|
| 33 |
#configure model
|
| 34 |
cfg.DATALOADER.NUM_WORKERS = 1
|
| 35 |
cfg.SOLVER.IMS_PER_BATCH = 1
|
|
@@ -49,6 +50,7 @@ def prediction_runner(filename, coco_dest_path, val_img_dest_path, predictor, se
|
|
| 49 |
#set up annotation builder
|
| 50 |
ann_builder = instantiate_ann_build()
|
| 51 |
|
|
|
|
| 52 |
#set up image
|
| 53 |
initImg = preprocess_image(filename)
|
| 54 |
init_width = initImg.shape[1]
|
|
|
|
| 29 |
|
| 30 |
def main(cfg,img_source_path, coco_dest_filename, val_img_dest_filename):
|
| 31 |
os.chdir(str(from_root()))
|
| 32 |
+
|
| 33 |
+
print("Inside main: " + img_source_path)
|
| 34 |
#configure model
|
| 35 |
cfg.DATALOADER.NUM_WORKERS = 1
|
| 36 |
cfg.SOLVER.IMS_PER_BATCH = 1
|
|
|
|
| 50 |
#set up annotation builder
|
| 51 |
ann_builder = instantiate_ann_build()
|
| 52 |
|
| 53 |
+
print("Filename inside prediction_runner: ", filename)
|
| 54 |
#set up image
|
| 55 |
initImg = preprocess_image(filename)
|
| 56 |
init_width = initImg.shape[1]
|
requirements.txt
CHANGED
|
@@ -8,4 +8,4 @@ matplotlib
|
|
| 8 |
labelme2coco
|
| 9 |
numpy
|
| 10 |
from_root
|
| 11 |
-
gradio==
|
|
|
|
| 8 |
labelme2coco
|
| 9 |
numpy
|
| 10 |
from_root
|
| 11 |
+
pip install gradio==4.44.1
|