Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +62 -8
src/streamlit_app.py
CHANGED
|
@@ -18,6 +18,13 @@ import tempfile
|
|
| 18 |
os.environ['STREAMLIT_BROWSER_GATHER_USAGE_STATS'] = 'false'
|
| 19 |
os.environ['MPLCONFIGDIR'] = tempfile.gettempdir()
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Page configuration
|
| 22 |
st.set_page_config(
|
| 23 |
page_title="Kolam Design Analyzer",
|
|
@@ -362,11 +369,25 @@ except ImportError as e:
|
|
| 362 |
with col1:
|
| 363 |
st.markdown("### π€ Upload Kolam Image")
|
| 364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
uploaded_file = st.file_uploader(
|
| 366 |
"Choose a Kolam image...",
|
| 367 |
type=["png", "jpg", "jpeg"],
|
| 368 |
help="Upload a clear image of a Kolam design for analysis"
|
| 369 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
|
| 371 |
if uploaded_file:
|
| 372 |
# Display uploaded image
|
|
@@ -374,24 +395,56 @@ with col1:
|
|
| 374 |
st.image(image, caption="Uploaded Kolam", use_column_width=True)
|
| 375 |
|
| 376 |
# Analysis button
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
if st.button("π Analyze Kolam Design", type="primary"):
|
| 378 |
with st.spinner("Analyzing Kolam design..."):
|
| 379 |
# Process image
|
| 380 |
original, thresh, edges = analyzer.preprocess_image(
|
| 381 |
-
|
| 382 |
)
|
| 383 |
-
|
| 384 |
# Detect nodes and edges
|
| 385 |
nodes = analyzer.detect_nodes(edges, max_corners)
|
| 386 |
graph_edges = analyzer.detect_edges(edges, nodes, min_line_length)
|
| 387 |
-
|
| 388 |
# Build graph
|
| 389 |
G = analyzer.build_graph(nodes, graph_edges)
|
| 390 |
-
|
| 391 |
# Extract features
|
| 392 |
features = analyzer.extract_graph_features(G)
|
| 393 |
-
|
| 394 |
-
#
|
| 395 |
st.session_state.analysis_complete = True
|
| 396 |
st.session_state.original_img = original
|
| 397 |
st.session_state.thresh_img = thresh
|
|
@@ -399,13 +452,14 @@ with col1:
|
|
| 399 |
st.session_state.nodes = nodes
|
| 400 |
st.session_state.graph = G
|
| 401 |
st.session_state.features = features
|
| 402 |
-
|
| 403 |
# Generate encryption key
|
| 404 |
encryption_key = analyzer.generate_encryption_key()
|
| 405 |
st.session_state.encryption_key = encryption_key
|
| 406 |
-
|
| 407 |
st.success("β
Analysis completed successfully!")
|
| 408 |
|
|
|
|
| 409 |
with col2:
|
| 410 |
st.markdown("### π Analysis Results")
|
| 411 |
|
|
|
|
| 18 |
os.environ['STREAMLIT_BROWSER_GATHER_USAGE_STATS'] = 'false'
|
| 19 |
os.environ['MPLCONFIGDIR'] = tempfile.gettempdir()
|
| 20 |
|
| 21 |
+
# --- Session state initialization ---
|
| 22 |
+
if 'uploaded_image' not in st.session_state:
|
| 23 |
+
st.session_state['uploaded_image'] = None
|
| 24 |
+
if 'analysis_complete' not in st.session_state:
|
| 25 |
+
st.session_state['analysis_complete'] = False
|
| 26 |
+
|
| 27 |
+
|
| 28 |
# Page configuration
|
| 29 |
st.set_page_config(
|
| 30 |
page_title="Kolam Design Analyzer",
|
|
|
|
| 369 |
with col1:
|
| 370 |
st.markdown("### π€ Upload Kolam Image")
|
| 371 |
|
| 372 |
+
#uploaded_file = st.file_uploader(
|
| 373 |
+
#"Choose a Kolam image...",
|
| 374 |
+
#type=["png", "jpg", "jpeg"],
|
| 375 |
+
#help="Upload a clear image of a Kolam design for analysis"
|
| 376 |
+
#)
|
| 377 |
uploaded_file = st.file_uploader(
|
| 378 |
"Choose a Kolam image...",
|
| 379 |
type=["png", "jpg", "jpeg"],
|
| 380 |
help="Upload a clear image of a Kolam design for analysis"
|
| 381 |
)
|
| 382 |
+
|
| 383 |
+
# Store in session state only if a new file is uploaded
|
| 384 |
+
if uploaded_file is not None:
|
| 385 |
+
st.session_state['uploaded_image'] = Image.open(uploaded_file)
|
| 386 |
+
|
| 387 |
+
# Display the uploaded image if available
|
| 388 |
+
if st.session_state['uploaded_image'] is not None:
|
| 389 |
+
st.image(st.session_state['uploaded_image'], caption="Uploaded Kolam", use_column_width=True)
|
| 390 |
+
|
| 391 |
|
| 392 |
if uploaded_file:
|
| 393 |
# Display uploaded image
|
|
|
|
| 395 |
st.image(image, caption="Uploaded Kolam", use_column_width=True)
|
| 396 |
|
| 397 |
# Analysis button
|
| 398 |
+
#if st.button("π Analyze Kolam Design", type="primary"):
|
| 399 |
+
#with st.spinner("Analyzing Kolam design..."):
|
| 400 |
+
# Process image
|
| 401 |
+
#original, thresh, edges = analyzer.preprocess_image(
|
| 402 |
+
#image, image_size, threshold_value, canny_low, canny_high
|
| 403 |
+
#)
|
| 404 |
+
|
| 405 |
+
# Detect nodes and edges
|
| 406 |
+
#nodes = analyzer.detect_nodes(edges, max_corners)
|
| 407 |
+
#graph_edges = analyzer.detect_edges(edges, nodes, min_line_length)
|
| 408 |
+
|
| 409 |
+
# Build graph
|
| 410 |
+
#G = analyzer.build_graph(nodes, graph_edges)
|
| 411 |
+
|
| 412 |
+
# Extract features
|
| 413 |
+
#features = analyzer.extract_graph_features(G)
|
| 414 |
+
|
| 415 |
+
# Store results in session state
|
| 416 |
+
#st.session_state.analysis_complete = True
|
| 417 |
+
#st.session_state.original_img = original
|
| 418 |
+
#st.session_state.thresh_img = thresh
|
| 419 |
+
#st.session_state.edges_img = edges
|
| 420 |
+
#st.session_state.nodes = nodes
|
| 421 |
+
#st.session_state.graph = G
|
| 422 |
+
#st.session_state.features = features
|
| 423 |
+
|
| 424 |
+
# Generate encryption key
|
| 425 |
+
#encryption_key = analyzer.generate_encryption_key()
|
| 426 |
+
#st.session_state.encryption_key = encryption_key
|
| 427 |
+
|
| 428 |
+
#st.success("β
Analysis completed successfully!")
|
| 429 |
+
if st.session_state['uploaded_image'] is not None:
|
| 430 |
if st.button("π Analyze Kolam Design", type="primary"):
|
| 431 |
with st.spinner("Analyzing Kolam design..."):
|
| 432 |
# Process image
|
| 433 |
original, thresh, edges = analyzer.preprocess_image(
|
| 434 |
+
st.session_state['uploaded_image'], image_size, threshold_value, canny_low, canny_high
|
| 435 |
)
|
| 436 |
+
|
| 437 |
# Detect nodes and edges
|
| 438 |
nodes = analyzer.detect_nodes(edges, max_corners)
|
| 439 |
graph_edges = analyzer.detect_edges(edges, nodes, min_line_length)
|
| 440 |
+
|
| 441 |
# Build graph
|
| 442 |
G = analyzer.build_graph(nodes, graph_edges)
|
| 443 |
+
|
| 444 |
# Extract features
|
| 445 |
features = analyzer.extract_graph_features(G)
|
| 446 |
+
|
| 447 |
+
# Save results in session state
|
| 448 |
st.session_state.analysis_complete = True
|
| 449 |
st.session_state.original_img = original
|
| 450 |
st.session_state.thresh_img = thresh
|
|
|
|
| 452 |
st.session_state.nodes = nodes
|
| 453 |
st.session_state.graph = G
|
| 454 |
st.session_state.features = features
|
| 455 |
+
|
| 456 |
# Generate encryption key
|
| 457 |
encryption_key = analyzer.generate_encryption_key()
|
| 458 |
st.session_state.encryption_key = encryption_key
|
| 459 |
+
|
| 460 |
st.success("β
Analysis completed successfully!")
|
| 461 |
|
| 462 |
+
|
| 463 |
with col2:
|
| 464 |
st.markdown("### π Analysis Results")
|
| 465 |
|