Spaces:
Sleeping
Sleeping
jovian
commited on
Commit
·
19ca7c4
1
Parent(s):
372a23a
adding confidence chart
Browse files
app.py
CHANGED
|
@@ -243,6 +243,65 @@ def login_auth(username, password):
|
|
| 243 |
|
| 244 |
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
# Gradio interface components
|
| 247 |
with gr.Blocks() as demo:
|
| 248 |
|
|
@@ -448,8 +507,25 @@ with gr.Blocks() as demo:
|
|
| 448 |
inputs=output_annotations,
|
| 449 |
outputs=frequency_graph_component)
|
| 450 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
|
| 452 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
# Login row, initially visible
|
| 454 |
with gr.Row(visible=True) as login_row:
|
| 455 |
with gr.Column():
|
|
@@ -474,15 +550,26 @@ with gr.Blocks() as demo:
|
|
| 474 |
gr.update(visible=login_state), # Show area_graph_row
|
| 475 |
gr.update(visible=login_state), # Show area_btn_row
|
| 476 |
gr.update(visible=login_state), # Show frequency_graph_row
|
| 477 |
-
gr.update(visible=login_state),
|
|
|
|
|
|
|
| 478 |
gr.update(visible=not login_state) # for login
|
| 479 |
),
|
| 480 |
inputs=login_successful,
|
| 481 |
-
outputs=[header_row,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 482 |
)
|
| 483 |
|
| 484 |
with gr.Column(scale=2):
|
| 485 |
gr.Markdown("")
|
|
|
|
| 486 |
|
| 487 |
|
| 488 |
|
|
|
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
+
# Function to create individual bar charts for each defect type
|
| 247 |
+
def generate_confidence_bar_chart(annotations):
|
| 248 |
+
# Categorize confidence scores
|
| 249 |
+
confidence_bins = {'<25%': 0, '25%-75%': 0, '>75%': 0}
|
| 250 |
+
defect_bins = {
|
| 251 |
+
"Nicks": confidence_bins.copy(),
|
| 252 |
+
"Dents": confidence_bins.copy(),
|
| 253 |
+
"Scratches": confidence_bins.copy(),
|
| 254 |
+
"Pittings": confidence_bins.copy(),
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
# Populate bins based on annotations
|
| 258 |
+
for annotation in annotations:
|
| 259 |
+
defect = annotation["category_name"]
|
| 260 |
+
score = annotation["score"] * 100 # Convert to percentage
|
| 261 |
+
if score < 25:
|
| 262 |
+
defect_bins[defect]['<25%'] += 1
|
| 263 |
+
elif 25 <= score <= 75:
|
| 264 |
+
defect_bins[defect]['25%-75%'] += 1
|
| 265 |
+
else:
|
| 266 |
+
defect_bins[defect]['>75%'] += 1
|
| 267 |
+
|
| 268 |
+
# Define colors for each defect
|
| 269 |
+
category_styles = {
|
| 270 |
+
'Nicks': 'rgba(255, 60, 60, 0.7)', # Red
|
| 271 |
+
'Dents': 'rgba(255, 148, 156, 0.7)', # Light Red
|
| 272 |
+
'Scratches': 'rgba(255, 116, 28, 0.7)', # Orange
|
| 273 |
+
'Pittings': 'rgba(255, 180, 28, 0.7)' # Yellow
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
# Generate individual charts
|
| 277 |
+
charts = []
|
| 278 |
+
for defect, bins in defect_bins.items():
|
| 279 |
+
fig = go.Figure()
|
| 280 |
+
fig.add_trace(go.Bar(
|
| 281 |
+
name=defect,
|
| 282 |
+
x=list(bins.keys()), # Confidence ranges
|
| 283 |
+
y=list(bins.values()), # Counts
|
| 284 |
+
text=[f"{v} defects" for v in bins.values()], # Hover text
|
| 285 |
+
hoverinfo="text",
|
| 286 |
+
marker_color=category_styles.get(defect, 'rgba(255, 0, 0, 0.7)') # Default to red
|
| 287 |
+
))
|
| 288 |
+
|
| 289 |
+
# Customize layout
|
| 290 |
+
fig.update_layout(
|
| 291 |
+
title=f"{defect} Confidence Score Distribution",
|
| 292 |
+
xaxis_title="Confidence Range",
|
| 293 |
+
yaxis_title="Defect Count",
|
| 294 |
+
template="plotly_white"
|
| 295 |
+
)
|
| 296 |
+
charts.append(fig)
|
| 297 |
+
|
| 298 |
+
return charts # Return list of charts
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
|
| 305 |
# Gradio interface components
|
| 306 |
with gr.Blocks() as demo:
|
| 307 |
|
|
|
|
| 507 |
inputs=output_annotations,
|
| 508 |
outputs=frequency_graph_component)
|
| 509 |
|
| 510 |
+
|
| 511 |
+
|
| 512 |
+
# Gradio row for confidence bar chart
|
| 513 |
+
with gr.Row(visible=False) as confidence_bar_chart_row:
|
| 514 |
+
nicks_confidence_bar_chart = gr.Plot(label="Nicks Confidence Score Distribution")
|
| 515 |
+
dents_confidence_bar_chart = gr.Plot(label="Dents Confidence Score Distribution")
|
| 516 |
+
scratches_confidence_bar_chart = gr.Plot(label="Scratches Confidence Score Distribution")
|
| 517 |
+
pittings_confidence_bar_chart = gr.Plot(label="Pittings Confidence Score Distribution")
|
| 518 |
+
|
| 519 |
|
| 520 |
|
| 521 |
+
with gr.Row(visible=False) as confidence_btn_row:
|
| 522 |
+
confidence_chart_btn = gr.Button("Generate Confidence Chart", variant="primary")
|
| 523 |
+
confidence_chart_btn.click(
|
| 524 |
+
generate_confidence_bar_chart,
|
| 525 |
+
inputs=output_annotations, # Pass the annotations
|
| 526 |
+
outputs=[nicks_confidence_bar_chart,dents_confidence_bar_chart,scratches_confidence_bar_chart,pittings_confidence_bar_chart]
|
| 527 |
+
)
|
| 528 |
+
|
| 529 |
# Login row, initially visible
|
| 530 |
with gr.Row(visible=True) as login_row:
|
| 531 |
with gr.Column():
|
|
|
|
| 550 |
gr.update(visible=login_state), # Show area_graph_row
|
| 551 |
gr.update(visible=login_state), # Show area_btn_row
|
| 552 |
gr.update(visible=login_state), # Show frequency_graph_row
|
| 553 |
+
gr.update(visible=login_state), # Show frequency_btn_row
|
| 554 |
+
gr.update(visible=login_state), #Show Confidence chart
|
| 555 |
+
gr.update(visible=login_state), #Show Confidence btn
|
| 556 |
gr.update(visible=not login_state) # for login
|
| 557 |
),
|
| 558 |
inputs=login_successful,
|
| 559 |
+
outputs=[header_row,
|
| 560 |
+
input_row,
|
| 561 |
+
area_graph_row,
|
| 562 |
+
area_btn_row,
|
| 563 |
+
frequency_graph_row,
|
| 564 |
+
frequency_btn_row,
|
| 565 |
+
confidence_bar_chart_row,
|
| 566 |
+
confidence_btn_row,
|
| 567 |
+
login_row]
|
| 568 |
)
|
| 569 |
|
| 570 |
with gr.Column(scale=2):
|
| 571 |
gr.Markdown("")
|
| 572 |
+
|
| 573 |
|
| 574 |
|
| 575 |
|