Spaces:
Sleeping
Sleeping
Download app.py from Kedhareswer/DataVisl: direct link, hf CLI and curl.
- Browser
- Download file 8.13 kB
-
https://huggingface.co/spaces/Kedhareswer/DataVisl/resolve/main/app.py
- Command line
-
hf download hf://spaces/Kedhareswer/DataVisl/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Kedhareswer/DataVisl/resolve/main/app.py
8.13 kB
| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| import os | |
| from utils import load_example_data, display_dataset_info | |
| # Page configuration | |
| st.set_page_config( | |
| page_title="Data Science Toolkit", | |
| page_icon="π", | |
| layout="wide", | |
| initial_sidebar_state="expanded" | |
| ) | |
| # Application title and description | |
| st.title("π Interactive Data Science Toolkit") | |
| st.markdown(""" | |
| This comprehensive data science application serves as an interactive toolkit for end-to-end data operations. | |
| Upload your CSV file or use one of our example datasets to get started! | |
| **Key Features:** | |
| - **Data Exploration & Visualization**: Explore data with summary statistics and create insightful visualizations | |
| - **Statistical Analysis & Machine Learning**: Apply statistical tests and build ML models for classification and regression | |
| - **AI Integration**: Use Ollama for local AI assistance and OpenAI for advanced analysis (requires API key) | |
| - **Advanced Capabilities**: Interactive dashboards, time series analysis, NLP, data quality assessment | |
| - **Collaboration & Reporting**: Share projects, generate reports, and automate analysis workflows | |
| With 15 specialized modules covering the entire data science workflow, this toolkit empowers both beginners and experienced analysts. | |
| Navigate through the different pages using the sidebar to access all features. | |
| """) | |
| # Sidebar for data upload and selection | |
| st.sidebar.title("π Data Selection") | |
| # Session state initialization for dataset | |
| if 'df' not in st.session_state: | |
| st.session_state.df = None | |
| if 'dataset_name' not in st.session_state: | |
| st.session_state.dataset_name = None | |
| if 'uploaded_file' not in st.session_state: | |
| st.session_state.uploaded_file = None | |
| # File uploader for various data formats | |
| uploaded_file = st.sidebar.file_uploader("Upload a data file", | |
| type=['csv', 'xlsx', 'xls', 'json', 'parquet', 'tsv', 'txt']) | |
| # Examples datasets | |
| st.sidebar.markdown("### Or select an example dataset:") | |
| example_datasets = { | |
| "None": None, | |
| "Iris Flower Dataset": "iris", | |
| "Boston Housing Dataset": "boston", | |
| "Titanic Dataset": "titanic", | |
| "Wine Quality Dataset": "wine" | |
| } | |
| selected_example = st.sidebar.selectbox( | |
| "Choose an example:", | |
| list(example_datasets.keys()) | |
| ) | |
| # Handle dataset loading | |
| if uploaded_file is not None: | |
| try: | |
| # Get file extension and load appropriate file format | |
| file_extension = uploaded_file.name.split('.')[-1].lower() | |
| if file_extension == 'csv': | |
| st.session_state.df = pd.read_csv(uploaded_file) | |
| elif file_extension in ['xlsx', 'xls']: | |
| st.session_state.df = pd.read_excel(uploaded_file) | |
| elif file_extension == 'json': | |
| st.session_state.df = pd.read_json(uploaded_file) | |
| elif file_extension == 'parquet': | |
| st.session_state.df = pd.read_parquet(uploaded_file) | |
| elif file_extension in ['tsv', 'txt']: | |
| # For TSV or general delimited files, try to detect delimiter | |
| try: | |
| # First try with tab as delimiter | |
| st.session_state.df = pd.read_csv(uploaded_file, sep='\t') | |
| except: | |
| # If that fails, try to infer delimiter with Python's csv sniffer | |
| import csv | |
| dialect = csv.Sniffer().sniff(uploaded_file.getvalue().decode('utf-8')) | |
| uploaded_file.seek(0) # Reset file pointer to beginning | |
| st.session_state.df = pd.read_csv(uploaded_file, sep=dialect.delimiter) | |
| else: | |
| st.error(f"Unsupported file format: {file_extension}") | |
| st.session_state.df = None | |
| # Check for duplicate column names and rename them if necessary | |
| if st.session_state.df is not None: | |
| # Check if there are duplicate column names | |
| if len(st.session_state.df.columns) != len(set(st.session_state.df.columns)): | |
| # Find duplicate columns | |
| seen = set() | |
| dupes = [col for col in st.session_state.df.columns if col in seen or seen.add(col)] | |
| # Rename duplicates with a suffix | |
| for col in dupes: | |
| # Find all occurrences of the duplicate column | |
| cols = [c for c in st.session_state.df.columns if c == col] | |
| # Rename all but the first occurrence | |
| for i in range(1, len(cols)): | |
| idx = list(st.session_state.df.columns).index(cols[i]) | |
| new_cols = list(st.session_state.df.columns) | |
| new_cols[idx] = f"{col}_{i+1}" | |
| st.session_state.df.columns = new_cols | |
| st.warning(f"Found and renamed duplicate column names: {dupes}") | |
| # Set session state variables | |
| st.session_state.dataset_name = uploaded_file.name | |
| st.session_state.uploaded_file = uploaded_file | |
| except Exception as e: | |
| st.error(f"Error loading the file: {e}") | |
| elif selected_example != "None" and example_datasets[selected_example] is not None: | |
| st.session_state.df = load_example_data(example_datasets[selected_example]) | |
| st.session_state.dataset_name = selected_example | |
| st.session_state.uploaded_file = None | |
| # Display dataset preview if available | |
| if st.session_state.df is not None: | |
| st.header(f"Dataset: {st.session_state.dataset_name}") | |
| # Data overview | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.subheader("Data Preview") | |
| st.dataframe(st.session_state.df.head(10), use_container_width=True) | |
| with col2: | |
| # Display dataset info | |
| display_dataset_info(st.session_state.df) | |
| # Learning section | |
| st.subheader("π Learning Corner: Getting Started with Data Science") | |
| st.markdown(""" | |
| ### Understanding Your Data | |
| The first step in any data science project is understanding your data. Look at: | |
| - The number of rows and columns | |
| - Data types for each column | |
| - Missing values | |
| - Basic statistics like mean, median, and standard deviation | |
| ### Next Steps | |
| Use the navigation on the left sidebar to: | |
| 1. **Explore** your data in depth | |
| 2. **Visualize** your data with charts | |
| 3. **Analyze** with statistical methods | |
| 4. Try basic **Machine Learning** algorithms | |
| Each section contains educational content to help you understand the concepts behind the tools. | |
| """) | |
| else: | |
| # Display welcome message if no data is loaded | |
| st.info("π Please upload a data file (CSV, Excel, JSON, etc.) or select an example dataset from the sidebar to get started!") | |
| # Display information about what the user can do | |
| st.header("π Getting Started with Data Science") | |
| st.markdown(""" | |
| ### What can you do with this toolkit? | |
| This interactive app helps you learn and apply data science concepts: | |
| 1. **Upload your own data** or use example datasets | |
| 2. **Explore and understand** your data with summary statistics | |
| 3. **Visualize patterns** with various chart types | |
| 4. **Analyze relationships** between variables | |
| 5. **Apply machine learning** for prediction and clustering | |
| 6. **AI Assistant** for data insights and code generation using Ollama | |
| 7. **Advanced Analysis** with pivot tables, custom formulas, and data export | |
| 8. **Interactive Dashboards** to create and save custom visualization layouts | |
| 9. **Time Series Analysis** for temporal data patterns and forecasting | |
| 10. **Natural Language Processing** for text analysis and sentiment detection | |
| 11. **Data Quality Assessment** to identify and fix data issues | |
| 12. **Collaborative Features** to share and manage analysis projects | |
| 13. **Report Generation** to create professional reports from your analysis | |
| 14. **Enhanced AI Integration** for deeper insights and code automation | |
| 15. **AutoML** for automated model building, optimization, and deployment | |
| Each section includes educational explanations to help you learn while doing! | |
| """) | |