Vivekkrishu commited on
Commit
97f014a
Β·
1 Parent(s): b6e85e1
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -16,9 +16,11 @@ def load_csv(file):
16
  return None, f"❌ CSV must contain {required_cols}"
17
 
18
  # Add Age Group
19
- df["Age Group"] = pd.cut(df["Age"],
20
- bins=[20, 25, 30, 35, 40],
21
- labels=["21-25", "26-30", "31-35", "36-40"])
 
 
22
  return df, "βœ… File loaded successfully!"
23
  except Exception as e:
24
  return None, f"❌ Error: {e}"
@@ -48,10 +50,11 @@ def salary_chart():
48
  plt.xticks(rotation=45)
49
  plt.grid(axis="y", linestyle="--", alpha=0.7)
50
  plt.tight_layout()
51
- buf = io.BytesIO()
52
- plt.savefig(buf, format="png")
53
- buf.seek(0)
54
- return buf
 
55
 
56
 
57
  def performance_chart():
@@ -65,10 +68,11 @@ def performance_chart():
65
  plt.xticks(rotation=45)
66
  plt.grid(True, linestyle="--", alpha=0.6)
67
  plt.tight_layout()
68
- buf = io.BytesIO()
69
- plt.savefig(buf, format="png")
70
- buf.seek(0)
71
- return buf
 
72
 
73
 
74
  def search_employee(query):
@@ -98,8 +102,9 @@ with gr.Blocks() as demo:
98
  salary_btn = gr.Button("πŸ’° Salary Chart")
99
  performance_btn = gr.Button("πŸ† Performance Chart")
100
 
101
- salary_plot = gr.Image(type="auto", label="Salary Chart")
102
- performance_plot = gr.Image(type="auto", label="Performance Chart")
 
103
 
104
  # Events
105
  file_input.change(load_csv, inputs=file_input, outputs=[data_table, status])
 
16
  return None, f"❌ CSV must contain {required_cols}"
17
 
18
  # Add Age Group
19
+ df["Age Group"] = pd.cut(
20
+ df["Age"],
21
+ bins=[20, 25, 30, 35, 40],
22
+ labels=["21-25", "26-30", "31-35", "36-40"]
23
+ )
24
  return df, "βœ… File loaded successfully!"
25
  except Exception as e:
26
  return None, f"❌ Error: {e}"
 
50
  plt.xticks(rotation=45)
51
  plt.grid(axis="y", linestyle="--", alpha=0.7)
52
  plt.tight_layout()
53
+
54
+ filepath = "salary_chart.png"
55
+ plt.savefig(filepath)
56
+ plt.close()
57
+ return filepath
58
 
59
 
60
  def performance_chart():
 
68
  plt.xticks(rotation=45)
69
  plt.grid(True, linestyle="--", alpha=0.6)
70
  plt.tight_layout()
71
+
72
+ filepath = "performance_chart.png"
73
+ plt.savefig(filepath)
74
+ plt.close()
75
+ return filepath
76
 
77
 
78
  def search_employee(query):
 
102
  salary_btn = gr.Button("πŸ’° Salary Chart")
103
  performance_btn = gr.Button("πŸ† Performance Chart")
104
 
105
+ # βœ… Fixed: use "filepath"
106
+ salary_plot = gr.Image(type="filepath", label="Salary Chart")
107
+ performance_plot = gr.Image(type="filepath", label="Performance Chart")
108
 
109
  # Events
110
  file_input.change(load_csv, inputs=file_input, outputs=[data_table, status])