manikantachary18 commited on
Commit
fd895d9
·
verified ·
1 Parent(s): 9030235

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -20
app.py CHANGED
@@ -11,14 +11,13 @@ def load_data(file):
11
  try:
12
  if file is None:
13
  return pd.DataFrame()
14
- ext = file.name.split('.')[-1].lower()
15
- file_bytes = file.read() # Use file.read() to get bytes
16
  if ext == 'csv':
17
- return pd.read_csv(io.BytesIO(file_bytes))
18
  elif ext in ['xls', 'xlsx']:
19
- return pd.read_excel(io.BytesIO(file_bytes))
20
  elif ext == 'json':
21
- return pd.read_json(io.BytesIO(file_bytes))
22
  except Exception as e:
23
  print("File load error:", e)
24
  return pd.DataFrame()
@@ -76,7 +75,8 @@ def update_plot(chart_type, x, y):
76
  print("Plot error:", e)
77
  return None
78
 
79
- # Gradio UI with animated background
 
80
  with gr.Blocks(css="""
81
  body {
82
  margin: 0;
@@ -96,7 +96,7 @@ body {
96
  background: linear-gradient(120deg, rgba(33,147,176,0.6), rgba(109,213,237,0.6));
97
  background-size: 200% 200%;
98
  animation: bgMove 20s ease infinite;
99
- filter: blur(100px);
100
  }
101
  @keyframes bgMove {
102
  0% { background-position: 0% 50%; }
@@ -112,27 +112,26 @@ body {
112
  }
113
  """) as demo:
114
 
115
- gr.HTML('<div id="bg-theme"></div>') # Animated background
116
 
117
  gr.Markdown("## 📊 Thunder BI-Data Visualizer", elem_classes="fade-in")
118
-
119
  with gr.Row():
120
- file_input = gr.File(file_types=[".csv", ".xlsx", ".json"], label="Upload File", elem_classes="fade-in")
121
- url_input = gr.Textbox(label="Or enter file URL", elem_classes="fade-in")
122
 
123
- load_button = gr.Button("Load", elem_classes="fade-in")
124
 
125
- df_preview = gr.Dataframe(label="Preview", interactive=False, elem_classes="fade-in")
126
- x_dropdown = gr.Dropdown(label="X-axis", elem_classes="fade-in")
127
- y_dropdown = gr.Dropdown(label="Y-axis", elem_classes="fade-in")
128
- chart_type = gr.Dropdown(["Bar Chart", "Line Chart", "Scatter Plot", "Pie Chart", "Box Plot"], label="Chart Type", elem_classes="fade-in")
129
- plot_area = gr.Plot(label="Chart", elem_classes="fade-in")
130
- generate_button = gr.Button("Generate Plot", elem_classes="fade-in")
131
 
132
  # Event hooks
133
  load_button.click(process_inputs, inputs=[file_input, url_input], outputs=[df_preview, x_dropdown, y_dropdown])
134
  generate_button.click(update_plot, inputs=[chart_type, x_dropdown, y_dropdown], outputs=plot_area)
135
 
136
  if __name__ == "__main__":
137
- demo.launch()
138
-
 
11
  try:
12
  if file is None:
13
  return pd.DataFrame()
14
+ ext = file.name.split('.')[-1]
 
15
  if ext == 'csv':
16
+ return pd.read_csv(file.name)
17
  elif ext in ['xls', 'xlsx']:
18
+ return pd.read_excel(file.name)
19
  elif ext == 'json':
20
+ return pd.read_json(file.name)
21
  except Exception as e:
22
  print("File load error:", e)
23
  return pd.DataFrame()
 
75
  print("Plot error:", e)
76
  return None
77
 
78
+
79
+ # Themed UI
80
  with gr.Blocks(css="""
81
  body {
82
  margin: 0;
 
96
  background: linear-gradient(120deg, rgba(33,147,176,0.6), rgba(109,213,237,0.6));
97
  background-size: 200% 200%;
98
  animation: bgMove 20s ease infinite;
99
+ filter: blur(100px);
100
  }
101
  @keyframes bgMove {
102
  0% { background-position: 0% 50%; }
 
112
  }
113
  """) as demo:
114
 
115
+ gr.HTML('<div id="bg-theme"></div>') # Themed animated background
116
 
117
  gr.Markdown("## 📊 Thunder BI-Data Visualizer", elem_classes="fade-in")
118
+
119
  with gr.Row():
120
+ file_input = gr.File(file_types=[".csv", ".xlsx", ".json"], label="Upload File")
121
+ url_input = gr.Textbox(label="Or enter file URL")
122
 
123
+ load_button = gr.Button("Load")
124
 
125
+ df_preview = gr.Dataframe(label="Preview", interactive=False)
126
+ x_dropdown = gr.Dropdown(label="X-axis")
127
+ y_dropdown = gr.Dropdown(label="Y-axis")
128
+ chart_type = gr.Dropdown(["Bar Chart", "Line Chart", "Scatter Plot", "Pie Chart", "Box Plot"], label="Chart Type")
129
+ plot_area = gr.Plot(label="Chart")
130
+ generate_button = gr.Button("Generate Plot")
131
 
132
  # Event hooks
133
  load_button.click(process_inputs, inputs=[file_input, url_input], outputs=[df_preview, x_dropdown, y_dropdown])
134
  generate_button.click(update_plot, inputs=[chart_type, x_dropdown, y_dropdown], outputs=plot_area)
135
 
136
  if __name__ == "__main__":
137
+ demo.launch()