Skip to content

agiani99/Workflow_Inspector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”„ Python Workflow Analyzer

A powerful Streamlit application that analyzes Python scripts and Jupyter notebooks to generate visual workflow diagrams. Perfect for understanding code structure, documenting workflows, and visualizing the relationships between functions, classes, and methods.

Python Workflow Analyzer Streamlit License

✨ Features

πŸ“€ Multiple Input Methods

  • File Upload: Support for .py, .ipynb, and .txt files
  • URL Fetching: Direct import from GitHub URLs (automatically converts to raw format)
  • Code Pasting: Direct code input with syntax highlighting

πŸ” Intelligent Code Analysis

  • Function Detection: Identifies all function definitions with parameters
  • Class Analysis: Maps classes and their methods
  • Import Tracking: Lists all imports and dependencies
  • Call Graph: Traces function call relationships
  • Notebook Support: Cell-by-cell analysis for Jupyter notebooks

πŸ“Š Visual Workflow Generation

Script Mode

  • Network Graph: Shows function/class relationships
  • Color-coded Elements:
    • πŸ”΄ Classes (Red)
    • πŸ”΅ Functions (Blue)
    • 🟠 Methods (Orange)
  • Smart Text Wrapping: Handles long function names
  • Interactive Layout: Spring-based positioning

Notebook Mode

  • Sequential Workflow: Cell-by-cell progression
  • Cell Type Recognition: Code vs. Markdown cells
  • Content Preview: Shows cell contents and metadata
  • Visual Arrows: Clear workflow direction

πŸš€ Export & Sharing

  • High-Quality Downloads: PNG/JPEG export at 300 DPI
  • Multiple Formats: Choose your preferred image format
  • Easy Sharing: Direct download links

πŸ› οΈ Installation

Prerequisites

python >= 3.7

Required Packages

pip install streamlit matplotlib networkx requests numpy

Quick Start

  1. Clone or download the workflow_analyzer.py file
  2. Install dependencies:
    pip install streamlit matplotlib networkx requests numpy
  3. Run the application:
    streamlit run workflow_analyzer.py
  4. Open your browser to http://localhost:8501

πŸ“– Usage Guide

Method 1: File Upload

  1. Select "Upload File" in the sidebar
  2. Choose your Python file (.py, .ipynb, or .txt)
  3. View the analysis and generated diagram
  4. Export as needed

Method 2: GitHub URL

  1. Select "Enter URL" in the sidebar
  2. Paste any GitHub file URL (e.g., https://raw.githubusercontent.com/Fraunhofer-ITMP/PySASC/refs/heads/main/SASC_v2.ipynb?token=GHSAT0AAAAAADCRFWKM6YJIQNT5JQ24VLVK2B23WDA)
  3. Click "Fetch from URL"
  4. The app automatically converts to raw format and analyzes

Method 3: Code Pasting

  1. Select "Paste Code" in the sidebar
  2. Paste your Python code directly
  3. Instant analysis and visualization

🎯 Use Cases

For Developers

  • Code Documentation: Generate visual documentation for complex projects
  • Code Review: Quickly understand code structure and dependencies
  • Refactoring: Identify tightly coupled components
  • Onboarding: Help new team members understand codebase structure

For Data Scientists

  • Notebook Analysis: Visualize Jupyter notebook workflows
  • Pipeline Documentation: Document data processing pipelines
  • Experiment Tracking: Understand analysis workflows

For Educators

  • Teaching Tool: Visualize code structure for students
  • Assignment Review: Quickly assess student code organization
  • Curriculum Planning: Show progression of coding concepts

πŸ”§ Technical Details

Supported File Types

  • Python Scripts (.py): Full AST analysis with function call mapping
  • Jupyter Notebooks (.ipynb): JSON parsing with cell-by-cell analysis
  • Text Files (.txt): Basic parsing with cell delimiter detection

Code Cleaning Features

  • Character Normalization: Fixes problematic Unicode characters
  • Quote Standardization: Converts smart quotes to standard quotes
  • Whitespace Handling: Normalizes various space characters
  • Error Recovery: Graceful handling of syntax errors

GitHub Integration

  • Automatic URL Conversion: github.com/.../blob/... β†’ raw.githubusercontent.com/...
  • Branch Support: Works with any branch or commit
  • Error Handling: Clear feedback for inaccessible repositories

🎨 Visualization Features

Color Scheme

  • Classes: Bright Red (#E74C3C) - Highly visible for main components
  • Functions: Blue (#3498DB) - Clear distinction from methods
  • Methods: Orange (#F39C12) - Easy identification of class methods

Smart Text Handling

  • Automatic Wrapping: Long function names split intelligently
  • Underscore Splitting: Respects Python naming conventions
  • Readable Font Size: Optimized for clarity

Layout Options

  • Spring Layout: Automatic positioning based on relationships
  • Scalable Design: Adapts to different numbers of elements
  • High DPI Output: Professional quality for presentations

🀝 Contributing

We welcome contributions! Here are some ways you can help:

Feature Requests

  • Additional file format support
  • New visualization types
  • Enhanced analysis capabilities
  • UI/UX improvements

Bug Reports

  • Use the GitHub issues tab
  • Include error messages and steps to reproduce
  • Attach problematic files (if possible)

Development

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“ Examples

Analyzing a Simple Script

def calculate_area(radius):
    return 3.14159 * radius ** 2

def calculate_volume(radius, height):
    base_area = calculate_area(radius)
    return base_area * height

class Circle:
    def __init__(self, radius):
        self.radius = radius
    
    def area(self):
        return calculate_area(self.radius)

Result: Network diagram showing function calls and class relationships

Analyzing a Jupyter Notebook

{
  "cells": [
    {
      "cell_type": "markdown",
      "source": ["# Data Analysis Workflow"]
    },
    {
      "cell_type": "code", 
      "source": ["import pandas as pd\ndf = pd.read_csv('data.csv')"]
    }
  ]
}

Result: Sequential workflow showing cell progression

πŸ” Troubleshooting

Common Issues

"Syntax error in Python code"

  • The file may contain special characters
  • Try copying code to a plain text editor first
  • Use the built-in character cleaning feature

"No cells found in notebook"

  • Ensure the file is a valid .ipynb format
  • Check that cells contain actual content
  • Try the "Paste Code" method as alternative

"Error fetching URL"

  • Verify the URL is accessible
  • For private repositories, download and upload the file instead
  • Check your internet connection

Performance Tips

  • Large files may take longer to analyze
  • Complex notebooks with many cells will generate larger diagrams
  • Use PNG format for better quality, JPEG for smaller file sizes

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Streamlit Team: For the amazing web app framework
  • NetworkX: For powerful graph visualization capabilities
  • Matplotlib: For high-quality plotting functionality
  • Python AST: For robust code parsing capabilities

πŸ“Š Project Stats

  • Languages: Python, Markdown
  • Dependencies: 4 main packages
  • File Size: ~25KB
  • Features: 15+ core features
  • Use Cases: 10+ identified scenarios

πŸš€ Ready to visualize your code?

Get Started Now | Report Issues | Request Features

Made with ❀️ for the Python community

About

Visualize Python script and notebook

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages