Spaces:
Sleeping
Sleeping
AdityaAdaki
commited on
Commit
·
96cbe01
1
Parent(s):
77ed7b0
Add complete application structure and error logging
Browse files- Dockerfile +22 -6
- main.py +5 -1
- templates/analysis.html +17 -87
Dockerfile
CHANGED
@@ -3,14 +3,30 @@
|
|
3 |
|
4 |
FROM python:3.9
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
RUN useradd -m -u 1000 user
|
7 |
USER user
|
8 |
-
ENV PATH="/home/user/.local/bin:$PATH"
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
|
|
14 |
|
15 |
-
|
16 |
-
CMD ["
|
|
|
3 |
|
4 |
FROM python:3.9
|
5 |
|
6 |
+
WORKDIR /app
|
7 |
+
|
8 |
+
# Install system dependencies
|
9 |
+
RUN apt-get update && apt-get install -y \
|
10 |
+
chromium \
|
11 |
+
chromium-driver \
|
12 |
+
libgl1-mesa-glx \
|
13 |
+
libglib2.0-0 \
|
14 |
+
&& rm -rf /var/lib/apt/lists/*
|
15 |
+
|
16 |
+
# Create a non-root user
|
17 |
RUN useradd -m -u 1000 user
|
18 |
USER user
|
|
|
19 |
|
20 |
+
# Install Python dependencies
|
21 |
+
COPY --chown=user requirements.txt requirements.txt
|
22 |
+
RUN pip install --user -r requirements.txt
|
23 |
+
|
24 |
+
# Copy application files
|
25 |
+
COPY --chown=user . .
|
26 |
|
27 |
+
# Set environment variables
|
28 |
+
ENV PATH="/home/user/.local/bin:${PATH}"
|
29 |
+
ENV PYTHONPATH="/home/user/.local/lib/python3.9/site-packages:${PYTHONPATH}"
|
30 |
|
31 |
+
# Run the application
|
32 |
+
CMD ["python", "main.py"]
|
main.py
CHANGED
@@ -14,6 +14,8 @@ import uuid
|
|
14 |
from werkzeug.utils import secure_filename
|
15 |
from PIL import Image, ImageDraw
|
16 |
|
|
|
|
|
17 |
app = Flask(__name__)
|
18 |
|
19 |
# Configure screenshot directory
|
@@ -262,6 +264,7 @@ def create_polygon_mask(image_size, points):
|
|
262 |
|
263 |
@app.route('/')
|
264 |
def index():
|
|
|
265 |
return render_template('index.html')
|
266 |
|
267 |
@app.route('/search_location', methods=['POST'])
|
@@ -398,6 +401,7 @@ def capture_screenshot():
|
|
398 |
|
399 |
@app.route('/analyze')
|
400 |
def analyze():
|
|
|
401 |
try:
|
402 |
image_path = request.args.get('image')
|
403 |
if not image_path:
|
@@ -439,7 +443,7 @@ def analyze():
|
|
439 |
masks=segmentation_results['masks'])
|
440 |
|
441 |
except Exception as e:
|
442 |
-
logging.error(f"Error
|
443 |
return f"Error processing image: {str(e)}", 500
|
444 |
|
445 |
@app.route('/upload', methods=['POST'])
|
|
|
14 |
from werkzeug.utils import secure_filename
|
15 |
from PIL import Image, ImageDraw
|
16 |
|
17 |
+
logging.basicConfig(level=logging.DEBUG)
|
18 |
+
|
19 |
app = Flask(__name__)
|
20 |
|
21 |
# Configure screenshot directory
|
|
|
264 |
|
265 |
@app.route('/')
|
266 |
def index():
|
267 |
+
logging.info("Index route accessed")
|
268 |
return render_template('index.html')
|
269 |
|
270 |
@app.route('/search_location', methods=['POST'])
|
|
|
401 |
|
402 |
@app.route('/analyze')
|
403 |
def analyze():
|
404 |
+
logging.info("Analyze route accessed")
|
405 |
try:
|
406 |
image_path = request.args.get('image')
|
407 |
if not image_path:
|
|
|
443 |
masks=segmentation_results['masks'])
|
444 |
|
445 |
except Exception as e:
|
446 |
+
logging.error(f"Error in analyze route: {str(e)}", exc_info=True)
|
447 |
return f"Error processing image: {str(e)}", 500
|
448 |
|
449 |
@app.route('/upload', methods=['POST'])
|
templates/analysis.html
CHANGED
@@ -1,95 +1,25 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
-
<title>
|
5 |
-
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
6 |
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
7 |
-
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
8 |
</head>
|
9 |
<body>
|
10 |
-
<
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
<div class="image-wrapper">
|
26 |
-
<img src="{{ image_path }}" alt="Original Image" class="analyzed-image">
|
27 |
-
</div>
|
28 |
-
</div>
|
29 |
-
<div class="col-md-6">
|
30 |
-
<h3 class="card-title">
|
31 |
-
<i class="fas fa-layer-group me-2"></i>Segmented Image
|
32 |
-
</h3>
|
33 |
-
<div class="image-wrapper">
|
34 |
-
<img src="{{ masks['segmented'] }}" alt="Segmented Image" class="analyzed-image">
|
35 |
-
</div>
|
36 |
-
</div>
|
37 |
-
</div>
|
38 |
-
</div>
|
39 |
-
</div>
|
40 |
-
</div>
|
41 |
-
|
42 |
-
<!-- Results Panel -->
|
43 |
-
<div class="col-lg-4">
|
44 |
-
<div class="card mb-4">
|
45 |
-
<div class="card-body">
|
46 |
-
<h3 class="card-title">
|
47 |
-
<i class="fas fa-chart-pie me-2"></i>Distribution Analysis
|
48 |
-
</h3>
|
49 |
-
<div class="results-list-wrapper">
|
50 |
-
<ul class="results-list">
|
51 |
-
{% for feature, percentage in results.items() %}
|
52 |
-
<li class="feature-item">
|
53 |
-
<div class="feature-header">
|
54 |
-
<span class="feature-name">{{ feature|title }}</span>
|
55 |
-
<span class="feature-percentage">{{ percentage }}%</span>
|
56 |
-
</div>
|
57 |
-
<div class="progress">
|
58 |
-
<div class="progress-bar feature-{{ feature }}"
|
59 |
-
style="width: {{ percentage }}%">
|
60 |
-
</div>
|
61 |
-
</div>
|
62 |
-
</li>
|
63 |
-
{% endfor %}
|
64 |
-
</ul>
|
65 |
-
</div>
|
66 |
-
</div>
|
67 |
-
</div>
|
68 |
-
</div>
|
69 |
-
</div>
|
70 |
-
|
71 |
-
<!-- Feature Masks -->
|
72 |
-
<div class="card">
|
73 |
-
<div class="card-body">
|
74 |
-
<h3 class="card-title mb-4">
|
75 |
-
<i class="fas fa-map-marked-alt me-2"></i>Feature Detection Masks
|
76 |
-
</h3>
|
77 |
-
<div class="masks-grid">
|
78 |
-
{% for feature, mask_path in masks.items() %}
|
79 |
-
{% if feature != 'segmented' %}
|
80 |
-
<div class="mask-item">
|
81 |
-
<h4 class="mask-title">{{ feature|title }}</h4>
|
82 |
-
<div class="mask-wrapper">
|
83 |
-
<img src="{{ mask_path }}" alt="{{ feature }} mask" class="mask-image">
|
84 |
-
</div>
|
85 |
-
</div>
|
86 |
-
{% endif %}
|
87 |
-
{% endfor %}
|
88 |
-
</div>
|
89 |
-
</div>
|
90 |
-
</div>
|
91 |
-
</div>
|
92 |
</div>
|
93 |
-
|
94 |
</body>
|
95 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
+
<title>Analysis Results</title>
|
|
|
|
|
|
|
5 |
</head>
|
6 |
<body>
|
7 |
+
<h1>Analysis Results</h1>
|
8 |
+
<img src="{{ image_path }}" alt="Original Image">
|
9 |
+
|
10 |
+
<h2>Segmentation Results:</h2>
|
11 |
+
<ul>
|
12 |
+
{% for feature, percentage in results.items() %}
|
13 |
+
<li>{{ feature }}: {{ percentage }}%</li>
|
14 |
+
{% endfor %}
|
15 |
+
</ul>
|
16 |
+
|
17 |
+
<h2>Segmentation Masks:</h2>
|
18 |
+
{% for feature, mask_path in masks.items() %}
|
19 |
+
<div>
|
20 |
+
<h3>{{ feature }}</h3>
|
21 |
+
<img src="{{ mask_path }}" alt="{{ feature }} mask">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
</div>
|
23 |
+
{% endfor %}
|
24 |
</body>
|
25 |
</html>
|