Skip to content

feat: Add bundled React webview CLI for local file visualization #2107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ganeshrvel
Copy link
Collaborator

Problem Statement

What we're trying to solve:

  • Python project generates local output files that need visual inspection
  • Users need a simple CLI command (load-webview) to instantly view these files in a web interface
  • Want to ship React frontend + Python backend as a single pip-installable package
  • Need both development mode (separate servers) and production mode (bundled React served by Python)

The Architecture:
pip install my-project

my-project generates local files

load-webview # Single CLI command

Launches: Python API server + React frontend

User opens browser → Views local files via web interface

How we're solving it:

  1. Bundled Distribution Strategy:
    - Development: React dev server (port 3000) + Python API (port 8000) running separately
    - Production: React app pre-built into static files, served by Python server
    - Single pip package contains both frontend bundle and Python backend
  2. CLI Workflow: # User installs package pip install my-project

User generates files with main project

my-project --input data.json --output results/

User views results in browser

load-webview --data-dir results/

→ Opens http://localhost:8000 with React app

  1. Build Pipeline:
    - scripts/build.py: Builds React app → js-bundle/ directory
    - scripts/dev.py: Runs both servers for development
    - Package includes pre-built React bundle for production
    - CLI automatically serves bundled frontend if available
  2. Technical Implementation:
    - Frontend: React + TypeScript for file visualization (tables, charts, etc.)
    - Backend: FastAPI with file reading APIs (/api/datasets, /api/files)
    - Development: Auto-reload on code changes, CORS configured
    - Production: Static file serving, SPA routing, single server

   Problem Statement

  What we're trying to solve:
  - Python project generates local output files that need visual inspection
  - Users need a simple CLI command (load-webview) to instantly view these files
   in a web interface
  - Want to ship React frontend + Python backend as a single pip-installable
  package
  - Need both development mode (separate servers) and production mode (bundled
  React served by Python)

  The Architecture:
  pip install my-project
  ↓
  my-project generates local files
  ↓
  load-webview  # Single CLI command
  ↓
  Launches: Python API server + React frontend
  ↓
  User opens browser → Views local files via web interface

  How we're solving it:

  1. Bundled Distribution Strategy:
    - Development: React dev server (port 3000) + Python API (port 8000) running
   separately
    - Production: React app pre-built into static files, served by Python server
    - Single pip package contains both frontend bundle and Python backend
  2. CLI Workflow:
  # User installs package
  pip install my-project

  # User generates files with main project
  my-project --input data.json --output results/

  # User views results in browser
  load-webview --data-dir results/
  # → Opens http://localhost:8000 with React app
  3. Build Pipeline:
    - scripts/build.py: Builds React app → js-bundle/ directory
    - scripts/dev.py: Runs both servers for development
    - Package includes pre-built React bundle for production
    - CLI automatically serves bundled frontend if available
  4. Technical Implementation:
    - Frontend: React + TypeScript for file visualization (tables, charts, etc.)
    - Backend: FastAPI with file reading APIs (/api/datasets, /api/files)
    - Development: Auto-reload on code changes, CORS configured
    - Production: Static file serving, SPA routing, single server
@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jul 14, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR introduces a new feature to add a web-based visualization interface for Ragas evaluation results through a bundled React webview CLI. The implementation allows users to view local evaluation files through a browser with a simple CLI command.

The changes introduce:

  • A Python FastAPI backend that serves both API endpoints and static files
  • A React frontend with TypeScript and TailwindCSS for visualization
  • Development mode with separate servers and hot-reload
  • Production mode where React is pre-built and served by Python

However, there are several critical issues that need addressing:

  1. The package.json specifies non-existent future versions of dependencies (React 19.1.0, TailwindCSS 4.0.0)
  2. The datasets.py service has hardcoded paths and ignores the data_dir parameter
  3. Bundle validation in bundle.py could be more robust

Confidence score: 2/5

  1. This PR will likely cause immediate dependency and runtime issues if merged
  2. The dependency versions and hardcoded paths make this PR unstable and potentially broken
  3. Files needing attention:
    • webview-poc/ragas-webview/package.json (invalid dependency versions)
    • webview-poc/ragas_webview_cli/services/datasets.py (hardcoded paths)
    • webview-poc/ragas_webview_cli/services/bundle.py (validation logic)

30 files reviewed, 19 comments
Edit PR Review Bot Settings | Greptile


export function ErrorMessage({ message, onRetry }: ErrorMessageProps) {
return (
<div className="flex items-center justify-center min-h-screen">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: min-h-screen forces full viewport height - might not be desirable in all contexts where this error could be used

.Python
build/
develop-eggs/
dist/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: dist/ appears multiple times in the file (line 56). Consider consolidating these entries to avoid confusion.


def get_environment() -> Environment:
"""Get current environment from env var."""
env_str = os.getenv("WEBVIEW_ENV", "PRODUCTION").upper()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: env var name should have prefix matching project (RAGAS_WEBVIEW_ENV instead of WEBVIEW_ENV)

Comment on lines +49 to +50
background-color: #f9fafb;
color: #111827;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: use CSS variables instead of hardcoded colors to maintain consistency with the theme system

import sys
import os
import time
import signal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: signal module is imported but never used

Comment on lines +14 to +16
current_file = Path(__file__)
project_root = current_file.parent.parent.parent
csv_file = project_root / "samples_data" / "evaluation_results.csv"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: path resolution from file is fragile and assumes fixed directory structure. This breaks if installed via pip. Use data_dir parameter instead

export default tseslint.config([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Add .jsx extension to file pattern for better compatibility

Comment on lines +127 to +129
- `GET /` - Serves React app (production) or API info (development)
- `GET /api/health` - Health check endpoint
- `GET /assets/*` - Static assets (CSS, JS, images)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: API endpoints section is incomplete. Missing dataset and file endpoints mentioned in the PR description.

)


def create_datasets_router(data_dir: Optional[str] = None) -> APIRouter:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: data_dir parameter is never used in the implementation. Either use it or remove it

return router


def mount_static_files(app, js_bundle_dir: Path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Missing type hint for 'app' parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant