rtik007 commited on
Commit
3d3fa38
·
verified ·
1 Parent(s): 51923bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -86,12 +86,12 @@ def get_scatter_plot(feature1, feature2):
86
  return "scatter_plot.png"
87
 
88
  def get_anomaly_samples():
89
- """Returns top, middle, and bottom 10 records based on anomaly score."""
90
  sorted_df = df.sort_values("Anomaly_Score", ascending=False)
91
- top_10 = sorted_df.head(10).to_dict(orient="records")
92
- middle_10 = sorted_df.iloc[len(sorted_df) // 2 - 5: len(sorted_df) // 2 + 5].to_dict(orient="records")
93
- bottom_10 = sorted_df.tail(10).to_dict(orient="records")
94
- return {"Top 10 Anomalies": top_10, "Middle 10 Records": middle_10, "Bottom 10 Scores": bottom_10}
95
 
96
  # Create Gradio interface
97
  with gr.Blocks() as demo:
@@ -119,10 +119,15 @@ with gr.Blocks() as demo:
119
  scatter_button.click(get_scatter_plot, inputs=[feature1_dropdown, feature2_dropdown], outputs=scatter_image)
120
 
121
  with gr.Tab("Anomaly Samples"):
122
- gr.Markdown("### View Anomaly Scores")
123
- anomaly_samples_button = gr.Button("Get Anomaly Samples")
124
- anomaly_samples_output = gr.JSON()
125
- anomaly_samples_button.click(get_anomaly_samples, outputs=anomaly_samples_output)
 
 
 
 
 
126
 
127
  # Launch the Gradio app
128
  demo.launch()
 
86
  return "scatter_plot.png"
87
 
88
  def get_anomaly_samples():
89
+ """Returns formatted top, middle, and bottom 10 records based on anomaly score."""
90
  sorted_df = df.sort_values("Anomaly_Score", ascending=False)
91
+ top_10 = sorted_df.head(10)
92
+ middle_10 = sorted_df.iloc[len(sorted_df) // 2 - 5: len(sorted_df) // 2 + 5]
93
+ bottom_10 = sorted_df.tail(10)
94
+ return top_10, middle_10, bottom_10
95
 
96
  # Create Gradio interface
97
  with gr.Blocks() as demo:
 
119
  scatter_button.click(get_scatter_plot, inputs=[feature1_dropdown, feature2_dropdown], outputs=scatter_image)
120
 
121
  with gr.Tab("Anomaly Samples"):
122
+ gr.Markdown("### Anomaly Samples")
123
+ anomaly_samples_button = gr.Button("Show Anomaly Samples")
124
+ top_table = gr.Dataframe(label="Top 10 Records")
125
+ middle_table = gr.Dataframe(label="Middle 10 Records")
126
+ bottom_table = gr.Dataframe(label="Bottom 10 Records")
127
+ anomaly_samples_button.click(
128
+ get_anomaly_samples,
129
+ outputs=[top_table, middle_table, bottom_table]
130
+ )
131
 
132
  # Launch the Gradio app
133
  demo.launch()