Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,11 +74,16 @@ def server(input, output, session: Session):
|
|
| 74 |
|
| 75 |
# Run prediction with original BGR image
|
| 76 |
prediction = predictor(im)
|
|
|
|
| 77 |
|
| 78 |
results.append({
|
| 79 |
"filename": file["name"],
|
| 80 |
"image": img_base64,
|
| 81 |
-
**prediction
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
})
|
| 83 |
|
| 84 |
# Update reactive value
|
|
@@ -104,12 +109,19 @@ def server(input, output, session: Session):
|
|
| 104 |
ui.span(f"Viable = {r.get('viable', '?')}"),
|
| 105 |
ui.span(f"Nonviable = {r.get('nonviable', '?')}", style="margin: 0 15px;"),
|
| 106 |
ui.span(f"Empty = {r.get('empty', '?')}"),
|
|
|
|
| 107 |
class_="results-text"
|
| 108 |
),
|
| 109 |
class_="card p-3"
|
| 110 |
) for r in results]
|
| 111 |
)
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
@session.download()
|
| 114 |
def download():
|
| 115 |
results = analysis_results.get()
|
|
@@ -117,7 +129,8 @@ def server(input, output, session: Session):
|
|
| 117 |
"Filename": r["filename"],
|
| 118 |
"Viable": r.get("viable", ""),
|
| 119 |
"Nonviable": r.get("nonviable", ""),
|
| 120 |
-
"Empty": r.get("empty", "")
|
|
|
|
| 121 |
} for r in results])
|
| 122 |
|
| 123 |
# Create in-memory CSV file
|
|
|
|
| 74 |
|
| 75 |
# Run prediction with original BGR image
|
| 76 |
prediction = predictor(im)
|
| 77 |
+
classes = pred["instances"].pred_classes.tolist()
|
| 78 |
|
| 79 |
results.append({
|
| 80 |
"filename": file["name"],
|
| 81 |
"image": img_base64,
|
| 82 |
+
**prediction,
|
| 83 |
+
"viable": classes.count(1),
|
| 84 |
+
"non-viable": classes.count(2),
|
| 85 |
+
"empty": classes.count(3),
|
| 86 |
+
"total": len(classes)
|
| 87 |
})
|
| 88 |
|
| 89 |
# Update reactive value
|
|
|
|
| 109 |
ui.span(f"Viable = {r.get('viable', '?')}"),
|
| 110 |
ui.span(f"Nonviable = {r.get('nonviable', '?')}", style="margin: 0 15px;"),
|
| 111 |
ui.span(f"Empty = {r.get('empty', '?')}"),
|
| 112 |
+
ui.span(f"Total = {r.get('total', '?')}"),
|
| 113 |
class_="results-text"
|
| 114 |
),
|
| 115 |
class_="card p-3"
|
| 116 |
) for r in results]
|
| 117 |
)
|
| 118 |
|
| 119 |
+
# @render.plot
|
| 120 |
+
# def output_image():
|
| 121 |
+
# results.
|
| 122 |
+
|
| 123 |
+
# return fig
|
| 124 |
+
|
| 125 |
@session.download()
|
| 126 |
def download():
|
| 127 |
results = analysis_results.get()
|
|
|
|
| 129 |
"Filename": r["filename"],
|
| 130 |
"Viable": r.get("viable", ""),
|
| 131 |
"Nonviable": r.get("nonviable", ""),
|
| 132 |
+
"Empty": r.get("empty", ""),
|
| 133 |
+
"Total": r.get("total", "")
|
| 134 |
} for r in results])
|
| 135 |
|
| 136 |
# Create in-memory CSV file
|