hussain786110 commited on
Commit
2564989
·
verified ·
1 Parent(s): 400cf7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -19
app.py CHANGED
@@ -1,27 +1,56 @@
1
- def advanced_plot(df, chart_type):
 
 
 
 
 
 
2
  plt.figure(figsize=(8, 6))
3
-
4
- if chart_type == "Bar":
5
- sns.barplot(x='Category', y='Value', data=df)
6
- elif chart_type == "Line":
7
- sns.lineplot(x='Category', y='Value', data=df)
8
- elif chart_type == "Pie":
9
- df.set_index('Category')['Value'].plot.pie(autopct='%1.1f%%', figsize=(8, 6))
10
-
11
- plt.title(f'{chart_type} Chart')
 
 
 
12
  plt.xlabel('Category')
13
  plt.ylabel('Value')
 
 
 
 
 
 
 
 
14
  return plt
15
 
16
- def gradio_interface_advanced(file, chart_type):
17
- df = pd.read_csv(file.name)
18
- return advanced_plot(df, chart_type)
19
 
20
- interface = gr.Interface(fn=gradio_interface_advanced,
21
- inputs=[gr.File(label="Upload CSV"),
22
- gr.Dropdown(["Bar", "Line", "Pie"], label="Select Chart Type")],
23
- outputs=gr.Plot())
24
-
25
- interface.launch()
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
+
6
+ # Function to plot a bar chart
7
+ def plot_bar_chart(df):
8
  plt.figure(figsize=(8, 6))
9
+ sns.barplot(x='Category', y='Value', data=df)
10
+ plt.title('Category vs Value')
11
+ plt.xlabel('Category')
12
+ plt.ylabel('Value')
13
+ plt.tight_layout()
14
+ return plt
15
+
16
+ # Function to plot a line chart
17
+ def plot_line_chart(df):
18
+ plt.figure(figsize=(8, 6))
19
+ sns.lineplot(x='Category', y='Value', data=df)
20
+ plt.title('Category vs Value')
21
  plt.xlabel('Category')
22
  plt.ylabel('Value')
23
+ plt.tight_layout()
24
+ return plt
25
+
26
+ # Function to plot a pie chart
27
+ def plot_pie_chart(df):
28
+ plt.figure(figsize=(8, 6))
29
+ df.set_index('Category')['Value'].plot.pie(autopct='%1.1f%%', figsize=(8, 6))
30
+ plt.title('Category Distribution')
31
  return plt
32
 
33
+ # Streamlit interface
34
+ st.title('Advanced Data Visualization App')
 
35
 
36
+ # Upload CSV file
37
+ uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
 
 
 
 
38
 
39
+ if uploaded_file is not None:
40
+ # Load CSV into a pandas DataFrame
41
+ df = pd.read_csv(uploaded_file)
42
+
43
+ # Display the dataframe
44
+ st.write(df)
45
+
46
+ # Chart type selection
47
+ chart_type = st.selectbox('Select the chart type:', ['Bar Chart', 'Line Chart', 'Pie Chart'])
48
+
49
+ # Plot based on selected chart type
50
+ if chart_type == 'Bar Chart':
51
+ st.pyplot(plot_bar_chart(df))
52
+ elif chart_type == 'Line Chart':
53
+ st.pyplot(plot_line_chart(df))
54
+ elif chart_type == 'Pie Chart':
55
+ st.pyplot(plot_pie_chart(df))
56