Spaces:
Sleeping
Add targeted claim regeneration from analysis feedback
Browse filesWhen claim analysis shows a non-perfect rating (e.g., Specificity: Medium),
an "Improve" button appears on that card. Clicking it sends the current
claims plus the analysis feedback to Gemini, which rewrites the claims
with specific focus on improving that dimension while preserving strengths
in other areas. Old analysis is cleared so the user can re-analyze.
- Extend ClaimRequest model with improvement_focus, previous_claims, and
analysis_feedback optional fields
- Update /api/generate-claim to use a targeted improvement prompt when
improvement_focus is provided (backwards compatible)
- Add Improve buttons to analysis cards (hidden when rating is already best)
- Add improveClaimDimension() JS function with loading states
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Files changed (2)
43 unmodified lines444546474849216 unmodified lines26626726826927027127227327427527643 unmodified linesclass ClaimRequest(BaseModel):invention_text: strprior_art: list[dict]class ClaimAnalysisRequest(BaseModel):claims: str216 unmodified linesf"- {p.get('patentNumber', 'N/A')}: \"{p.get('title', '')}\" ({p.get('assignee', '')}, {p.get('year', '')}): {p.get('abstract', '')}"for p in req.prior_art)system_prompt = """You are a senior USPTO patent attorney. Write a professional first-draft patent claim set.Format: 1 independent claim + 3 dependent claims. Use proper patent claim language (wherein, comprising, wherein said...).Number each claim. Be precise and technically accurate. Distinguish from the provided prior art."""user_msg = f"Invention: {req.invention_text}\n\nPrior Art to distinguish from:\n{prior_art_summary}\n\nDraft the claim set."claim_text = await call_gemini(system_prompt, user_msg)return {"claims": claim_text.strip()}43 unmodified lines444546474849505152216 unmodified lines26927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231343 unmodified linesclass ClaimRequest(BaseModel):invention_text: strprior_art: list[dict]improvement_focus: str | None = Noneprevious_claims: str | None = Noneanalysis_feedback: dict | None = Noneclass ClaimAnalysisRequest(BaseModel):claims: str216 unmodified linesf"- {p.get('patentNumber', 'N/A')}: \"{p.get('title', '')}\" ({p.get('assignee', '')}, {p.get('year', '')}): {p.get('abstract', '')}"for p in req.prior_art)if req.improvement_focus and req.previous_claims and req.analysis_feedback:dimension_labels = {"specificity": "specificity (how precise and well-defined the claim elements are)","protection": "protection scope (how broad the coverage is without being vulnerable to invalidation)","infringements": "infringement potential (how commercially relevant and broadly applicable the claims are)",}dim_label = dimension_labels.get(req.improvement_focus, req.improvement_focus)fb = req.analysis_feedbackbullets = "\n".join(f"- {b}" for b in fb.get("bullets", []))system_prompt = f"""You are a senior USPTO patent attorney. Rewrite the following patent claims to specifically improve their {dim_label}.The previous analysis rated this dimension as: {fb.get('rating', 'Unknown')}Assessment: {fb.get('summary', '')}Key issues identified:{bullets}IMPORTANT INSTRUCTIONS:- Rewrite ALL claims (independent and dependent) to address the identified weaknesses- Maintain proper patent claim language (wherein, comprising, wherein said...)- Keep the same structure: 1 independent claim + 3 dependent claims- Preserve the claims' strengths in other dimensions while improving {req.improvement_focus}- Number each claim. Be precise and technically accurate.- Distinguish from the provided prior art."""user_msg = (f"Previous Claims to Improve:\n{req.previous_claims}\n\n"f"Invention: {req.invention_text}\n\n"f"Prior Art to distinguish from:\n{prior_art_summary}\n\n"f"Rewrite the claims with improved {req.improvement_focus}.")else:system_prompt = """You are a senior USPTO patent attorney. Write a professional first-draft patent claim set.Format: 1 independent claim + 3 dependent claims. Use proper patent claim language (wherein, comprising, wherein said...).Number each claim. Be precise and technically accurate. Distinguish from the provided prior art."""user_msg = f"Invention: {req.invention_text}\n\nPrior Art to distinguish from:\n{prior_art_summary}\n\nDraft the claim set."claim_text = await call_gemini(system_prompt, user_msg)return {"claims": claim_text.strip()}
581 unmodified lines582583584585586587906 unmodified lines149414951496149714981499150015011502150315041 unmodified line150615071508150915101511151215131514151515161517581 unmodified lines.analysis-bullets li::before {content: '\2014'; position: absolute; left: 0; color: var(--muted);}</style></head><body>906 unmodified lines{ key: 'protection', icon: '\uD83D\uDEE1\uFE0F', title: 'Protection Scope' },{ key: 'infringements', icon: '\u26A0\uFE0F', title: 'Potential Infringements' }];grid.innerHTML = sections.map(s => {const section = data[s.key];if (!section) return '';const color = ratingColor(s.key, section.rating);const bullets = (section.bullets || []).map(b => `<li>${escapeHtml(b)}</li>`).join('');return `<div class="analysis-card"><div class="analysis-card-icon">${s.icon}</div>1 unmodified line<div class="analysis-rating ${color}">${escapeHtml(section.rating)}</div><div class="analysis-summary">${escapeHtml(section.summary)}</div><ul class="analysis-bullets">${bullets}</ul></div>`;}).join('');document.getElementById('claimAnalysisWrap').style.display = 'block';document.getElementById('analysisStatus').style.display = 'inline-flex';}// βββ RESTORE SESSION ON LOAD βββββββββββββββββββββββββββββββββββββββββββββββββfunction restoreSession() {loadState();581 unmodified lines582583584585586587588589590591592593594595596597906 unmodified lines1504150515061507150815091510151115121513151415151516151715181 unmodified line1520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583581 unmodified lines.analysis-bullets li::before {content: '\2014'; position: absolute; left: 0; color: var(--muted);}.analysis-improve-btn {margin-top: 16px; padding: 6px 14px; font-size: 11px; font-weight: 500;font-family: var(--sans); border-radius: 6px; cursor: pointer;background: transparent; color: var(--accent);border: 1px solid rgba(200,241,53,0.3);transition: all 0.15s;}.analysis-improve-btn:hover {background: var(--accent-dim); border-color: var(--accent);}</style></head><body>906 unmodified lines{ key: 'protection', icon: '\uD83D\uDEE1\uFE0F', title: 'Protection Scope' },{ key: 'infringements', icon: '\u26A0\uFE0F', title: 'Potential Infringements' }];const bestRating = { specificity: 'high', protection: 'broad', infringements: 'high' };grid.innerHTML = sections.map(s => {const section = data[s.key];if (!section) return '';const color = ratingColor(s.key, section.rating);const bullets = (section.bullets || []).map(b => `<li>${escapeHtml(b)}</li>`).join('');const isBest = (section.rating || '').toLowerCase() === bestRating[s.key];const improveBtn = isBest ? '' :`<button class="analysis-improve-btn" onclick="improveClaimDimension('${s.key}')">↻ Improve ${escapeHtml(s.title)}</button>`;return `<div class="analysis-card"><div class="analysis-card-icon">${s.icon}</div>1 unmodified line<div class="analysis-rating ${color}">${escapeHtml(section.rating)}</div><div class="analysis-summary">${escapeHtml(section.summary)}</div><ul class="analysis-bullets">${bullets}</ul>${improveBtn}</div>`;}).join('');document.getElementById('claimAnalysisWrap').style.display = 'block';document.getElementById('analysisStatus').style.display = 'inline-flex';}async function improveClaimDimension(dimension) {const claims = document.getElementById('claimContent').innerText.trim();if (!claims || !state.claimAnalysis || !state.claimAnalysis[dimension]) return;const feedback = state.claimAnalysis[dimension];// Show loading state β reuse claim loading spinnerdocument.getElementById('claimAnalysisWrap').style.display = 'none';document.getElementById('claimAnalysisLoading').style.display = 'none';document.getElementById('claimLoading').style.display = 'block';document.getElementById('claimOutputWrap').style.display = 'none';const approvedPatents = state.approvedArt.map(i => state.priorArt[i]);try {const response = await fetch(`${API_BASE}/api/generate-claim`, {method: "POST",headers: { "Content-Type": "application/json" },body: JSON.stringify({invention_text: state.ideaText,prior_art: approvedPatents,improvement_focus: dimension,previous_claims: claims,analysis_feedback: feedback})});if (!response.ok) {const err = await response.json().catch(() => ({}));throw new Error(err.detail || `Server error (HTTP ${response.status})`);}const data = await response.json();state.claimDraft = data.claims || '';} catch(err) {document.getElementById('claimLoading').style.display = 'none';const wrap = document.getElementById('claimOutputWrap');renderError(wrap, 'Claim improvement failed', err.message, () => improveClaimDimension(dimension));return;}// Clear old analysis so user re-analyzes the improved versionstate.claimAnalysis = null;document.getElementById('claimContent').innerText = state.claimDraft;document.getElementById('claimLoading').style.display = 'none';document.getElementById('claimOutputWrap').style.display = 'block';document.getElementById('claimAnalysisWrap').style.display = 'none';document.getElementById('analysisStatus').style.display = 'none';document.getElementById('analyzeClaimBtn').innerHTML = '⚖ Analyze Claims';saveState();document.getElementById('claimContent').scrollIntoView({ behavior: 'smooth' });}// βββ RESTORE SESSION ON LOAD βββββββββββββββββββββββββββββββββββββββββββββββββfunction restoreSession() {loadState();