aniket47 commited on
Commit
848c0b1
·
0 Parent(s):
Files changed (5) hide show
  1. .gitignore +21 -0
  2. LICENSE.md +21 -0
  3. README.md +42 -0
  4. app.py +123 -0
  5. requirements.txt +4 -0
.gitignore ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.pyc
4
+
5
+ # Distribution / packaging
6
+ .Python
7
+ build/
8
+ dist/
9
+ *.egg-info/
10
+
11
+ # Installer logs
12
+ pip-log.txt
13
+ pip-delete-this-directory.txt
14
+
15
+ # Unit test / coverage reports
16
+ htmlcov/
17
+ .tox/
18
+ .nox/
19
+ .coverage
20
+ .coverage.*
21
+ .pytest_cache
LICENSE.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Aniket Kamble
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 📊 Psychometric Template Generator
2
+
3
+ Psychometric Template Generator is a data visualization tool built using Python, Streamlit, Pandas, Matplotlib, and Plotly. It allows users to upload a CSV file and create intutive data visualizations just by selecting the features from the data.
4
+
5
+ ## ✨ Features
6
+
7
+ - Upload CSV data: Allows users to upload CSV files containing the data for psychometric testing.
8
+ - Data preview: Displays a glimpse of the uploaded data using a Streamlit expander.
9
+ - Feature selection: Enables users to choose specific features (columns) for comparison in the charts.
10
+ - Feature validation: Ensures the selected features are numerical for visualization.
11
+ - Chart selection: Provides a dropdown menu for users to select the desired chart type (Line, Bar, Scatter, Pie, Histogram, Heatmap).
12
+ - Chart generation: Creates charts based on the chosen chart type and displays them on the Streamlit app.
13
+ - Line chart: Plots lines for each selected feature over the data index.
14
+ - Bar chart: Creates a bar chart to compare the values of selected features across the data index.
15
+ - Scatter plot: Generates a scatter plot to visualize the relationship between two selected features.
16
+ - Pie chart: Creates a pie chart to represent the distribution of data across the selected features.
17
+ - Histogram: Generates a histogram to show the frequency distribution of a single selected feature.
18
+ - Heatmap: Creates a heatmap to visualize the correlation between all selected features.
19
+
20
+ ## 🛠️ Technologies Used
21
+
22
+ - Python
23
+ - Streamlit
24
+ - Pands
25
+ - Matplotlib
26
+ - Plotly
27
+
28
+ ## 🚀 Installation
29
+
30
+ 1. Clone this repository to your local machine using:
31
+ - `git clone`
32
+ 2. Install the required Python packages using pip:
33
+ - `pip install -r requirements.txt`
34
+
35
+ ## 💡 Usage
36
+
37
+ 1. Run the app using:
38
+ - `streamlit run app.py`
39
+ 2. Upload the dataset.
40
+ 3. Select features from the data.
41
+ 4. Select the Visualization from the given visualization charts and plots.
42
+ 5. You're Done, You'll get the visualization from selected features.
app.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024 Aniket Kamble
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ import streamlit as st
5
+ import pandas as pd
6
+ import matplotlib.pyplot as plt
7
+ import plotly.express as px
8
+
9
+ # Config
10
+ # st.set_option("deprecation.showPyplotGlobalUse", False)
11
+
12
+ def main():
13
+ st.set_page_config(page_title="Psychometric Template Generator", layout="wide")
14
+ st.title("📊 Psychometric Template Generator")
15
+
16
+ # Sidebar for file upload and chart selection
17
+ with st.sidebar:
18
+ st.header("Upload Data")
19
+ uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
20
+
21
+ if uploaded_file:
22
+ df = pd.read_csv(uploaded_file)
23
+ display_data_preview(df)
24
+ selected_features = select_features(df)
25
+
26
+ if selected_features:
27
+ if validate_features(df, selected_features):
28
+ chart_type = select_chart_type()
29
+ display_chart(df, selected_features, chart_type)
30
+
31
+ def display_data_preview(df):
32
+ """Displays a preview of the uploaded data."""
33
+ with st.expander("Preview of the uploaded data", expanded=False):
34
+ st.write(df.head())
35
+
36
+ def select_features(df):
37
+ """Allows the user to select features for comparison."""
38
+ selected_features = st.multiselect("Select features for comparison", df.columns)
39
+ if not selected_features:
40
+ st.warning("Please select at least one feature for comparison.")
41
+ return selected_features
42
+
43
+ def validate_features(df, selected_features):
44
+ """Validates that selected features are numeric."""
45
+ if not all(df[feature].dtype in (int, float) for feature in selected_features):
46
+ st.error("Selected features must be numeric for visualization.")
47
+ return False
48
+ return True
49
+
50
+ def select_chart_type():
51
+ """Allows the user to select the type of chart."""
52
+ with st.sidebar:
53
+ st.header("Chart Selection")
54
+ return st.selectbox(
55
+ "Select the type of chart",
56
+ ["Line Chart", "Bar Chart", "Scatter Plot", "Pie Chart", "Histogram", "Heatmap"],
57
+ )
58
+
59
+ def display_chart(df, selected_features, chart_type):
60
+ """Displays the selected chart."""
61
+ st.subheader(f"{chart_type}")
62
+ if chart_type == "Line Chart":
63
+ generate_line_chart(df, selected_features)
64
+ elif chart_type == "Bar Chart":
65
+ generate_bar_chart(df, selected_features)
66
+ elif chart_type == "Scatter Plot":
67
+ generate_scatter_plot(df, selected_features)
68
+ elif chart_type == "Pie Chart":
69
+ generate_pie_chart(df, selected_features)
70
+ elif chart_type == "Histogram":
71
+ generate_histogram(df, selected_features[0])
72
+ elif chart_type == "Heatmap":
73
+ generate_heatmap(df, selected_features)
74
+
75
+ def generate_line_chart(df, selected_features):
76
+ fig, ax = plt.subplots(figsize=(15, 8))
77
+ for feature in selected_features:
78
+ ax.plot(df.index, df[feature], label=feature)
79
+
80
+ ax.set_xlabel("Index")
81
+ ax.set_ylabel("Values")
82
+ ax.set_title("Line Chart")
83
+ ax.legend()
84
+ st.pyplot(fig)
85
+
86
+ def generate_bar_chart(df, selected_features):
87
+ fig = px.bar(df, x=df.index, y=selected_features, barmode="group")
88
+ fig.update_layout(title="Bar Chart", xaxis_title="Index", yaxis_title="Values", height=600, width=1000)
89
+ st.plotly_chart(fig)
90
+
91
+ def generate_scatter_plot(df, selected_features):
92
+ fig = px.scatter(
93
+ df,
94
+ x=selected_features[0],
95
+ y=selected_features[1],
96
+ title="Scatter Plot",
97
+ labels={
98
+ selected_features[0]: selected_features[0],
99
+ selected_features[1]: selected_features[1],
100
+ },
101
+ height=600,
102
+ width=1000
103
+ )
104
+ st.plotly_chart(fig)
105
+
106
+ def generate_pie_chart(df, selected_features):
107
+ fig = px.pie(df, names=selected_features, title="Pie Chart", hole=0.3, height=600, width=1000)
108
+ st.plotly_chart(fig)
109
+
110
+ def generate_histogram(df, selected_feature):
111
+ fig, ax = plt.subplots(figsize=(15, 8))
112
+ ax.hist(df[selected_feature], bins=20, edgecolor="black")
113
+ ax.set_xlabel(selected_feature)
114
+ ax.set_ylabel("Frequency")
115
+ ax.set_title("Histogram")
116
+ st.pyplot(fig)
117
+
118
+ def generate_heatmap(df, selected_features):
119
+ fig = px.imshow(df[selected_features].corr(), title="Heatmap", height=600, width=1000)
120
+ st.plotly_chart(fig)
121
+
122
+ if __name__ == "__main__":
123
+ main()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit==1.35.0
2
+ pandas==2.2.2
3
+ matplotlib==3.8.4
4
+ plotly==5.20.0