Welcome to Data Visualization App’s documentation!
Introduction
This is the official documentation for Data Visualization App.
Installation
To install the application, run:
git clone https://github.com/your-repo/dataviz-m2-iasd.git
cd dataviz-m2-iasd
pip install -r requirements.txt
Usage
To run the application:
python app.py
Modules
This module implements a Flask web application for data visualization.
It provides functionalities for uploading data files, performing data quality checks, applying data fixes, generating plots, and interacting with a language model for graph interpretation. It supports both Gemini and Claude APIs.
- app.ALLOWED_MIME_TYPES = {'csv': ['text/csv', 'text/plain', 'application/csv', 'application/vnd.ms-excel'], 'feather': ['application/octet-stream', 'application/x-feather'], 'hdf5': ['application/x-hdf5', 'application/octet-stream'], 'html': ['text/html'], 'json': ['application/json', 'text/plain'], 'orc': ['application/octet-stream', 'application/x-orc'], 'parquet': ['application/octet-stream', 'application/x-parquet'], 'sql': ['application/sql', 'application/x-sql', 'application/vnd.sqlite3', 'text/plain'], 'tsv': ['text/tab-separated-values', 'text/plain'], 'txt': ['text/plain'], 'xls': ['application/vnd.ms-excel', 'application/octet-stream'], 'xlsx': ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'], 'xml': ['application/xml', 'text/xml']}
A dictionary mapping allowed file extensions to a list of their acceptable MIME types. This allows for flexibility in MIME type detection, as different systems and file contents might lead to variations in the detected MIME type.
- app.app = <Flask 'app'>
The Flask application instance.
- app.apply_fixes()[source]
Applies data fixes to an uploaded file.
This route receives the filename of an uploaded file via a POST request. It loads the data, applies fixes using apply_fixes_to_data, and saves the corrected data back to the file. It returns a JSON response indicating success or failure.
- Returns:
A JSON response with a success/failure message and status code.
- Return type:
flask.Response
- app.check_data()[source]
Performs data quality checks on an uploaded file.
This route receives the filename of an uploaded file via a POST request. It loads the data using load_data and performs data quality analysis using analyze_data. It returns a JSON response containing the analysis results.
- Returns:
A JSON response with the analysis results and status code.
- Return type:
flask.Response
- app.generate_plots()[source]
Generates plot suggestions based on the uploaded data.
This route receives the filename, selected model, and API key via a POST request. It loads the data and uses the specified model (“gemini” or “claude”) to generate plot suggestions. It returns a JSON response containing the suggestions.
- Returns:
A JSON response with plot suggestions and status code.
- Return type:
flask.Response
- app.get_interpretation()[source]
Generates interpretations for a given plot suggestion.
This route receives the selected model, API key, filename, and suggestion text via a POST request. It loads the data, creates a dataset summary, and uses the specified model (“gemini” or “claude”) to generate an interpretation of the suggested plot. It returns a JSON response containing the interpretation.
- Returns:
A JSON response with the plot interpretation and status code.
- Return type:
flask.Response
- app.graph_chat()[source]
Handles user interactions with a graph image.
This route receives the selected model, API key, user message, base64 encoded image, and filename via a POST request. It loads the data, creates a dataset summary, and uses the specified model (“gemini” or “claude”) to handle communication related to the graph image. It returns a JSON response containing the model’s response.
- Returns:
A JSON response with the model’s response and status code.
- Return type:
flask.Response
- app.load_data(filepath, filename)[source]
Loads data from a file into a pandas DataFrame.
This function supports various file formats including CSV, Excel, JSON, TSV, Parquet, Feather, ORC, XML, HTML, and HDF5. It handles potential errors like UnicodeDecodeError and provides informative logging.
- Parameters:
filepath (str) – The path to the file.
filename (str) – The name of the file.
- Returns:
The loaded DataFrame, or None if an error occurred.
- Return type:
pandas.DataFrame
- app.upload_file()[source]
Handles file uploads.
This route accepts a file upload via a POST request. It checks if a file was provided, validates its content using validate_file_content, and saves it to the UPLOAD_FOLDER. It returns a JSON response indicating success or failure.
- Returns:
A JSON response with a message and status code.
- Return type:
flask.Response
- app.uploaded_file(filename)[source]
Serves uploaded files.
This route allows direct access to uploaded files via their filenames.
- Parameters:
filename (str) – The name of the file to retrieve.
- Returns:
The requested file, served with the correct MIME type.
- Return type:
flask.Response
- app.validate_file_content(filepath)[source]
Validates the content of an uploaded file using libmagic.
This function checks if the detected MIME type of the file is among the allowed MIME types for its extension. It uses a dictionary of lists to account for variations in MIME type detection.
- Parameters:
filepath (str) – The path to the file.
- Returns:
True if the file content is valid, False otherwise.
- Return type:
bool