gaurv007 commited on
Commit
15e2d6a
·
verified ·
1 Parent(s): 9bd2e1c

v4.2: Update extension/background.js

Browse files
Files changed (1) hide show
  1. extension/background.js +12 -5
extension/background.js CHANGED
@@ -4,7 +4,8 @@
4
  * FIXED: Error handling and retry logic
5
  */
6
 
7
- const API_BASE = "https://gaurv007-clauseguard-api.hf.space";
 
8
  const FREE_SCANS_PER_MONTH = 10;
9
  const API_TIMEOUT_MS = 45000;
10
 
@@ -181,13 +182,19 @@ function localAnalyze(text) {
181
  });
182
 
183
  const flagged = results.filter(r => r.categories.length > 0);
184
- const sev = { HIGH: 0, MEDIUM: 0, LOW: 0 };
185
- flagged.forEach(r => r.categories.forEach(c => sev[c.severity]++));
186
- const risk = Math.min(100, Math.round((sev.HIGH*20 + sev.MEDIUM*10 + sev.LOW*5) / Math.max(1, clauses.length) * 100));
 
 
 
 
 
 
187
 
188
  return {
189
  risk_score: risk,
190
- grade: risk >= 60 ? "F" : risk >= 40 ? "D" : risk >= 20 ? "C" : risk >= 10 ? "B" : "A",
191
  total_clauses: clauses.length, flagged_count: flagged.length, results,
192
  };
193
  }
 
4
  * FIXED: Error handling and retry logic
5
  */
6
 
7
+ // FIX v4.2: Corrected API_BASE URL to match the actual Gradio Space
8
+ const API_BASE = "https://gaurv007-clauseguard.hf.space";
9
  const FREE_SCANS_PER_MONTH = 10;
10
  const API_TIMEOUT_MS = 45000;
11
 
 
182
  });
183
 
184
  const flagged = results.filter(r => r.categories.length > 0);
185
+ const sev = { CRITICAL: 0, HIGH: 0, MEDIUM: 0, LOW: 0 };
186
+ flagged.forEach(r => r.categories.forEach(c => {
187
+ if (sev.hasOwnProperty(c.severity)) sev[c.severity]++;
188
+ else sev.MEDIUM++; // default for unknown severity
189
+ }));
190
+ // FIX v4.2: Use the same diminishing-returns formula as the backend (app.py)
191
+ // instead of normalizing by clause count (which gave different scores)
192
+ const weighted = sev.CRITICAL*40 + sev.HIGH*20 + sev.MEDIUM*10 + sev.LOW*3;
193
+ const risk = Math.min(100, Math.round(100 * (1 - (1 / (1 + weighted / 30)))));
194
 
195
  return {
196
  risk_score: risk,
197
+ grade: risk >= 70 ? "F" : risk >= 50 ? "D" : risk >= 30 ? "C" : risk >= 15 ? "B" : "A",
198
  total_clauses: clauses.length, flagged_count: flagged.length, results,
199
  };
200
  }