Skip to content

RedtRocks/google-gen-hack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏛## What it does

  • Upload a PDF or paste text; we extract text (PyPDF2 for PDFs) -## Folder guide
main.py                 # FastAPI app and endpoints (serves React SPA)
client/                 # React frontend (Vite, TypeScript)
  src/
    routes/
      LegalDocumentPage/  # Main legal document analysis page
requirements.txt        # Python dependencies
Dockerfile, app.yaml, cloudbuild.yaml
scripts/                # Helper scripts (frontend build helpers)
backup_frontend/        # Original Jinja2 templates (preserved for reference)

Notes

  • The UI is a custom React app designed specifically for legal document analysis
  • Chat history shows previous Q&A and can be cleared per session
  • PDF extraction uses PyPDF2's text; image-only PDFs won't be OCR'd
  • Build the frontend with npm run client:build whenever static assets need to be refreshedctured analysis: summary, key points, risks, recommendations, simple explanation
  • Ask follow-up questions grounded in the uploaded content, with confidence level and supporting snippets
  • Keep a local chat history per session (no DB required)

Tech stack

  • Backend: FastAPI, Uvicorn, requests
  • AI: Google Gemini (via HTTPS REST call)
  • Parsing: PyPDF2
  • Frontend: React/Vite app (TypeScript, custom legal document analysis UI)
  • Tooling: npm + Vite build pipeline, python-dotenv; Docker & GCP configs includedment Demystifier

AI app to turn dense legal docs into clear, actionable insights with follow‑up Q&A. Built with FastAPI and Google Gemini.

What it does

  • Upload a PDF or paste text; we extract text (PyPDF2 for PDFs)
  • Generate a structured analysis: summary, key points, risks, recommendations, simple explanation
  • Ask follow‑up questions grounded in the uploaded content, with confidence level and supporting snippets
  • Keep a local chat history per session (no DB required)

Tech stack

  • Backend: FastAPI, Uvicorn, requests
  • AI: Google Gemini (via HTTPS REST call)
  • Parsing: PyPDF2
  • Frontend: Makyo React/Vite app (TypeScript, Radix UI, TanStack Query)
  • Tooling: npm + Vite build pipeline, python-dotenv; Docker & GCP configs included

Run locally

Prereqs: Python 3.10+, Node.js 18+, a Gemini API key.

1) Get a Gemini API Key

Visit https://aistudio.google.com/app/apikey and create a free API key.

2) Set up environment variables

# Copy the example file
copy .env.example .env

Then edit .env and replace your-gemini-api-key-here with your actual API key.

OR set it directly in PowerShell:

$env:GEMINI_API_KEY="your-actual-api-key"

3) Install Python dependencies

pip install -r requirements.txt

4) Install frontend dependencies & build once (outputs to client/dist)

npm install --legacy-peer-deps
npm run client:build

Tip: for iterative UI work run npm run client in a second terminal (Vite dev server on http://localhost:8441). The FastAPI backend continues to run on http://localhost:8080.

  1. Set environment variables (Windows PowerShell)
$env:GEMINI_API_KEY="your-api-key"
# Optional Makyo settings
$env:MAKYO_API_TOKEN="changeme"
$env:MAKYO_OLLAMA_HOST="http://host.docker.internal:11434"  # or unset if not using Ollama
  1. Start the backend
python main.py

Open http://localhost:8080. FastAPI now serves the built React SPA.

Configuration

  • GEMINI_API_KEY (required): Google Generative Language API key
  • PORT (optional, default 8080)

Endpoints

  • GET / → React SPA entry point (Legal Document Demystifier UI)
  • GET /assets/* → Hashed static assets served from Vite build output
  • POST /analyze-document → file upload (PDF/TXT); returns JSON analysis + document_id
  • POST /analyze-text → raw text; returns JSON analysis + document_id
  • POST /ask-question → question + document_id or document_text; returns answer, relevant_sections, confidence_level
  • POST /save-chat → persist chat in memory for session
  • GET /chat-history → session chat history
  • POST /clear-chat-history → clear session chat
  • GET /health → health probe

How answers are structured

Responses from Gemini are coerced to strict JSON. If parsing fails, we return a graceful fallback with the raw snippet and guidance to retry.

Security & privacy

  • Documents and chats are stored in memory only (per process)
  • No external storage; clear chat endpoint included
  • Provide your own API key via environment variable

Deploy

Deploy to Azure (Recommended)

The easiest way to deploy this application to production is using Microsoft Azure App Service.

Quick Deploy:

# 1. Build frontend
npm run client:build

# 2. Login to Azure
az login

# 3. Deploy using automated script
.\deploy_azure.ps1 -ResourceGroup "legal-demystifier-rg" -AppName "your-unique-app-name"

Documentation:

Requirements:

  • Azure account (free tier available)
  • Azure CLI installed
  • Gemini API key

Deploy to Google Cloud Platform

  • Dockerfile now performs a multi-stage build (Node → Python) so the React assets are bundled automatically.
  • deploy.sh / deploy_windows.bat install Node deps, build the frontend, then call the existing GCP deployment flow.
  • cloudbuild.yaml deploys the same container; provide _GEMINI_API_KEY substitution or set GEMINI_API_KEY in the target environment.

Deploy with Docker

# Build the image
docker build -t legal-demystifier .

# Run the container
docker run -p 8080:8080 -e GEMINI_API_KEY="your-api-key" legal-demystifier

Folder guide

main.py                 # FastAPI app and endpoints (serves React SPA)
client/                 # Makyo React frontend (Vite, TypeScript)
server/                 # Makyo server code (available for future integration)
shared/                 # Shared TypeScript types used by the frontend/server
requirements.txt        # Python dependencies
Dockerfile, app.yaml, cloudbuild.yaml
scripts/                # Helper scripts (frontend build helpers)

Notes

  • The UI is now powered by Makyo’s modern React experience (dark theme, personas, snippets, etc.)
  • Chat history shows previous Q&A and can be cleared per session
  • PDF extraction uses PyPDF2’s text; image-only PDFs won’t be OCR’d
  • Build the frontend with npm run client:build whenever static assets need to be refreshed

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •