gaurv007 commited on
Commit
96721b2
·
verified ·
1 Parent(s): f62934e

fix: web/app/api/analyze/route.ts

Browse files
Files changed (1) hide show
  1. web/app/api/analyze/route.ts +18 -2
web/app/api/analyze/route.ts CHANGED
@@ -58,7 +58,8 @@ export async function POST(req: NextRequest) {
58
  }
59
 
60
  // Step 1: Submit to Gradio Space
61
- const submitRes = await fetch(`${GRADIO_URL}/gradio_api/call/_analysis_and_index`, {
 
62
  method: "POST",
63
  headers: { "Content-Type": "application/json" },
64
  body: JSON.stringify({ data: [text] }),
@@ -80,7 +81,7 @@ export async function POST(req: NextRequest) {
80
 
81
  while (attempts < maxAttempts) {
82
  const resultRes = await fetch(
83
- `${GRADIO_URL}/gradio_api/call/_analysis_and_index/${event_id}`,
84
  { headers: { Accept: "text/event-stream" } }
85
  );
86
 
@@ -208,6 +209,21 @@ export async function POST(req: NextRequest) {
208
  .update({ analyses_this_month: scanCount + 1 })
209
  .eq("id", user.id);
210
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  return NextResponse.json({
212
  risk_score: riskScore,
213
  grade,
 
58
  }
59
 
60
  // Step 1: Submit to Gradio Space
61
+ // FIX v4.3: Use the explicit api_name="analyze" set in app.py scan_btn.click()
62
+ const submitRes = await fetch(`${GRADIO_URL}/gradio_api/call/analyze`, {
63
  method: "POST",
64
  headers: { "Content-Type": "application/json" },
65
  body: JSON.stringify({ data: [text] }),
 
81
 
82
  while (attempts < maxAttempts) {
83
  const resultRes = await fetch(
84
+ `${GRADIO_URL}/gradio_api/call/analyze/${event_id}`,
85
  { headers: { Accept: "text/event-stream" } }
86
  );
87
 
 
209
  .update({ analyses_this_month: scanCount + 1 })
210
  .eq("id", user.id);
211
 
212
+ // FIX v4.3: Save analysis to DB so it shows in history
213
+ await supabase.from("analyses").insert({
214
+ user_id: user.id,
215
+ total_clauses: totalClauses,
216
+ flagged_count: flaggedCount,
217
+ risk_score: riskScore,
218
+ grade,
219
+ clauses: results,
220
+ entities: analysisData.entities || [],
221
+ contradictions: analysisData.contradictions || [],
222
+ obligations: analysisData.obligations || [],
223
+ compliance: analysisData.compliance || {},
224
+ model: modelStatus.includes("loaded") ? "ml" : "regex",
225
+ }).then(() => {}).catch(() => {}); // fire-and-forget, don't block response
226
+
227
  return NextResponse.json({
228
  risk_score: riskScore,
229
  grade,