bhaskar1225 commited on
Commit
2d4ad1a
·
verified ·
1 Parent(s): d82a6d1

Deploy VerifyDoc static demo (cockpit -> hosted API)

Browse files
Files changed (2) hide show
  1. README.md +37 -5
  2. index.html +165 -18
README.md CHANGED
@@ -1,10 +1,42 @@
1
  ---
2
- title: Verifydoc
3
- emoji: 👁
4
- colorFrom: indigo
5
  colorTo: blue
6
  sdk: static
7
- pinned: false
 
 
 
 
 
 
 
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: VerifyDoc
3
+ emoji: 🔒
4
+ colorFrom: green
5
  colorTo: blue
6
  sdk: static
7
+ app_file: index.html
8
+ pinned: true
9
+ license: apache-2.0
10
+ short_description: Which extracted document values should you trust?
11
+ tags:
12
+ - document-ai
13
+ - ocr
14
+ - information-extraction
15
+ - calibration
16
+ - hallucination-detection
17
  ---
18
 
19
+ # VerifyDoc the trust layer for document → JSON extraction
20
+
21
+ A **free static Space**: the VerifyDoc review cockpit, calling the hosted
22
+ VerifyDoc API. Paste a receipt or invoice, pick a schema, click **Verify** —
23
+ every field comes back with a **calibrated confidence**, a **source grounding**,
24
+ and an **accept / review** decision. Confident, grounded fields are
25
+ auto-accepted; the rest are highlighted for review.
26
+
27
+ - Local extraction runs on the hosted backend for free.
28
+ - The **Claude** model is **bring-your-own-key**: paste your Anthropic key; it is
29
+ used only for that request and never stored.
30
+
31
+ `index.html` is generated from the packaged review cockpit
32
+ (`verifydoc/server/review.html`) by `scripts/build_hf_static.py`, with its API
33
+ calls pointed at the hosted backend.
34
+
35
+ ## Links
36
+
37
+ - ⭐ **GitHub:** <https://github.com/bhaskargurram-ai/verifydoc>
38
+ - 📦 **PyPI:** `pip install verifydoc` — <https://pypi.org/project/verifydoc/>
39
+ - 📖 **Docs:** <https://bhaskargurram-ai.github.io/verifydoc/>
40
+
41
+ Private by default — self-host the whole app on your own infra:
42
+ `docker run -p 8000:8000 ghcr.io/bhaskargurram-ai/verifydoc`.
index.html CHANGED
@@ -1,19 +1,166 @@
 
1
  <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- GENERATED from verifydoc/server/review.html by scripts/build_hf_static.py — do not edit by hand. -->
2
  <!doctype html>
3
+ <html lang="en"><head><meta charset="utf-8">
4
+ <meta name="viewport" content="width=device-width, initial-scale=1">
5
+ <meta name="theme-color" content="#0e8a16">
6
+ <title>VerifyDoc review cockpit</title>
7
+ <style>
8
+ :root{--ok:#0e8a16;--rev:#d93f0b;--done:#1f6feb;--bg:#0d1117;--fg:#e6edf3;--card:#161b22;--mut:#8b949e;--line:#30363d}
9
+ *{box-sizing:border-box} body{margin:0;font:14px/1.5 system-ui,sans-serif;background:var(--bg);color:var(--fg)}
10
+ header{display:flex;align-items:center;gap:16px;padding:12px 18px;border-bottom:1px solid var(--line)}
11
+ header h1{margin:0;font-size:17px} .sum{color:var(--mut);font-size:13px}
12
+ header .grow{flex:1}
13
+ button{padding:8px 14px;background:var(--ok);color:#fff;border:0;border-radius:6px;font-weight:600;cursor:pointer}
14
+ button.ghost{background:#21262d;color:var(--fg);border:1px solid var(--line)}
15
+ .controls{display:flex;flex-wrap:wrap;gap:10px;padding:12px 18px;border-bottom:1px solid var(--line);align-items:end}
16
+ .controls label{display:block;font-size:12px;color:var(--mut);margin-bottom:3px}
17
+ input,textarea,select{background:var(--card);color:var(--fg);border:1px solid var(--line);border-radius:6px;padding:7px;font:inherit}
18
+ textarea{min-height:52px;width:320px} .controls .schema textarea{width:360px}
19
+ main{display:grid;grid-template-columns:minmax(360px,1fr) minmax(360px,1fr);gap:0;height:calc(100vh - 118px)}
20
+ .pane{overflow:auto;padding:14px} .pane.left{border-right:1px solid var(--line)}
21
+ h2{font-size:12px;text-transform:uppercase;letter-spacing:.05em;color:var(--mut);margin:0 0 10px}
22
+ .field{padding:9px 11px;margin:7px 0;background:var(--card);border-left:4px solid var(--mut);border-radius:6px;cursor:pointer}
23
+ .field.accept{border-left-color:var(--ok)} .field.review{border-left-color:var(--rev)} .field.done{border-left-color:var(--done)}
24
+ .field.sel{outline:2px solid var(--done)}
25
+ .field .top{display:flex;justify-content:space-between;align-items:center;gap:8px}
26
+ .field .path{font-weight:600} .field .badge{font-size:11px;color:var(--mut)}
27
+ .field input.val{width:100%;margin-top:6px}
28
+ .bar{height:4px;background:#21262d;border-radius:2px;margin-top:7px;overflow:hidden}
29
+ .bar>i{display:block;height:100%;background:var(--ok)}
30
+ .src{white-space:pre-wrap;font:13px/1.6 ui-monospace,monospace;background:var(--card);padding:12px;border-radius:6px}
31
+ mark{border-radius:3px;padding:0 1px;cursor:pointer} mark.accept{background:#1a4d2e;color:#c9f5d5}
32
+ mark.review{background:#5a2418;color:#ffd6cc} mark.done{background:#12385f;color:#cfe6ff} mark.flash{outline:2px solid var(--fg)}
33
+ .hint{color:var(--mut);font-size:12px;margin-top:8px} .err{color:var(--rev)}
34
+ </style></head><body>
35
+ <header>
36
+ <h1>🔒 VerifyDoc</h1>
37
+ <div class="sum" id="summary">▶ Click <b>Verify</b> to try the sample, or upload your own PDF. Local extraction is free; for the Claude model, paste your own key (never stored).</div>
38
+ <div class="grow"></div>
39
+ <button class="ghost" onclick="exportJSON()">Export JSON</button>
40
+ </header>
41
+ <div class="controls">
42
+ <div><label>Upload PDF/image</label><input type="file" id="file"></div>
43
+ <div><label>…or paste document text</label><textarea id="text" placeholder="paste a receipt/invoice">ACME Supplies Ltd
44
+ Invoice #: INV-2024-0912
45
+ Date: 2024-03-04
46
+ Subtotal: 1,100.00
47
+ Tax: 134.50
48
+ Total: $1,234.50</textarea></div>
49
+ <div class="schema"><label>Schema (JSON)</label><textarea id="schema">{"type":"object","properties":{"invoice_id":{"type":"string"},"vendor":{"type":"string","x-scoring":"semantic"},"date":{"type":"string"},"total":{"type":"number","x-numeric-tol":0.01}}}</textarea></div>
50
+ <div><label>Adapter</label><br><select id="adapter"><option>text-search</option><option>rapidocr</option><option>api-vlm</option><option>hf-vlm</option></select></div>
51
+ <div><label>Threshold</label><br><input id="threshold" type="number" value="0.8" step="0.05" min="0" max="1" style="width:80px"></div>
52
+ <div><label>Anthropic key (optional · for api-vlm)</label><br><input id="apikey" type="password" placeholder="sk-ant-… used only for this request" autocomplete="off" style="width:250px"></div>
53
+ <div><button onclick="run()">Verify</button></div>
54
+ </div>
55
+ <main>
56
+ <div class="pane left"><h2>Fields — ⚠️ review need a human (Tab to move · Enter to confirm)</h2><div id="fields"></div></div>
57
+ <div class="pane right"><h2>Source</h2><div id="source" class="src">—</div></div>
58
+ </main>
59
+ <script>
60
+ const API_BASE = "https://verifydoc-966512405851.us-central1.run.app";
61
+ let STATE = {fields: [], text: "", sel: -1};
62
+
63
+ function flatten(nested){
64
+ const out=[];
65
+ (function walk(o,p){for(const k in o){const v=o[k];const np=p?p+"."+k:k;
66
+ if(v&&typeof v==="object"&&"decision"in v)out.push(Object.assign({path:np},v));
67
+ else if(v&&typeof v==="object")walk(v,np);}})(nested,"");
68
+ return out;
69
+ }
70
+
71
+ async function run(){
72
+ const src=document.getElementById("source"); src.classList.remove("err"); src.textContent="Verifying…";
73
+ const schema=document.getElementById("schema").value;
74
+ const adapter=document.getElementById("adapter").value;
75
+ const threshold=parseFloat(document.getElementById("threshold").value);
76
+ const file=document.getElementById("file").files[0];
77
+ const text=document.getElementById("text").value;
78
+ const apikey=document.getElementById("apikey").value.trim();
79
+ try{
80
+ let res;
81
+ if(file){
82
+ const fd=new FormData(); fd.append("file",file); fd.append("schema",schema);
83
+ fd.append("adapter",adapter); fd.append("threshold",threshold);
84
+ if(apikey)fd.append("api_key",apikey);
85
+ res=await fetch(API_BASE+"/verify/upload",{method:"POST",body:fd});
86
+ }else{
87
+ res=await fetch(API_BASE+"/verify",{method:"POST",headers:{"Content-Type":"application/json"},
88
+ body:JSON.stringify({document:text,schema:JSON.parse(schema),adapter,threshold,api_key:apikey||null})});
89
+ }
90
+ if(!res.ok){src.classList.add("err");src.textContent=await res.text();return;}
91
+ const data=await res.json();
92
+ STATE={fields:flatten(data.fields),text:file?"":text,sel:-1};
93
+ render();
94
+ }catch(e){src.classList.add("err");src.textContent=String(e);}
95
+ }
96
+
97
+ function cls(f){return f.reviewed?"done":f.decision;}
98
+
99
+ function render(){
100
+ const F=STATE.fields;
101
+ const nAcc=F.filter(f=>f.decision==="accept").length, nRev=F.filter(f=>f.decision==="review").length;
102
+ const done=F.filter(f=>f.reviewed).length;
103
+ document.getElementById("summary").textContent=
104
+ `${F.length} fields · ${nAcc} auto-accepted · ${nRev} to review · ${done} confirmed · STP ${(F.length?100*nAcc/F.length:0).toFixed(0)}%`;
105
+ // left: field cards
106
+ const fd=document.getElementById("fields"); fd.innerHTML="";
107
+ F.forEach((f,i)=>{
108
+ const d=document.createElement("div"); d.className="field "+cls(f)+(i===STATE.sel?" sel":""); d.dataset.i=i;
109
+ const conf=(f.confidence*100).toFixed(0);
110
+ const where=f.grounding?(" · page "+f.grounding.page):" · not grounded";
111
+ d.innerHTML=`<div class="top"><span class="path">${f.path}</span>`+
112
+ `<span class="badge">${f.reviewed?"✔ confirmed":(f.decision==="accept"?"✅ accept":"⚠️ review")} · ${conf}%${where}</span></div>`+
113
+ `<div class="bar"><i style="width:${conf}%;background:${f.decision==="accept"?"var(--ok)":"var(--rev)"}"></i></div>`;
114
+ const inp=document.createElement("input"); inp.className="val"; inp.value=(f.value==null?"":f.value);
115
+ inp.addEventListener("input",e=>{f.value=e.target.value; f.edited=true;});
116
+ d.appendChild(inp);
117
+ d.addEventListener("click",()=>select(i));
118
+ fd.appendChild(d);
119
+ });
120
+ // right: source with highlights (text path only)
121
+ const src=document.getElementById("source");
122
+ if(STATE.text){
123
+ const spans=F.map((f,i)=>({i,s:f.grounding&&f.grounding.char_span?f.grounding.char_span[0]:-1,
124
+ e:f.grounding&&f.grounding.char_span?f.grounding.char_span[1]:-1,f}))
125
+ .filter(x=>x.s>=0&&x.e>x.s).sort((a,b)=>a.s-b.s);
126
+ let html="",cur=0;
127
+ for(const x of spans){ if(x.s<cur)continue;
128
+ html+=esc(STATE.text.slice(cur,x.s))+`<mark class="${cls(x.f)}" data-i="${x.i}" onclick="select(${x.i})">`+esc(STATE.text.slice(x.s,x.e))+"</mark>";
129
+ cur=x.e; }
130
+ html+=esc(STATE.text.slice(cur));
131
+ src.innerHTML=html||esc(STATE.text);
132
+ }else{
133
+ src.innerHTML=`<div class="hint">Uploaded file — per-field grounding shown on the left (page/bbox). Paste text to see inline source highlighting.</div>`;
134
+ }
135
+ }
136
+
137
+ function esc(s){return s.replace(/[&<>]/g,c=>({"&":"&amp;","<":"&lt;",">":"&gt;"}[c]));}
138
+
139
+ function select(i){
140
+ STATE.sel=i; render();
141
+ const mark=document.querySelector(`mark[data-i="${i}"]`);
142
+ if(mark){mark.classList.add("flash");mark.scrollIntoView({block:"center",behavior:"smooth"});setTimeout(()=>mark.classList.remove("flash"),900);}
143
+ const card=document.querySelector(`.field[data-i="${i}"]`);
144
+ if(card)card.scrollIntoView({block:"nearest"});
145
+ }
146
+
147
+ function reviewIndices(){return STATE.fields.map((f,i)=>i).filter(i=>STATE.fields[i].decision==="review");}
148
+
149
+ document.addEventListener("keydown",e=>{
150
+ if(e.target.tagName==="INPUT"||e.target.tagName==="TEXTAREA"){if(e.key!=="Enter")return;}
151
+ const revs=reviewIndices(); if(!revs.length)return;
152
+ if(e.key==="Tab"){e.preventDefault();
153
+ const pos=revs.indexOf(STATE.sel); const next=revs[(pos+(e.shiftKey?-1:1)+revs.length)%revs.length];
154
+ select(next);
155
+ }else if(e.key==="Enter"&&STATE.sel>=0){e.preventDefault();
156
+ STATE.fields[STATE.sel].reviewed=true; const revs2=reviewIndices().filter(i=>!STATE.fields[i].reviewed);
157
+ render(); if(revs2.length)select(revs2[0]);
158
+ }
159
+ });
160
+
161
+ function exportJSON(){
162
+ const obj={}; for(const f of STATE.fields) obj[f.path]={value:f.value,confidence:f.confidence,decision:f.reviewed?"confirmed":f.decision,edited:!!f.edited};
163
+ const blob=new Blob([JSON.stringify(obj,null,2)],{type:"application/json"});
164
+ const a=document.createElement("a"); a.href=URL.createObjectURL(blob); a.download="verified.json"; a.click();
165
+ }
166
+ </script></body></html>