Spaces:
Sleeping
Sleeping
Dharini Baskaran
commited on
Commit
·
e134a29
1
Parent(s):
5a5448a
updated app.py
Browse files
app.py
CHANGED
|
@@ -28,7 +28,7 @@ model_path = os.path.join(OUTPUT_DIR, "model_final.pth")
|
|
| 28 |
GOOGLE_DRIVE_FILE_ID = "1yr64AOgaYZPTcQzG6cxG6lWBENHR9qjW"
|
| 29 |
GDRIVE_URL = f"https://drive.google.com/uc?id={GOOGLE_DRIVE_FILE_ID}"
|
| 30 |
|
| 31 |
-
#
|
| 32 |
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 33 |
os.makedirs(JSON_DIR, exist_ok=True)
|
| 34 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
@@ -53,7 +53,7 @@ sys.path.append(MODEL_DIR)
|
|
| 53 |
from rcnn_run import main, write_config
|
| 54 |
|
| 55 |
# ==================================
|
| 56 |
-
#
|
| 57 |
# ==================================
|
| 58 |
|
| 59 |
st.set_page_config(
|
|
@@ -62,24 +62,6 @@ st.set_page_config(
|
|
| 62 |
initial_sidebar_state="collapsed"
|
| 63 |
)
|
| 64 |
|
| 65 |
-
st.markdown(
|
| 66 |
-
"""
|
| 67 |
-
<style>
|
| 68 |
-
.stApp { background-color: #FAFAFA; }
|
| 69 |
-
.header-title { font-size: 2.5rem; font-weight: bold; text-align: center;
|
| 70 |
-
background: linear-gradient(to right, #D4ECDD, #EAF4F4);
|
| 71 |
-
color: #2C3E50; padding: 20px; border-radius: 12px; }
|
| 72 |
-
.upload-container { display: flex; flex-direction: column; align-items: center;
|
| 73 |
-
justify-content: center; background: white; padding: 20px;
|
| 74 |
-
border-radius: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1); }
|
| 75 |
-
.json-container { background: #F5F5F5; padding: 15px; border-radius: 10px;
|
| 76 |
-
font-family: monospace; overflow-y: auto; max-height: 400px;
|
| 77 |
-
white-space: pre-wrap; }
|
| 78 |
-
</style>
|
| 79 |
-
""",
|
| 80 |
-
unsafe_allow_html=True
|
| 81 |
-
)
|
| 82 |
-
|
| 83 |
# ==================================
|
| 84 |
# HEADER
|
| 85 |
# ==================================
|
|
@@ -130,11 +112,14 @@ if uploaded_file is not None:
|
|
| 130 |
progress_bar = st.progress(0)
|
| 131 |
status_text = st.empty()
|
| 132 |
|
| 133 |
-
# === 🔥 Run
|
| 134 |
input_image = uploaded_path
|
| 135 |
output_json_name = uploaded_file.name.replace(".png", "_result.json").replace(".jpg", "_result.json").replace(".jpeg", "_result.json")
|
| 136 |
output_image_name = uploaded_file.name.replace(".png", "_result.png").replace(".jpg", "_result.png").replace(".jpeg", "_result.png")
|
| 137 |
|
|
|
|
|
|
|
|
|
|
| 138 |
cfg = write_config()
|
| 139 |
print("⚙️ Model config created. Running model...")
|
| 140 |
|
|
@@ -144,15 +129,9 @@ if uploaded_file is not None:
|
|
| 144 |
progress_bar.progress(i)
|
| 145 |
status_text.text(f"Preprocessing: {i}%")
|
| 146 |
|
| 147 |
-
|
| 148 |
-
output_json_path = os.path.join(JSON_DIR, output_json_name)
|
| 149 |
-
output_image_path = os.path.join(JSON_DIR, output_image_name)
|
| 150 |
main(cfg, input_image, output_json_path, output_image_path)
|
| 151 |
print("✅ Model run complete.")
|
| 152 |
-
# main(cfg, input_image, output_json_name, output_image_name)
|
| 153 |
-
# # Prepare output paths
|
| 154 |
-
# output_json_path = os.path.join(JSON_DIR, output_json_name)
|
| 155 |
-
# output_image_path = os.path.join(JSON_DIR, output_image_name)
|
| 156 |
|
| 157 |
while not os.path.exists(output_json_path):
|
| 158 |
print("Waiting for JSON output...")
|
|
@@ -179,26 +158,26 @@ if uploaded_file is not None:
|
|
| 179 |
st.session_state.processing_complete = True
|
| 180 |
|
| 181 |
# ==================================
|
| 182 |
-
# DISPLAY
|
| 183 |
# ==================================
|
| 184 |
|
| 185 |
out_col1, out_col2 = st.columns(2)
|
| 186 |
|
| 187 |
with out_col1:
|
| 188 |
if os.path.exists(output_image_path):
|
| 189 |
-
# st.image(output_image_path, caption="🖼 Output Vectorized Image", use_container_width=True)
|
| 190 |
with open(output_image_path, "rb") as img_file:
|
| 191 |
image = Image.open(img_file)
|
| 192 |
st.image(image, caption="🖼 Output Vectorized Image", use_container_width=True)
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
|
|
|
|
| 202 |
json_str = json.dumps(st.session_state.json_output, indent=4)
|
| 203 |
st.download_button(
|
| 204 |
label="Download JSON",
|
|
@@ -206,8 +185,6 @@ if uploaded_file is not None:
|
|
| 206 |
file_name="floorplan_output.json",
|
| 207 |
mime="application/json"
|
| 208 |
)
|
| 209 |
-
else:
|
| 210 |
-
st.warning("⚠️ Output image not found.")
|
| 211 |
|
| 212 |
with out_col2:
|
| 213 |
st.markdown("<div class='json-container'>", unsafe_allow_html=True)
|
|
|
|
| 28 |
GOOGLE_DRIVE_FILE_ID = "1yr64AOgaYZPTcQzG6cxG6lWBENHR9qjW"
|
| 29 |
GDRIVE_URL = f"https://drive.google.com/uc?id={GOOGLE_DRIVE_FILE_ID}"
|
| 30 |
|
| 31 |
+
# Create necessary folders
|
| 32 |
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 33 |
os.makedirs(JSON_DIR, exist_ok=True)
|
| 34 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
|
|
| 53 |
from rcnn_run import main, write_config
|
| 54 |
|
| 55 |
# ==================================
|
| 56 |
+
# PAGE CONFIG
|
| 57 |
# ==================================
|
| 58 |
|
| 59 |
st.set_page_config(
|
|
|
|
| 62 |
initial_sidebar_state="collapsed"
|
| 63 |
)
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
# ==================================
|
| 66 |
# HEADER
|
| 67 |
# ==================================
|
|
|
|
| 112 |
progress_bar = st.progress(0)
|
| 113 |
status_text = st.empty()
|
| 114 |
|
| 115 |
+
# === 🔥 Model Run Here ===
|
| 116 |
input_image = uploaded_path
|
| 117 |
output_json_name = uploaded_file.name.replace(".png", "_result.json").replace(".jpg", "_result.json").replace(".jpeg", "_result.json")
|
| 118 |
output_image_name = uploaded_file.name.replace(".png", "_result.png").replace(".jpg", "_result.png").replace(".jpeg", "_result.png")
|
| 119 |
|
| 120 |
+
output_json_path = os.path.join(JSON_DIR, output_json_name)
|
| 121 |
+
output_image_path = os.path.join(JSON_DIR, output_image_name)
|
| 122 |
+
|
| 123 |
cfg = write_config()
|
| 124 |
print("⚙️ Model config created. Running model...")
|
| 125 |
|
|
|
|
| 129 |
progress_bar.progress(i)
|
| 130 |
status_text.text(f"Preprocessing: {i}%")
|
| 131 |
|
| 132 |
+
# Run model
|
|
|
|
|
|
|
| 133 |
main(cfg, input_image, output_json_path, output_image_path)
|
| 134 |
print("✅ Model run complete.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
while not os.path.exists(output_json_path):
|
| 137 |
print("Waiting for JSON output...")
|
|
|
|
| 158 |
st.session_state.processing_complete = True
|
| 159 |
|
| 160 |
# ==================================
|
| 161 |
+
# DISPLAY OUTPUTS
|
| 162 |
# ==================================
|
| 163 |
|
| 164 |
out_col1, out_col2 = st.columns(2)
|
| 165 |
|
| 166 |
with out_col1:
|
| 167 |
if os.path.exists(output_image_path):
|
|
|
|
| 168 |
with open(output_image_path, "rb") as img_file:
|
| 169 |
image = Image.open(img_file)
|
| 170 |
st.image(image, caption="🖼 Output Vectorized Image", use_container_width=True)
|
| 171 |
|
| 172 |
+
img_file.seek(0)
|
| 173 |
+
st.download_button(
|
| 174 |
+
label="Download Output Image",
|
| 175 |
+
data=img_file,
|
| 176 |
+
file_name="floorplan_output.png",
|
| 177 |
+
mime="image/png"
|
| 178 |
+
)
|
| 179 |
|
| 180 |
+
if os.path.exists(output_json_path):
|
| 181 |
json_str = json.dumps(st.session_state.json_output, indent=4)
|
| 182 |
st.download_button(
|
| 183 |
label="Download JSON",
|
|
|
|
| 185 |
file_name="floorplan_output.json",
|
| 186 |
mime="application/json"
|
| 187 |
)
|
|
|
|
|
|
|
| 188 |
|
| 189 |
with out_col2:
|
| 190 |
st.markdown("<div class='json-container'>", unsafe_allow_html=True)
|