hussain786110 commited on
Commit
f695738
·
verified ·
1 Parent(s): bdc7380

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -70
app.py CHANGED
@@ -1,72 +1,27 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import plotly.express as px
4
- import matplotlib.pyplot as plt
5
- import seaborn as sns
6
-
7
- # Load your dataset here
8
- df = pd.read_csv('your_data.csv') # Replace with your actual dataset file
9
-
10
- # Streamlit Interface for Plotting Scatter Plot and Simple Chart
11
- def streamlit_interface():
12
- st.title("Interactive Data Visualization App")
13
-
14
- # Display dataframe
15
- st.write(df.head())
16
-
17
- # Plot interactive scatter plot with Plotly
18
- scatter_fig = px.scatter(df, x='column_x', y='column_y', color='category_column', title="Interactive Scatter Plot")
19
- st.plotly_chart(scatter_fig)
20
-
21
- # Input fields for custom plotting
22
- x_values = st.text_input("Enter X values (comma-separated)", "1,2,3,4,5")
23
- y_values = st.text_input("Enter Y values (comma-separated)", "2,4,6,8,10")
24
-
25
- # Button to plot custom chart
26
- if st.button("Plot Custom Chart"):
27
- plot_custom_chart(x_values, y_values)
28
-
29
- # Correlation Heatmap using Seaborn
30
- st.subheader("Correlation Heatmap")
31
- plot_correlation_heatmap(df)
32
-
33
- # Function to plot custom chart
34
- def plot_custom_chart(x_values, y_values):
35
- try:
36
- # Convert the X and Y values from string input to lists of integers
37
- x_vals = list(map(int, x_values.split(',')))
38
- y_vals = list(map(int, y_values.split(',')))
39
-
40
- # Ensure both X and Y values have the same length
41
- if len(x_vals) != len(y_vals):
42
- st.error("Error: X and Y values must have the same number of elements.")
43
- return
44
-
45
- # Plot using Matplotlib
46
- plt.figure(figsize=(8, 5))
47
- plt.plot(x_vals, y_vals, marker='o', color='b', label="Data Points")
48
- plt.title("Custom Data Visualization")
49
- plt.xlabel("X Values")
50
- plt.ylabel("Y Values")
51
- plt.grid(True)
52
- plt.legend()
53
-
54
- # Display the plot
55
- st.pyplot(plt)
56
-
57
- except ValueError:
58
- st.error("Error: Please make sure the values are valid integers.")
59
-
60
- # Function to plot correlation heatmap
61
- def plot_correlation_heatmap(df):
62
- corr = df.corr() # Calculate correlation matrix
63
- plt.figure(figsize=(10, 8))
64
- sns.heatmap(corr, annot=True, cmap='coolwarm', fmt='.2f')
65
- plt.title('Correlation Heatmap')
66
- st.pyplot(plt) # Display in Streamlit
67
-
68
- # Run the Streamlit interface
69
- if __name__ == "__main__":
70
- streamlit_interface()
71
 
72
 
 
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