Your React frontend application has been successfully created in a separate workspace structure alongside your backend API.
DataExtractor-workspace/
├── backend/ # Your existing FastAPI API
│ ├── backend/
│ │ ├── main.py # ✅ Updated with CORS support
│ │ ├── extractor.py
│ │ └── model.py
│ ├── requirements.txt
│ └── ...
│
└── frontend/ # 🆕 New React TypeScript app
├── src/
│ ├── components/
│ │ ├── FileUpload.tsx # PDF upload component
│ │ └── DataTable.tsx # Data display component
│ ├── styles/
│ │ ├── FileUpload.css
│ │ └── DataTable.css
│ ├── App.tsx
│ ├── App.css
│ ├── index.css
│ └── main.tsx
├── package.json
├── index.html
├── vite.config.ts
├── tsconfig.json
└── README.md
- ✅ File Upload: Simple, user-friendly PDF file input
- ✅ Data Display: Beautiful table showing extracted invoice data
- ✅ Line Items: Table view for invoice line items
- ✅ Error Handling: User-friendly error messages
- ✅ Loading States: Visual feedback during processing
- ✅ Responsive Design: Works on desktop and tablets
- ✅ CORS Enabled: Frontend can now call the API
- ✅ Error Handling: Comprehensive error management
- ✅ Response Validation: Proper HTTP status codes
cd DataExtractor-workspace/backend
source myenv/bin/activate # or: myenv\Scripts\activate on Windows
python -m uvicorn backend.main:app --reload --port 8000Backend will run at: http://localhost:8000
cd DataExtractor-workspace/frontend
npm install # Already done, but in case of issues
npm run devFrontend will run at: http://localhost:5173
- Upload PDF: Click the file upload button and select a PDF invoice
- Processing: The frontend sends the PDF to your backend API
- Extraction: Backend extracts invoice data using OpenAI's LLM
- Display: Results are shown in an organized table format
Open your browser and go to: http://localhost:5173
- Accepts PDF files only
- Shows loading state during processing
- Validates file type
- Disabled state during upload
- Displays main invoice fields:
- Vendor Name
- Invoice Number
- Invoice Date
- Vendor Address
- Invoice Total (highlighted)
- Shows line items in a separate table with:
- Description
- Quantity
- Unit Price
- Line Total
- Clean, modern interface
- Professional color scheme
- Hover effects on table rows
- Responsive grid layout
- Smooth animations
The frontend calls your backend at:
- Endpoint:
http://localhost:8000/extract - Method: POST
- Content-Type: multipart/form-data
- Field Name: file
Expected response format matches your InvoiceData model.
- Vite: Ultra-fast build tool (instant HMR)
- TypeScript: Full type safety
- React 18: Latest stable version
- No external UI libraries: Pure CSS for simplicity
- Customize Styling: Edit files in
src/styles/to match your brand - Add Features: Error retry button, data export, etc.
- Production Build: Run
npm run buildto create optimized build - Deploy: Host the built files on any static hosting service
- Ensure backend is running on port 8000
- Check CORS is enabled (it is in the updated main.py)
- Check browser console for errors (F12)
npm install # Reinstall dependencies
npm run dev- Backend:
uvicorn backend.main:app --port 8001 - Frontend:
npm run dev -- --port 5174
- components/: Reusable React components
- styles/: Component-specific CSS
- App.tsx: Main application logic
- main.tsx: React entry point
- index.html: HTML template
- vite.config.ts: Build configuration
- package.json: Dependencies and scripts
# Create component file
src/components/NewComponent.tsx
# Create corresponding style file
src/styles/NewComponent.css
# Import in App.tsx
import NewComponent from './components/NewComponent'Edit App.tsx line where it calls /extract:
const response = await fetch("http://localhost:8000/extract", {
method: "POST",
body: formData,
});Enjoy your new Invoice Data Extractor application! 🚀