Spaces:
Sleeping
Sleeping
alrichardbollans
commited on
Commit
·
18a5290
1
Parent(s):
ff1a4ee
Fix downloads without results
Browse files- app.py +17 -13
- styles.css +10 -32
app.py
CHANGED
|
@@ -58,7 +58,7 @@ app_ui = ui.page_fluid(
|
|
| 58 |
ui.input_slider("threshold", "Threshold", 0, 1.0, 0.8),
|
| 59 |
ui.input_action_button("analyze", "Analyze", class_="btn-success"),
|
| 60 |
# ui.input_switch("mask", "Mask", False),
|
| 61 |
-
ui.column(4, ui.download_button("download", "Download Results", class_="btn-
|
| 62 |
width=300
|
| 63 |
|
| 64 |
),
|
|
@@ -220,18 +220,22 @@ def server(input, output, session: Session):
|
|
| 220 |
@session.download()
|
| 221 |
def download():
|
| 222 |
results = analysis_results.get()
|
| 223 |
-
|
| 224 |
-
"
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
|
| 237 |
app = App(app_ui, server)
|
|
|
|
| 58 |
ui.input_slider("threshold", "Threshold", 0, 1.0, 0.8),
|
| 59 |
ui.input_action_button("analyze", "Analyze", class_="btn-success"),
|
| 60 |
# ui.input_switch("mask", "Mask", False),
|
| 61 |
+
ui.column(4, ui.download_button("download", "Download Results", class_="btn-success")),
|
| 62 |
width=300
|
| 63 |
|
| 64 |
),
|
|
|
|
| 220 |
@session.download()
|
| 221 |
def download():
|
| 222 |
results = analysis_results.get()
|
| 223 |
+
if not results:
|
| 224 |
+
return ui.div("No results yet. Upload images and click 'Analyze'.",
|
| 225 |
+
class_="text-muted")
|
| 226 |
+
else:
|
| 227 |
+
df = pd.DataFrame([{
|
| 228 |
+
"Filename": r["filename"],
|
| 229 |
+
"Viable": r.get("viable", ""),
|
| 230 |
+
"Non-Viable": r.get("non-viable", ""),
|
| 231 |
+
"Empty": r.get("empty", ""),
|
| 232 |
+
"Total": r.get("total", "")
|
| 233 |
+
} for r in results])
|
| 234 |
+
|
| 235 |
+
# Create in-memory CSV file
|
| 236 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as tmp:
|
| 237 |
+
df.to_csv(tmp.name, index=False)
|
| 238 |
+
return tmp.name
|
| 239 |
|
| 240 |
|
| 241 |
app = App(app_ui, server)
|
styles.css
CHANGED
|
@@ -2,10 +2,18 @@
|
|
| 2 |
/* Modern sleek theme with dark mode elements */
|
| 3 |
|
| 4 |
body {
|
| 5 |
-
background-color:
|
| 6 |
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
|
| 7 |
}
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
.container-fluid {
|
| 10 |
padding: 20px;
|
| 11 |
max-width: 1400px;
|
|
@@ -63,7 +71,6 @@ body {
|
|
| 63 |
|
| 64 |
.btn-file:hover {
|
| 65 |
background-color: #357abd;
|
| 66 |
-
transform: translateY(-1px);
|
| 67 |
}
|
| 68 |
|
| 69 |
/* Analyze button styling */
|
|
@@ -78,7 +85,6 @@ body {
|
|
| 78 |
|
| 79 |
.btn-success:hover {
|
| 80 |
background-color: #219653 !important;
|
| 81 |
-
transform: translateY(-1px);
|
| 82 |
}
|
| 83 |
|
| 84 |
/* Image cards styling */
|
|
@@ -92,19 +98,7 @@ body {
|
|
| 92 |
transition: transform 0.2s ease;
|
| 93 |
}
|
| 94 |
|
| 95 |
-
.card:hover {
|
| 96 |
-
transform: translateY(-3px);
|
| 97 |
-
}
|
| 98 |
|
| 99 |
-
/* Image display styling */
|
| 100 |
-
img {
|
| 101 |
-
border-radius: 10px;
|
| 102 |
-
object-fit: cover;
|
| 103 |
-
max-height: 300px;
|
| 104 |
-
width: 100%;
|
| 105 |
-
margin: 10px 0;
|
| 106 |
-
/*box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);*/
|
| 107 |
-
}
|
| 108 |
|
| 109 |
/* Results text styling */
|
| 110 |
.results-text {
|
|
@@ -118,22 +112,6 @@ img {
|
|
| 118 |
border-left: 4px solid #4a90e2;
|
| 119 |
}
|
| 120 |
|
| 121 |
-
/* Download button styling */
|
| 122 |
-
.btn-primary {
|
| 123 |
-
background-color: #2ecc71 !important;
|
| 124 |
-
right: 10px;
|
| 125 |
-
top: 10px;
|
| 126 |
-
border: none;
|
| 127 |
-
border-radius: 8px;
|
| 128 |
-
padding: 10px 25px;
|
| 129 |
-
font-weight: 600;
|
| 130 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
.btn-primary:hover {
|
| 134 |
-
background-color: #27ae60 !important;
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
/* Responsive design */
|
| 138 |
@media (max-width: 768px) {
|
| 139 |
.col-md-4 {
|
|
|
|
| 2 |
/* Modern sleek theme with dark mode elements */
|
| 3 |
|
| 4 |
body {
|
| 5 |
+
background-color: white;
|
| 6 |
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
|
| 7 |
}
|
| 8 |
+
/* Image display styling */
|
| 9 |
+
img {
|
| 10 |
+
border-radius: 10px;
|
| 11 |
+
object-fit: cover;
|
| 12 |
+
max-height: 300px;
|
| 13 |
+
width: 100%;
|
| 14 |
+
margin: 10px 0;
|
| 15 |
+
/*box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);*/
|
| 16 |
+
}
|
| 17 |
.container-fluid {
|
| 18 |
padding: 20px;
|
| 19 |
max-width: 1400px;
|
|
|
|
| 71 |
|
| 72 |
.btn-file:hover {
|
| 73 |
background-color: #357abd;
|
|
|
|
| 74 |
}
|
| 75 |
|
| 76 |
/* Analyze button styling */
|
|
|
|
| 85 |
|
| 86 |
.btn-success:hover {
|
| 87 |
background-color: #219653 !important;
|
|
|
|
| 88 |
}
|
| 89 |
|
| 90 |
/* Image cards styling */
|
|
|
|
| 98 |
transition: transform 0.2s ease;
|
| 99 |
}
|
| 100 |
|
|
|
|
|
|
|
|
|
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
/* Results text styling */
|
| 104 |
.results-text {
|
|
|
|
| 112 |
border-left: 4px solid #4a90e2;
|
| 113 |
}
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
/* Responsive design */
|
| 116 |
@media (max-width: 768px) {
|
| 117 |
.col-md-4 {
|