Skip to content

Latest commit

 

History

History
60 lines (52 loc) · 2.59 KB

File metadata and controls

60 lines (52 loc) · 2.59 KB

Python Flask Frontend for Code Analysis Agent

This directory contains the Python Flask frontend for the Code Analysis Agent.

Setup

  1. Install Python 3.12+

  2. Quick Start: Run startup.sh from the project root - it will:

    • Automatically create .env file from sample.env.txt (if it doesn't exist)
    • Set up virtual environment and install dependencies
    • Start the frontend service
  3. Manual Setup (if not using startup.sh):

    • Create a virtual environment and install dependencies:
    uv venv --python python3.12
    source .venv/bin/activate
    uv pip install -r requirements.txt
    # requirements.txt includes:
    # flask, requests, markdown, pygments, python-dotenv
    • Copy sample.env.txt to .env and customize if needed:
    cp sample.env.txt .env
  4. Environment Variables (configured in .env file):

    BACKEND_URL=http://localhost:8000  # Backend API URL (default: http://localhost:8000)
    PORT=5173                          # Port to run Flask app (default: 5173)
    DEBUG=False                         # Enable debug mode (default: False)
    • The application uses python-dotenv to automatically load variables from .env file
    • Logging is configured to output INFO level messages with timestamps

Usage

Run the Flask app:

python app.py

Visit http://localhost:5173 in your browser (or the port specified in your .env file).

Features

  • File Browser: Browse and select Python files from the data/src/ directory
  • Code Display: Selected code is displayed with syntax highlighting using Pygments
  • Code Analysis: Code is sent to the backend for analysis and narration
  • Narration Display: Narration is displayed with Markdown rendering
  • Audio Playback: Play the generated narration audio

Implementation Details

  • The frontend connects to the backend at http://localhost:8000 (configurable via BACKEND_URL environment variable)
  • Files are read from data/src/ directory (relative to project root)
  • Code syntax highlighting uses Pygments with the "monokai" style
  • Narration text is rendered as Markdown
  • Environment variables are loaded from .env file using python-dotenv
  • Structured logging is configured with timestamps and log levels (INFO, WARNING, ERROR)
  • Comprehensive error handling with user-friendly error messages displayed in the UI
  • All operations (file reading, API calls, errors) are logged for debugging and monitoring
  • Request timeouts are set for backend API calls (30s for analyze, 120s for narrate)
  • Error messages are displayed with clear, actionable feedback for users