Sarathrsk03 commited on
Commit
72af0d0
·
1 Parent(s): 589c7cd

updated workflow

Browse files
Files changed (2) hide show
  1. .github/workflows/hf_sync.yml +1 -1
  2. README.md +112 -2
.github/workflows/hf_sync.yml CHANGED
@@ -17,4 +17,4 @@ jobs:
17
  env:
18
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
19
  run: |
20
- git push https://Sarathrsk03:$HF_TOKEN@huggingface.co/spaces/Sarathrsk03/Catapult-Splitter main
 
17
  env:
18
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
19
  run: |
20
+ git push --force https://Sarathrsk03:$HF_TOKEN@huggingface.co/spaces/Sarathrsk03/Catapult-Splitter main
README.md CHANGED
@@ -9,5 +9,115 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- # Catapult Splitter
13
- Split bills fairly based on consumption ratios.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  pinned: false
10
  ---
11
 
12
+ # 🧾 Catapult Receipt Splitter
13
+
14
+ Catapult Splitter is an AI-powered receipt splitting application that uses **LangGraph**, **Gemini 2.5 Flash**, and **Tesseract OCR** to help friends split bills fairly based on actual consumption ratios. Unlike simple equal-split apps, Catapult handles complex scenarios like unshared items, taxes, and service charges proportionally.
15
+
16
+ ## 🚀 Features
17
+
18
+ - **AI-Powered OCR**: Automatically extracts restaurant names, dates, items, and prices from receipt images.
19
+ - **Smart Pydantic Extraction**: Uses Gemini to structure messy OCR text into valid JSON.
20
+ - **Human-in-the-Loop**: Interrupts the workflow to allow users to verify extracted items and assign people.
21
+ - **Proportional Splitting**: Automatically distributes non-itemized costs (tax, tips, service charges) based on each person's consumption ratio.
22
+ - **Export to CSV/Table**: Provides a clear breakdown of who owes what and why.
23
+
24
+ ## 🏗️ Architecture
25
+
26
+ The application is built using a state-machine approach with **LangGraph**.
27
+
28
+ ### LangGraph Workflow
29
+
30
+ ```mermaid
31
+ graph TD
32
+ START((Start)) --> OCR[OCR Node]
33
+ OCR --> PYD[Pydantic Generator]
34
+ PYD -->|Interrupt: Review| REVIEW[Review Node]
35
+ REVIEW -->|Interrupt: Matching| CALC[Calculator Node]
36
+ CALC --> END((End))
37
+
38
+ subgraph "Nodes"
39
+ OCR -.- |pytesseract| OCR
40
+ PYD -.- |Google Gemini| PYD
41
+ CALC -.- |Proportional Logic| CALC
42
+ end
43
+ ```
44
+
45
+ ### Logical Data Flow
46
+
47
+ ```mermaid
48
+ sequenceDiagram
49
+ participant User
50
+ participant UI as Gradio Frontend
51
+ participant LG as LangGraph Workflow
52
+ participant LLM as Gemini 2.5 Flash
53
+
54
+ User->>UI: Upload Receipt
55
+ UI->>LG: Start Workflow
56
+ LG->>LG: Extract Raw Text (OCR)
57
+ LG->>LLM: Structure Text to JSON
58
+ LG-->>UI: Interrupt (Review Items)
59
+ User->>UI: Confirm/Edit Items
60
+ UI->>LG: Resume (Update State)
61
+ LG-->>UI: Interrupt (Match People)
62
+ User->>UI: Assign People to Items
63
+ UI->>LG: Resume (Calculate)
64
+ LG->>LG: Run Proportional Split
65
+ LG-->>User: Display Final Breakdown
66
+ ```
67
+
68
+ ## 🛠️ Tech Stack
69
+
70
+ - **Framework**: [LangGraph](https://github.com/langchain-ai/langgraph)
71
+ - **UI**: [Gradio](https://gradio.app/)
72
+ - **LLM**: Google Gemini 2.5 Flash
73
+ - **OCR**: Pytesseract (Tesseract OCR)
74
+ - **Data Handling**: Pandas & Pydantic
75
+ - **Environment**: Managed with `uv`
76
+
77
+ ## 📦 Installation & Local Setup
78
+
79
+ ### Prerequisites
80
+ - Python 3.13+
81
+ - Tesseract OCR installed on your system (`brew install tesseract` on Mac, `apt install tesseract-ocr` on Linux)
82
+ - A Google Gemini API Key
83
+
84
+ ### Setup
85
+ 1. **Clone the repository**:
86
+ ```bash
87
+ git clone <your-repo-url>
88
+ cd catapultSplit
89
+ ```
90
+
91
+ 2. **Install dependencies**:
92
+ Using `uv` (recommended):
93
+ ```bash
94
+ uv sync
95
+ ```
96
+
97
+ 3. **Configure Environment**:
98
+ Create a `.env` file:
99
+ ```env
100
+ GOOGLE_API_KEY=your_gemini_api_key_here
101
+ ```
102
+
103
+ 4. **Run the app**:
104
+ ```bash
105
+ python app.py
106
+ ```
107
+
108
+ ## 🚢 Deployment (Hugging Face Spaces)
109
+
110
+ This project is configured for automatic deployment via GitHub Actions.
111
+
112
+ 1. **GitHub Secret**: Add `HF_TOKEN` to your GitHub repository secrets.
113
+ 2. **Hugging Face Secret**: Add `GOOGLE_API_KEY` to your Space's variables.
114
+ 3. **Trigger**: Any push to the `main` branch will automatically sync to the Hugging Face Space.
115
+
116
+ ## 📝 How the Split Logic Works
117
+
118
+ The "Fair Split" is calculated in three steps:
119
+ 1. **Individual Raw Total**: Sum of items assigned to a person (shared items are divided equally among sharers).
120
+ 2. **Ratio**: `Person's Raw Total / Sum of All Items`.
121
+ 3. **Final Result**: `Ratio * Final Amount Paid (swipe amount)`.
122
+
123
+ This ensures that taxes, discounts, and tips are distributed according to how much value each person actually received.