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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify, send_file
|
2 |
+
import ollama
|
3 |
+
import json
|
4 |
+
import re
|
5 |
+
from duckduckgo_search import DDGS
|
6 |
+
import requests
|
7 |
+
from bs4 import BeautifulSoup
|
8 |
+
import fitz # PyMuPDF
|
9 |
+
import urllib3
|
10 |
+
import pandas as pd
|
11 |
+
import io
|
12 |
+
import ast
|
13 |
+
|
14 |
+
|
15 |
+
app = Flask(__name__)
|
16 |
+
|
17 |
+
search_prompt = """
|
18 |
+
The user will provide a detailed description of a technical problem they are trying to solve in the context of intellectual property (IP) and patents. Your task is to generate some (2 to 5) highly specific and relevant search queries for Google, aimed at finding research papers closely related to the user's problem. Each search query should:
|
19 |
+
|
20 |
+
1. Be crafted to find research papers, articles, or academic resources that address similar issues or solutions.
|
21 |
+
2. Be focused and precise, avoiding generic or overly broad terms.
|
22 |
+
|
23 |
+
Provide the search queries in the following **JSON format**. There should be no extra text, only the search queries as values.
|
24 |
+
|
25 |
+
**Example Output:**
|
26 |
+
|
27 |
+
```json
|
28 |
+
{
|
29 |
+
"1": "user authentication 5G cryptographic keys identity management",
|
30 |
+
"2": "5G authentication security issues cryptography 3GPP key management"
|
31 |
+
}
|
32 |
+
```
|
33 |
+
"""
|
34 |
+
|
35 |
+
infringement_prompt = """You are an expert assistant designed to evaluate the novelty and inventiveness of patents by comparing them with existing documents. Your task is to analyze the background of a given patent and the first page of a related document to determine how well the document covers the problems mentioned in the patent.
|
36 |
+
|
37 |
+
# Instructions:
|
38 |
+
|
39 |
+
Understand the Patent Background: Carefully read and comprehend the background information provided for the patent. Identify the key problems that the patent aims to address.
|
40 |
+
|
41 |
+
Analyze the Document: Review the provided document. Focus on identifying any problems that are similar to those mentioned in the patent background.
|
42 |
+
|
43 |
+
Evaluate Coverage: Assess how well the document covers the problems mentioned in the patent. Use the following scoring system:
|
44 |
+
|
45 |
+
Score 5: The document explicitly discusses the same problems as the patent, indicating that the problems are not novel.
|
46 |
+
Score 4: The document discusses problems that are very similar to those in the patent, significantly impacting the novelty of the patent's problems.
|
47 |
+
Score 3: The document mentions problems that are somewhat similar to those in the patent, but the coverage is not extensive enough to fully block the novelty of the patent's problems.
|
48 |
+
Score 2: The document mentions problems that are similar in some ways but are clearly different from those in the patent.
|
49 |
+
Score 1: The document touches upon related problems but does not directly address the specific problems mentioned in the patent.
|
50 |
+
Score 0: The document does not discuss any problems related to those in the patent.
|
51 |
+
Provide a Score: Based on your analysis, provide a score from 0 to 5 indicating how well the document covers the problems mentioned in the patent.
|
52 |
+
|
53 |
+
Justify Your Score: Briefly explain the reasoning behind your score, highlighting specific similarities or differences between the problems discussed in the patent and the document.
|
54 |
+
|
55 |
+
# Output Format:
|
56 |
+
No details or explanations are required, just the results in the required **JSON** format with no additional word.
|
57 |
+
|
58 |
+
{
|
59 |
+
'score': [Your Score],
|
60 |
+
'justification': "[Your Justification]"
|
61 |
+
}
|
62 |
+
"""
|
63 |
+
|
64 |
+
insight_prompt = """Analyze the technical document and extract key insights that could enhance the patent problem. Focus on identifying security vulnerabilities, technical problems, innovative technologies, research questions, and protocols mentioned in the document.
|
65 |
+
|
66 |
+
# Instructions:
|
67 |
+
1. Identify 3-5 key insights from the document that could enhance or inform the patent problem.
|
68 |
+
2. Each insight should be concise (max 10 words) but informative.
|
69 |
+
3. Focus on technical elements that could be valuable for improving the patent.
|
70 |
+
|
71 |
+
# Output Format:
|
72 |
+
Return only a JSON object with insights as an array, with no additional text:
|
73 |
+
|
74 |
+
{
|
75 |
+
"insights": [
|
76 |
+
"Security vulnerability in authentication handshake",
|
77 |
+
"Novel quantum encryption protocol",
|
78 |
+
"Lightweight implementation for IoT devices",
|
79 |
+
"Privacy-preserving key exchange mechanism",
|
80 |
+
"Real-time threat detection algorithm"
|
81 |
+
]
|
82 |
+
}
|
83 |
+
"""
|
84 |
+
|
85 |
+
refine_problem_prompt = """You are an expert consultant specializing in enhancing and refining technical problems to make them more sophisticated, novel, and inventive. Your task is to transform an initial technical problem description into two improved versions by integrating selected insights from technical documents.
|
86 |
+
|
87 |
+
# Instructions:
|
88 |
+
1. Carefully review the initial technical problem.
|
89 |
+
2. Consider the selected insights from technical documents that could enhance the problem formulation.
|
90 |
+
3. If any user comments are provided, incorporate those suggestions into your refinement process.
|
91 |
+
4. Generate TWO distinct refined problem statements that:
|
92 |
+
- Integrate the selected insights in a meaningful way
|
93 |
+
- Make the problem more sophisticated and technically interesting
|
94 |
+
- Increase the novelty and inventive potential of any solution
|
95 |
+
- Add appropriate constraints and technical requirements
|
96 |
+
- Maintain coherence and technical feasibility
|
97 |
+
- Suggest innovative directions without fully solving the problem
|
98 |
+
|
99 |
+
# Output Format:
|
100 |
+
Return the results in JSON format with no additional text:
|
101 |
+
|
102 |
+
{
|
103 |
+
"refined_problem_1": {
|
104 |
+
"title": "Brief descriptive title for the first refined problem",
|
105 |
+
"description": "Comprehensive description of the first refined problem that integrates insights and adds sophistication"
|
106 |
+
},
|
107 |
+
"refined_problem_2": {
|
108 |
+
"title": "Brief descriptive title for the second refined problem",
|
109 |
+
"description": "Alternative comprehensive description that takes a different approach to refining the problem"
|
110 |
+
}
|
111 |
+
}
|
112 |
+
"""
|
113 |
+
|
114 |
+
|
115 |
+
def ask_ollama(user_message, model='gemma3:1b', system_prompt=search_prompt):
|
116 |
+
response = ollama.chat(model=model, messages=[
|
117 |
+
{
|
118 |
+
"role": "system",
|
119 |
+
"content": system_prompt
|
120 |
+
},
|
121 |
+
{
|
122 |
+
"role": "user",
|
123 |
+
"content": user_message
|
124 |
+
}
|
125 |
+
])
|
126 |
+
ai_reply = response['message']['content']
|
127 |
+
print(f"AI REPLY json:\n{ai_reply}")
|
128 |
+
|
129 |
+
# Process the response to ensure we return valid JSON
|
130 |
+
try:
|
131 |
+
# First, try to parse it directly in case it's already valid JSON
|
132 |
+
print(f"AI REPLY:\n{ai_reply}")
|
133 |
+
return ast.literal_eval(ai_reply.replace('json\n', '').replace('```', ''))
|
134 |
+
except:
|
135 |
+
print(f"ERROR:\n{e}")
|
136 |
+
# If it's not valid JSON, try to extract JSON from the text
|
137 |
+
return {
|
138 |
+
"1": "Error parsing response. Please try again.",
|
139 |
+
"2": "Error parsing response. Please try again."
|
140 |
+
}
|
141 |
+
|
142 |
+
def search_web(topic, max_references=5, data_type="pdf"):
|
143 |
+
"""Search the web using DuckDuckGo and return results."""
|
144 |
+
doc_list = []
|
145 |
+
with DDGS(verify=False) as ddgs:
|
146 |
+
i = 0
|
147 |
+
for r in ddgs.text(topic, region='wt-wt', safesearch='On', timelimit='n'):
|
148 |
+
if i >= max_references:
|
149 |
+
break
|
150 |
+
doc_list.append({"type": data_type, "title": r['title'], "body": r['body'], "url": r['href']})
|
151 |
+
i += 1
|
152 |
+
return doc_list
|
153 |
+
|
154 |
+
def analyze_pdf_novelty(patent_background, url, data_type="pdf"):
|
155 |
+
"""Extract full document text from PDF or background from patent and evaluate novelty"""
|
156 |
+
try:
|
157 |
+
# Disable SSL warnings
|
158 |
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
159 |
+
# Extract text based on the type
|
160 |
+
if data_type == "pdf":
|
161 |
+
headers = {
|
162 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
163 |
+
"Accept": "application/pdf"
|
164 |
+
}
|
165 |
+
|
166 |
+
response = requests.get(url, headers=headers, timeout=20, verify=False)
|
167 |
+
if response.status_code != 200:
|
168 |
+
print(f"Failed to download PDF (status code: {response.status_code})")
|
169 |
+
return {"error": f"Failed to download PDF (status code: {response.status_code})"}
|
170 |
+
|
171 |
+
# Extract full document text (limited to 6000 characters)
|
172 |
+
try:
|
173 |
+
pdf_document = fitz.open(stream=response.content, filetype="pdf")
|
174 |
+
if pdf_document.page_count == 0:
|
175 |
+
return {"error": "PDF has no pages"}
|
176 |
+
|
177 |
+
text = ""
|
178 |
+
for page_num in range(min(5, pdf_document.page_count)): # Limit to first 5 pages
|
179 |
+
page = pdf_document.load_page(page_num)
|
180 |
+
text += page.get_text() + " "
|
181 |
+
if len(text) >= 6000:
|
182 |
+
break
|
183 |
+
|
184 |
+
text = text[:6000] # Limit to 6000 characters
|
185 |
+
except Exception as e:
|
186 |
+
return {"error": f"Error processing PDF: {str(e)}"}
|
187 |
+
|
188 |
+
elif data_type == "patent":
|
189 |
+
# Extract background from patent
|
190 |
+
print("extract from patent")
|
191 |
+
try:
|
192 |
+
response = requests.get(url, timeout=20, verify=False)
|
193 |
+
if response.status_code != 200:
|
194 |
+
print(f"Failed to access patent (status code: {response.status_code})")
|
195 |
+
return {"error": f"Failed to access patent (status code: {response.status_code})"}
|
196 |
+
content = response.content.decode('utf-8').replace("\n", "")
|
197 |
+
soup = BeautifulSoup(content, 'html.parser')
|
198 |
+
section = soup.find('section', itemprop='description', itemscope='')
|
199 |
+
matches = re.findall(r"background(.*?)(?:summary|description of the drawing)", str(section), re.DOTALL | re.IGNORECASE)
|
200 |
+
if matches:
|
201 |
+
text = BeautifulSoup(matches[0], "html.parser").get_text(separator=" ").strip()
|
202 |
+
else:
|
203 |
+
text = "Background section not found in patent."
|
204 |
+
except Exception as e:
|
205 |
+
return {"error": f"Error processing patent: {str(e)}"}
|
206 |
+
elif data_type == "web":
|
207 |
+
try:
|
208 |
+
headers = {
|
209 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
210 |
+
"Accept": "application/pdf"
|
211 |
+
}
|
212 |
+
response = requests.get(url, headers=headers, timeout=20, verify=False)
|
213 |
+
response.raise_for_status()
|
214 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
215 |
+
full_text = soup.get_text()
|
216 |
+
text = re.sub(r'\n+', ' ', full_text)[:5000]
|
217 |
+
except requests.RequestException as e:
|
218 |
+
return {"error": f"Error fetching the page: {str(e)}"}
|
219 |
+
else:
|
220 |
+
return {"error": "Unknown document type"}
|
221 |
+
|
222 |
+
# Analyze with Ollama for novelty assessment
|
223 |
+
result = ask_ollama(
|
224 |
+
user_message=f"Patent background:\n{patent_background}\n\nDocument content:\n{text}",
|
225 |
+
system_prompt=infringement_prompt
|
226 |
+
)
|
227 |
+
|
228 |
+
# # Extract insights
|
229 |
+
# insights = ask_ollama(
|
230 |
+
# user_message=f"Document content:\n{text}",
|
231 |
+
# system_prompt=insight_prompt
|
232 |
+
# )
|
233 |
+
|
234 |
+
# # Combine results
|
235 |
+
# result['insights'] = insights.get('insights', [])
|
236 |
+
|
237 |
+
return result
|
238 |
+
|
239 |
+
except Exception as e:
|
240 |
+
return {"error": f"Error: {str(e)}"}
|
241 |
+
|
242 |
+
|
243 |
+
def extract_insights(patent_background, url, data_type="pdf"):
|
244 |
+
"""Extract full document text from PDF or background from patent and evaluate novelty"""
|
245 |
+
try:
|
246 |
+
# Disable SSL warnings
|
247 |
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
248 |
+
# Extract text based on the type
|
249 |
+
if data_type == "pdf":
|
250 |
+
headers = {
|
251 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
252 |
+
"Accept": "application/pdf"
|
253 |
+
}
|
254 |
+
|
255 |
+
response = requests.get(url, headers=headers, timeout=20, verify=False)
|
256 |
+
if response.status_code != 200:
|
257 |
+
print(f"Failed to download PDF (status code: {response.status_code})")
|
258 |
+
return {"error": f"Failed to download PDF (status code: {response.status_code})"}
|
259 |
+
|
260 |
+
# Extract full document text (limited to 6000 characters)
|
261 |
+
try:
|
262 |
+
pdf_document = fitz.open(stream=response.content, filetype="pdf")
|
263 |
+
if pdf_document.page_count == 0:
|
264 |
+
return {"error": "PDF has no pages"}
|
265 |
+
|
266 |
+
text = ""
|
267 |
+
for page_num in range(min(5, pdf_document.page_count)): # Limit to first 5 pages
|
268 |
+
page = pdf_document.load_page(page_num)
|
269 |
+
text += page.get_text() + " "
|
270 |
+
if len(text) >= 6000:
|
271 |
+
break
|
272 |
+
|
273 |
+
text = text[:6000] # Limit to 6000 characters
|
274 |
+
except Exception as e:
|
275 |
+
return {"error": f"Error processing PDF: {str(e)}"}
|
276 |
+
|
277 |
+
elif data_type == "patent":
|
278 |
+
# Extract background from patent
|
279 |
+
print("extract from patent")
|
280 |
+
try:
|
281 |
+
response = requests.get(url, timeout=20, verify=False)
|
282 |
+
if response.status_code != 200:
|
283 |
+
print(f"Failed to access patent (status code: {response.status_code})")
|
284 |
+
return {"error": f"Failed to access patent (status code: {response.status_code})"}
|
285 |
+
content = response.content.decode('utf-8').replace("\n", "")
|
286 |
+
soup = BeautifulSoup(content, 'html.parser')
|
287 |
+
section = soup.find('section', itemprop='description', itemscope='')
|
288 |
+
matches = re.findall(r"background(.*?)(?:summary|description of the drawing)", str(section), re.DOTALL | re.IGNORECASE)
|
289 |
+
if matches:
|
290 |
+
text = BeautifulSoup(matches[0], "html.parser").get_text(separator=" ").strip()
|
291 |
+
else:
|
292 |
+
text = "Background section not found in patent."
|
293 |
+
except Exception as e:
|
294 |
+
return {"error": f"Error processing patent: {str(e)}"}
|
295 |
+
elif data_type == "web":
|
296 |
+
try:
|
297 |
+
headers = {
|
298 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
299 |
+
"Accept": "application/pdf"
|
300 |
+
}
|
301 |
+
response = requests.get(url, headers=headers, timeout=20, verify=False)
|
302 |
+
response.raise_for_status()
|
303 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
304 |
+
full_text = soup.get_text()
|
305 |
+
text = re.sub(r'\n+', ' ', full_text)[:5000]
|
306 |
+
except requests.RequestException as e:
|
307 |
+
return {"error": f"Error fetching the page: {str(e)}"}
|
308 |
+
else:
|
309 |
+
return {"error": "Unknown document type"}
|
310 |
+
|
311 |
+
# Extract insights
|
312 |
+
insights = ask_ollama(
|
313 |
+
user_message=f"Document content:\n{text}",
|
314 |
+
system_prompt=insight_prompt
|
315 |
+
)
|
316 |
+
|
317 |
+
return insights
|
318 |
+
|
319 |
+
except Exception as e:
|
320 |
+
return {"error": f"Error: {str(e)}"}
|
321 |
+
|
322 |
+
@app.route('/')
|
323 |
+
def home():
|
324 |
+
return render_template('index.html')
|
325 |
+
|
326 |
+
@app.route('/chat', methods=['POST'])
|
327 |
+
def chat():
|
328 |
+
user_message = request.form.get('message')
|
329 |
+
ai_reply = ask_ollama(user_message)
|
330 |
+
return jsonify({'reply': ai_reply})
|
331 |
+
|
332 |
+
@app.route('/search', methods=['POST'])
|
333 |
+
def search():
|
334 |
+
query = request.form.get('query')
|
335 |
+
pdf_checked = request.form.get('pdfOption') == 'true'
|
336 |
+
patent_checked = request.form.get('patentOption') == 'true'
|
337 |
+
web_checked = request.form.get('webOption') == 'true' or request.form.get('webOption') == 'on'
|
338 |
+
|
339 |
+
if not query:
|
340 |
+
return jsonify({'error': 'No query provided', 'results': []})
|
341 |
+
|
342 |
+
all_results = []
|
343 |
+
|
344 |
+
try:
|
345 |
+
# Handle various combinations
|
346 |
+
if pdf_checked:
|
347 |
+
pdf_query = f"{query} filetype:pdf"
|
348 |
+
pdf_results = search_web(pdf_query, max_references=5, data_type="pdf")
|
349 |
+
all_results.extend(pdf_results)
|
350 |
+
|
351 |
+
if patent_checked:
|
352 |
+
patent_query = f"{query} site:patents.google.com"
|
353 |
+
patent_results = search_web(patent_query, max_references=5, data_type="patent")
|
354 |
+
all_results.extend(patent_results)
|
355 |
+
|
356 |
+
if web_checked:
|
357 |
+
# For web, we don't add anything to the query
|
358 |
+
web_results = search_web(query, max_references=5, data_type="web")
|
359 |
+
all_results.extend(web_results)
|
360 |
+
|
361 |
+
# If nothing is checked, default to web search
|
362 |
+
if not (pdf_checked or patent_checked or web_checked):
|
363 |
+
web_results = search_web(query, max_references=5, data_type="web")
|
364 |
+
all_results.extend(web_results)
|
365 |
+
|
366 |
+
return jsonify({'results': all_results})
|
367 |
+
except Exception as e:
|
368 |
+
print(f"Error performing search: {e}")
|
369 |
+
return jsonify({'error': str(e), 'results': []})
|
370 |
+
|
371 |
+
@app.route('/analyze', methods=['POST'])
|
372 |
+
def analyze():
|
373 |
+
data = request.json
|
374 |
+
if not data or 'patent_background' not in data or 'pdf_url' not in data:
|
375 |
+
return jsonify({'error': 'Missing required parameters', 'result': None})
|
376 |
+
|
377 |
+
try:
|
378 |
+
patent_background = data['patent_background']
|
379 |
+
url = data['pdf_url']
|
380 |
+
data_type = data.get('data_type', 'pdf') # Default to pdf if not specified
|
381 |
+
|
382 |
+
result = analyze_pdf_novelty(patent_background, url, data_type)
|
383 |
+
return jsonify({'result': result})
|
384 |
+
except Exception as e:
|
385 |
+
print(f"Error analyzing document: {e}")
|
386 |
+
return jsonify({'error': str(e), 'result': None})
|
387 |
+
|
388 |
+
@app.route('/post_insights', methods=['POST'])
|
389 |
+
def post_insights():
|
390 |
+
data = request.json
|
391 |
+
if not data or 'patent_background' not in data or 'pdf_url' not in data:
|
392 |
+
return jsonify({'error': 'Missing required parameters', 'result': None})
|
393 |
+
|
394 |
+
try:
|
395 |
+
patent_background = data['patent_background']
|
396 |
+
url = data['pdf_url']
|
397 |
+
data_type = data.get('data_type', 'pdf') # Default to pdf if not specified
|
398 |
+
|
399 |
+
result = extract_insights(patent_background, url, data_type)
|
400 |
+
return jsonify({'result': result})
|
401 |
+
except Exception as e:
|
402 |
+
print(f"Error analyzing document: {e}")
|
403 |
+
return jsonify({'error': str(e), 'result': None})
|
404 |
+
|
405 |
+
@app.route('/refine-problem', methods=['POST'])
|
406 |
+
def refine_problem():
|
407 |
+
data = request.json
|
408 |
+
if not data or 'original_problem' not in data or 'insights' not in data:
|
409 |
+
return jsonify({'error': 'Missing required parameters', 'result': None})
|
410 |
+
|
411 |
+
try:
|
412 |
+
original_problem = data['original_problem']
|
413 |
+
insights = data['insights']
|
414 |
+
user_comments = data.get('user_comments', '')
|
415 |
+
|
416 |
+
# Prepare the message for the LLM
|
417 |
+
message = f"""Initial Technical Problem:
|
418 |
+
{original_problem}
|
419 |
+
|
420 |
+
Selected Insights:
|
421 |
+
{', '.join(insights)}
|
422 |
+
|
423 |
+
User Comments/Suggestions:
|
424 |
+
{user_comments}
|
425 |
+
"""
|
426 |
+
|
427 |
+
# Get refined problem suggestions from the LLM
|
428 |
+
result = ask_ollama(
|
429 |
+
user_message=message,
|
430 |
+
system_prompt=refine_problem_prompt
|
431 |
+
)
|
432 |
+
|
433 |
+
return jsonify({'result': result})
|
434 |
+
except Exception as e:
|
435 |
+
print(f"Error refining problem: {e}")
|
436 |
+
return jsonify({'error': str(e), 'result': None})
|
437 |
+
|
438 |
+
@app.route('/export-excel', methods=['POST'])
|
439 |
+
def export_excel():
|
440 |
+
try:
|
441 |
+
data = request.json
|
442 |
+
if not data or 'tableData' not in data:
|
443 |
+
return jsonify({'error': 'No table data provided'})
|
444 |
+
|
445 |
+
# Create pandas DataFrame from the data
|
446 |
+
df = pd.DataFrame(data['tableData'])
|
447 |
+
|
448 |
+
# Get the user query
|
449 |
+
user_query = data.get('userQuery', 'No query provided')
|
450 |
+
|
451 |
+
# Get problem versions if available
|
452 |
+
problem_versions = data.get('problemVersions', {})
|
453 |
+
|
454 |
+
# Create a BytesIO object to store the Excel file
|
455 |
+
output = io.BytesIO()
|
456 |
+
|
457 |
+
# Create Excel file with xlsxwriter engine
|
458 |
+
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
|
459 |
+
# Write the data to a sheet named 'Results'
|
460 |
+
df.to_excel(writer, sheet_name='Results', index=False)
|
461 |
+
|
462 |
+
# Get workbook and worksheet objects
|
463 |
+
workbook = writer.book
|
464 |
+
worksheet = writer.sheets['Results']
|
465 |
+
|
466 |
+
# Add a sheet for the query
|
467 |
+
query_sheet = workbook.add_worksheet('Query')
|
468 |
+
query_sheet.write(0, 0, 'Patent Query')
|
469 |
+
query_sheet.write(1, 0, user_query)
|
470 |
+
|
471 |
+
# Add a sheet for problem versions if available
|
472 |
+
if problem_versions:
|
473 |
+
versions_sheet = workbook.add_worksheet('Problem Versions')
|
474 |
+
versions_sheet.write(0, 0, 'Version')
|
475 |
+
versions_sheet.write(0, 1, 'Problem Statement')
|
476 |
+
|
477 |
+
row = 1
|
478 |
+
for version, text in problem_versions.items():
|
479 |
+
versions_sheet.write(row, 0, version)
|
480 |
+
versions_sheet.write(row, 1, text)
|
481 |
+
row += 1
|
482 |
+
|
483 |
+
# Set column width for problem versions
|
484 |
+
versions_sheet.set_column(0, 0, 20)
|
485 |
+
versions_sheet.set_column(1, 1, 100)
|
486 |
+
|
487 |
+
# Adjust column widths
|
488 |
+
for i, col in enumerate(df.columns):
|
489 |
+
# Get maximum column width
|
490 |
+
max_len = max(
|
491 |
+
df[col].astype(str).map(len).max(),
|
492 |
+
len(col)
|
493 |
+
) + 2
|
494 |
+
# Set column width (limit to 100 to avoid issues)
|
495 |
+
worksheet.set_column(i, i, min(max_len, 100))
|
496 |
+
|
497 |
+
# Seek to the beginning of the BytesIO object
|
498 |
+
output.seek(0)
|
499 |
+
|
500 |
+
# Return the Excel file
|
501 |
+
return send_file(
|
502 |
+
output,
|
503 |
+
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
504 |
+
as_attachment=True,
|
505 |
+
download_name='patent_search_results.xlsx'
|
506 |
+
)
|
507 |
+
|
508 |
+
except Exception as e:
|
509 |
+
print(f"Error exporting Excel: {e}")
|
510 |
+
return jsonify({'error': str(e)})
|
511 |
+
|
512 |
+
if __name__ == '__main__':
|
513 |
+
app.run(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
annotated-types==0.7.0
|
2 |
+
anyio==4.9.0
|
3 |
+
beautifulsoup4==4.13.3
|
4 |
+
blinker==1.9.0
|
5 |
+
certifi==2025.1.31
|
6 |
+
charset-normalizer==3.4.1
|
7 |
+
click==8.1.8
|
8 |
+
duckduckgo_search==7.5.2
|
9 |
+
Flask==3.1.0
|
10 |
+
h11==0.14.0
|
11 |
+
httpcore==1.0.7
|
12 |
+
httpx==0.28.1
|
13 |
+
idna==3.10
|
14 |
+
itsdangerous==2.2.0
|
15 |
+
Jinja2==3.1.6
|
16 |
+
lxml==5.3.1
|
17 |
+
MarkupSafe==3.0.2
|
18 |
+
numpy==2.2.4
|
19 |
+
ollama==0.4.7
|
20 |
+
pandas==2.2.3
|
21 |
+
primp==0.14.0
|
22 |
+
pydantic==2.10.6
|
23 |
+
pydantic_core==2.27.2
|
24 |
+
PyMuPDF==1.25.4
|
25 |
+
python-dateutil==2.9.0.post0
|
26 |
+
pytz==2025.1
|
27 |
+
requests==2.32.3
|
28 |
+
six==1.17.0
|
29 |
+
sniffio==1.3.1
|
30 |
+
soupsieve==2.6
|
31 |
+
typing_extensions==4.12.2
|
32 |
+
tzdata==2025.1
|
33 |
+
urllib3==2.3.0
|
34 |
+
Werkzeug==3.1.3
|
35 |
+
XlsxWriter==3.2.2
|
static/style.css
ADDED
@@ -0,0 +1,628 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
:root {
|
2 |
+
--primary: #2563eb;
|
3 |
+
--primary-light: #3b82f6;
|
4 |
+
--primary-dark: #1d4ed8;
|
5 |
+
--danger: #ef4444;
|
6 |
+
--success: #10b981;
|
7 |
+
--warning: #f59e0b;
|
8 |
+
--gray-100: #f3f4f6;
|
9 |
+
--gray-200: #e5e7eb;
|
10 |
+
--gray-300: #d1d5db;
|
11 |
+
--gray-400: #9ca3af;
|
12 |
+
--gray-500: #6b7280;
|
13 |
+
--gray-600: #4b5563;
|
14 |
+
--gray-700: #374151;
|
15 |
+
--gray-800: #1f2937;
|
16 |
+
--gray-900: #111827;
|
17 |
+
--transition: all 0.2s ease;
|
18 |
+
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
19 |
+
--shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
|
20 |
+
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
21 |
+
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
22 |
+
}
|
23 |
+
|
24 |
+
* {
|
25 |
+
box-sizing: border-box;
|
26 |
+
margin: 0;
|
27 |
+
padding: 0;
|
28 |
+
}
|
29 |
+
|
30 |
+
body {
|
31 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
32 |
+
line-height: 1.6;
|
33 |
+
color: var(--gray-800);
|
34 |
+
background-color: #f8fafc;
|
35 |
+
max-width: 1200px;
|
36 |
+
margin: 0 auto;
|
37 |
+
padding: 2rem;
|
38 |
+
}
|
39 |
+
|
40 |
+
@media (max-width: 768px) {
|
41 |
+
body {
|
42 |
+
padding: 1rem;
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
.container {
|
47 |
+
max-width: 1000px;
|
48 |
+
margin: 0 auto;
|
49 |
+
}
|
50 |
+
|
51 |
+
.header {
|
52 |
+
margin-bottom: 2.5rem;
|
53 |
+
text-align: center;
|
54 |
+
}
|
55 |
+
|
56 |
+
.logo {
|
57 |
+
display: flex;
|
58 |
+
align-items: center;
|
59 |
+
justify-content: center;
|
60 |
+
margin-bottom: 1rem;
|
61 |
+
}
|
62 |
+
|
63 |
+
.logo-icon {
|
64 |
+
width: 40px;
|
65 |
+
height: 40px;
|
66 |
+
background-color: var(--primary);
|
67 |
+
border-radius: 8px;
|
68 |
+
color: white;
|
69 |
+
display: flex;
|
70 |
+
align-items: center;
|
71 |
+
justify-content: center;
|
72 |
+
font-weight: bold;
|
73 |
+
font-size: 1.5rem;
|
74 |
+
margin-right: 10px;
|
75 |
+
}
|
76 |
+
|
77 |
+
h1 {
|
78 |
+
font-size: 2rem;
|
79 |
+
font-weight: 700;
|
80 |
+
color: var(--gray-900);
|
81 |
+
margin-bottom: 0.5rem;
|
82 |
+
}
|
83 |
+
|
84 |
+
h2 {
|
85 |
+
font-size: 1.5rem;
|
86 |
+
font-weight: 600;
|
87 |
+
color: var(--gray-800);
|
88 |
+
margin-bottom: 1.5rem;
|
89 |
+
}
|
90 |
+
|
91 |
+
p {
|
92 |
+
color: var(--gray-600);
|
93 |
+
margin-bottom: 1rem;
|
94 |
+
}
|
95 |
+
|
96 |
+
.card {
|
97 |
+
background-color: white;
|
98 |
+
border-radius: 0.75rem;
|
99 |
+
box-shadow: var(--shadow);
|
100 |
+
padding: 2rem;
|
101 |
+
margin-bottom: 2rem;
|
102 |
+
}
|
103 |
+
|
104 |
+
.form-group {
|
105 |
+
margin-bottom: 1.5rem;
|
106 |
+
}
|
107 |
+
|
108 |
+
label {
|
109 |
+
display: block;
|
110 |
+
margin-bottom: 0.5rem;
|
111 |
+
font-weight: 500;
|
112 |
+
color: var(--gray-700);
|
113 |
+
}
|
114 |
+
|
115 |
+
#userInput {
|
116 |
+
width: 100%;
|
117 |
+
padding: 0.75rem;
|
118 |
+
border: 1px solid var(--gray-300);
|
119 |
+
border-radius: 0.5rem;
|
120 |
+
min-height: 150px;
|
121 |
+
font-family: inherit;
|
122 |
+
resize: vertical;
|
123 |
+
transition: var(--transition);
|
124 |
+
}
|
125 |
+
|
126 |
+
#userInput:focus {
|
127 |
+
outline: none;
|
128 |
+
border-color: var(--primary);
|
129 |
+
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
|
130 |
+
}
|
131 |
+
|
132 |
+
.btn {
|
133 |
+
display: inline-flex;
|
134 |
+
align-items: center;
|
135 |
+
justify-content: center;
|
136 |
+
padding: 0.625rem 1.25rem;
|
137 |
+
border: none;
|
138 |
+
border-radius: 0.5rem;
|
139 |
+
font-weight: 500;
|
140 |
+
font-size: 0.875rem;
|
141 |
+
cursor: pointer;
|
142 |
+
transition: var(--transition);
|
143 |
+
gap: 0.5rem;
|
144 |
+
}
|
145 |
+
|
146 |
+
.btn-primary {
|
147 |
+
background-color: var(--primary);
|
148 |
+
color: white;
|
149 |
+
}
|
150 |
+
|
151 |
+
.btn-primary:hover {
|
152 |
+
background-color: var(--primary-dark);
|
153 |
+
}
|
154 |
+
|
155 |
+
.btn-secondary {
|
156 |
+
background-color: var(--gray-100);
|
157 |
+
color: var(--gray-700);
|
158 |
+
}
|
159 |
+
|
160 |
+
.btn-secondary:hover {
|
161 |
+
background-color: var(--gray-200);
|
162 |
+
}
|
163 |
+
|
164 |
+
.btn-danger {
|
165 |
+
background-color: var(--danger);
|
166 |
+
color: white;
|
167 |
+
}
|
168 |
+
|
169 |
+
.btn-danger:hover {
|
170 |
+
background-color: #dc2626;
|
171 |
+
}
|
172 |
+
|
173 |
+
.btn-success {
|
174 |
+
background-color: var(--success);
|
175 |
+
color: white;
|
176 |
+
}
|
177 |
+
|
178 |
+
.btn-success:hover {
|
179 |
+
background-color: #059669;
|
180 |
+
}
|
181 |
+
|
182 |
+
.btn-warning {
|
183 |
+
background-color: var(--warning);
|
184 |
+
color: white;
|
185 |
+
}
|
186 |
+
|
187 |
+
.btn-warning:hover {
|
188 |
+
background-color: #d97706;
|
189 |
+
}
|
190 |
+
|
191 |
+
.query-item {
|
192 |
+
background-color: white;
|
193 |
+
border-radius: 0.75rem;
|
194 |
+
box-shadow: var(--shadow);
|
195 |
+
padding: 1.5rem;
|
196 |
+
margin-bottom: 1.5rem;
|
197 |
+
}
|
198 |
+
|
199 |
+
.query-container {
|
200 |
+
display: flex;
|
201 |
+
margin-bottom: 1rem;
|
202 |
+
align-items: center;
|
203 |
+
gap: 0.5rem;
|
204 |
+
}
|
205 |
+
|
206 |
+
.query-field {
|
207 |
+
flex-grow: 1;
|
208 |
+
padding: 0.625rem 0.75rem;
|
209 |
+
border: 1px solid var(--gray-300);
|
210 |
+
border-radius: 0.5rem;
|
211 |
+
transition: var(--transition);
|
212 |
+
}
|
213 |
+
|
214 |
+
.query-field:focus {
|
215 |
+
outline: none;
|
216 |
+
border-color: var(--primary);
|
217 |
+
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
|
218 |
+
}
|
219 |
+
|
220 |
+
.action-button {
|
221 |
+
background-color: hsl(192, 83%, 66%);
|
222 |
+
color: white;
|
223 |
+
padding: 8px 12px;
|
224 |
+
border: none;
|
225 |
+
border-radius: 4px;
|
226 |
+
cursor: pointer;
|
227 |
+
margin-right: 5px;
|
228 |
+
}
|
229 |
+
.delete-button {
|
230 |
+
background-color: #f44336;
|
231 |
+
}
|
232 |
+
.search-button {
|
233 |
+
background-color: #2196F3;
|
234 |
+
}
|
235 |
+
button:hover {
|
236 |
+
opacity: 0.9;
|
237 |
+
}
|
238 |
+
|
239 |
+
#resultsContainer {
|
240 |
+
margin-top: 20px;
|
241 |
+
display: none;
|
242 |
+
}
|
243 |
+
#queriesContainer {
|
244 |
+
margin-bottom: 15px;
|
245 |
+
}
|
246 |
+
#loadingIndicator {
|
247 |
+
display: none;
|
248 |
+
margin-top: 20px;
|
249 |
+
text-align: center;
|
250 |
+
color: #666;
|
251 |
+
}
|
252 |
+
.button-container {
|
253 |
+
margin-top: 15px;
|
254 |
+
}
|
255 |
+
.results-table {
|
256 |
+
width: 100%;
|
257 |
+
border-collapse: collapse;
|
258 |
+
margin-top: 10px;
|
259 |
+
display: none;
|
260 |
+
}
|
261 |
+
.results-table th, .results-table td {
|
262 |
+
border: 1px solid #ddd;
|
263 |
+
padding: 8px;
|
264 |
+
text-align: left;
|
265 |
+
}
|
266 |
+
.results-table th {
|
267 |
+
background-color: #f2f2f2;
|
268 |
+
}
|
269 |
+
.results-table tr:nth-child(even) {
|
270 |
+
background-color: #f9f9f9;
|
271 |
+
}
|
272 |
+
.results-table tr:hover {
|
273 |
+
background-color: #f1f1f1;
|
274 |
+
}
|
275 |
+
.search-loading {
|
276 |
+
display: none;
|
277 |
+
margin: 10px 0;
|
278 |
+
font-style: italic;
|
279 |
+
color: #666;
|
280 |
+
}
|
281 |
+
.url-link {
|
282 |
+
color: #0066cc;
|
283 |
+
text-decoration: none;
|
284 |
+
word-break: break-all;
|
285 |
+
}
|
286 |
+
.url-link:hover {
|
287 |
+
text-decoration: underline;
|
288 |
+
}
|
289 |
+
|
290 |
+
.analyze-button {
|
291 |
+
margin-top: 5px;
|
292 |
+
padding: 3px 8px;
|
293 |
+
font-size: 0.8em;
|
294 |
+
}
|
295 |
+
|
296 |
+
.loading-spinner {
|
297 |
+
border: 4px solid #f3f3f3;
|
298 |
+
border-top: 4px solid #3498db;
|
299 |
+
border-radius: 50%;
|
300 |
+
width: 20px;
|
301 |
+
height: 20px;
|
302 |
+
animation: spin 2s linear infinite;
|
303 |
+
margin: 0 auto;
|
304 |
+
}
|
305 |
+
|
306 |
+
@keyframes spin {
|
307 |
+
0% { transform: rotate(0deg); }
|
308 |
+
100% { transform: rotate(360deg); }
|
309 |
+
}
|
310 |
+
|
311 |
+
.score-cell, .justification-cell {
|
312 |
+
max-width: 150px;
|
313 |
+
overflow: hidden;
|
314 |
+
text-overflow: ellipsis;
|
315 |
+
}
|
316 |
+
|
317 |
+
.score-cell {
|
318 |
+
font-weight: bold;
|
319 |
+
text-align: center;
|
320 |
+
}
|
321 |
+
|
322 |
+
.floating-buttons {
|
323 |
+
position: fixed;
|
324 |
+
bottom: 2rem;
|
325 |
+
right: 2rem;
|
326 |
+
display: flex;
|
327 |
+
flex-direction: column;
|
328 |
+
gap: 0.75rem;
|
329 |
+
z-index: 100;
|
330 |
+
}
|
331 |
+
|
332 |
+
.floating-button {
|
333 |
+
padding: 0.75rem;
|
334 |
+
border-radius: 0.5rem;
|
335 |
+
box-shadow: var(--shadow-md);
|
336 |
+
transition: all 0.3s ease;
|
337 |
+
display: flex;
|
338 |
+
align-items: center;
|
339 |
+
justify-content: center;
|
340 |
+
gap: 0.5rem;
|
341 |
+
width: auto;
|
342 |
+
white-space: nowrap;
|
343 |
+
}
|
344 |
+
|
345 |
+
.floating-button:hover {
|
346 |
+
transform: translateY(-2px);
|
347 |
+
box-shadow: var(--shadow-lg);
|
348 |
+
}
|
349 |
+
|
350 |
+
.loading-overlay {
|
351 |
+
position: fixed;
|
352 |
+
top: 0;
|
353 |
+
left: 0;
|
354 |
+
width: 100%;
|
355 |
+
height: 100%;
|
356 |
+
background-color: rgba(0, 0, 0, 0.5);
|
357 |
+
display: none;
|
358 |
+
justify-content: center;
|
359 |
+
align-items: center;
|
360 |
+
z-index: 1000;
|
361 |
+
}
|
362 |
+
|
363 |
+
.loading-content {
|
364 |
+
background-color: white;
|
365 |
+
padding: 2rem;
|
366 |
+
border-radius: 0.75rem;
|
367 |
+
text-align: center;
|
368 |
+
box-shadow: var(--shadow-lg);
|
369 |
+
max-width: 80%;
|
370 |
+
}
|
371 |
+
|
372 |
+
.loading-content .loading-spinner {
|
373 |
+
width: 40px;
|
374 |
+
height: 40px;
|
375 |
+
border-width: 4px;
|
376 |
+
margin-bottom: 1rem;
|
377 |
+
}
|
378 |
+
|
379 |
+
.progress-text {
|
380 |
+
font-size: 1rem;
|
381 |
+
margin-top: 0.75rem;
|
382 |
+
color: var(--gray-700);
|
383 |
+
}
|
384 |
+
|
385 |
+
.button-container {
|
386 |
+
margin-top: 1.5rem;
|
387 |
+
display: flex;
|
388 |
+
justify-content: flex-start;
|
389 |
+
gap: 0.75rem;
|
390 |
+
}
|
391 |
+
|
392 |
+
/* Add icons for better UX */
|
393 |
+
.icon {
|
394 |
+
display: inline-block;
|
395 |
+
width: 20px;
|
396 |
+
height: 20px;
|
397 |
+
background-size: contain;
|
398 |
+
background-repeat: no-repeat;
|
399 |
+
background-position: center;
|
400 |
+
}
|
401 |
+
|
402 |
+
.table-container {
|
403 |
+
margin-top: 1rem;
|
404 |
+
overflow-x: auto;
|
405 |
+
border-radius: 0.5rem;
|
406 |
+
border: 1px solid var(--gray-200);
|
407 |
+
}
|
408 |
+
|
409 |
+
/* Responsive adjustments */
|
410 |
+
@media (max-width: 768px) {
|
411 |
+
.query-container {
|
412 |
+
flex-direction: column;
|
413 |
+
align-items: stretch;
|
414 |
+
}
|
415 |
+
|
416 |
+
.query-container .btn {
|
417 |
+
margin-top: 0.5rem;
|
418 |
+
}
|
419 |
+
|
420 |
+
.floating-buttons {
|
421 |
+
bottom: 1rem;
|
422 |
+
right: 1rem;
|
423 |
+
}
|
424 |
+
}
|
425 |
+
|
426 |
+
.search-options {
|
427 |
+
margin-bottom: 20px;
|
428 |
+
text-align: center;
|
429 |
+
}
|
430 |
+
|
431 |
+
.checkbox-group {
|
432 |
+
display: flex;
|
433 |
+
gap: 15px;
|
434 |
+
margin-top: 5px;
|
435 |
+
justify-content: center; /* This centers the checkboxes horizontally */
|
436 |
+
}
|
437 |
+
|
438 |
+
.checkbox-item {
|
439 |
+
display: flex;
|
440 |
+
align-items: center;
|
441 |
+
gap: 5px;
|
442 |
+
}
|
443 |
+
|
444 |
+
/* Adding styles for insights feature */
|
445 |
+
.insights-container {
|
446 |
+
margin-top: 10px;
|
447 |
+
border-top: 1px dashed #ccc;
|
448 |
+
padding-top: 10px;
|
449 |
+
}
|
450 |
+
|
451 |
+
.insights-header {
|
452 |
+
display: flex;
|
453 |
+
justify-content: space-between;
|
454 |
+
align-items: center;
|
455 |
+
margin-bottom: 8px;
|
456 |
+
}
|
457 |
+
|
458 |
+
.insights-title {
|
459 |
+
font-weight: bold;
|
460 |
+
color: #333;
|
461 |
+
}
|
462 |
+
|
463 |
+
.insights-actions {
|
464 |
+
display: flex;
|
465 |
+
gap: 8px;
|
466 |
+
}
|
467 |
+
|
468 |
+
.insights-button {
|
469 |
+
font-size: 12px;
|
470 |
+
padding: 2px 6px;
|
471 |
+
background-color: #4CAF50;
|
472 |
+
color: white;
|
473 |
+
border: none;
|
474 |
+
border-radius: 3px;
|
475 |
+
cursor: pointer;
|
476 |
+
}
|
477 |
+
|
478 |
+
.insights-list {
|
479 |
+
display: flex;
|
480 |
+
flex-wrap: wrap;
|
481 |
+
gap: 8px;
|
482 |
+
margin-top: 8px;
|
483 |
+
}
|
484 |
+
|
485 |
+
.insight-tag {
|
486 |
+
background-color: #f1f1f1;
|
487 |
+
border: 1px solid #ddd;
|
488 |
+
border-radius: 15px;
|
489 |
+
padding: 4px 12px;
|
490 |
+
font-size: 12px;
|
491 |
+
cursor: pointer;
|
492 |
+
transition: all 0.2s ease;
|
493 |
+
user-select: none;
|
494 |
+
}
|
495 |
+
|
496 |
+
.insight-tag.selected {
|
497 |
+
background-color: #4CAF50;
|
498 |
+
color: white;
|
499 |
+
border-color: #4CAF50;
|
500 |
+
}
|
501 |
+
|
502 |
+
/* Styles for problem refinement functionality */
|
503 |
+
.problem-history {
|
504 |
+
position: relative;
|
505 |
+
margin-bottom: 10px;
|
506 |
+
}
|
507 |
+
|
508 |
+
.problem-history-nav {
|
509 |
+
display: flex;
|
510 |
+
align-items: center;
|
511 |
+
margin-bottom: 5px;
|
512 |
+
}
|
513 |
+
|
514 |
+
.history-arrow {
|
515 |
+
padding: 2px 8px;
|
516 |
+
background-color: var(--gray-200);
|
517 |
+
border-radius: 3px;
|
518 |
+
cursor: pointer;
|
519 |
+
margin-right: 5px;
|
520 |
+
font-size: 14px;
|
521 |
+
color: var(--gray-700);
|
522 |
+
}
|
523 |
+
|
524 |
+
.history-arrow:hover {
|
525 |
+
background-color: var(--gray-300);
|
526 |
+
}
|
527 |
+
|
528 |
+
.history-arrow.disabled {
|
529 |
+
opacity: 0.5;
|
530 |
+
cursor: not-allowed;
|
531 |
+
}
|
532 |
+
|
533 |
+
.history-status {
|
534 |
+
font-size: 12px;
|
535 |
+
color: var(--gray-600);
|
536 |
+
}
|
537 |
+
|
538 |
+
.insight-comment-area {
|
539 |
+
margin-top: 10px;
|
540 |
+
width: 100%;
|
541 |
+
}
|
542 |
+
|
543 |
+
.insight-comment-textarea {
|
544 |
+
width: 100%;
|
545 |
+
padding: 8px;
|
546 |
+
border: 1px solid var(--gray-300);
|
547 |
+
border-radius: 4px;
|
548 |
+
font-size: 14px;
|
549 |
+
resize: vertical;
|
550 |
+
min-height: 60px;
|
551 |
+
}
|
552 |
+
|
553 |
+
.refined-problem-container {
|
554 |
+
margin-top: 20px;
|
555 |
+
border: 1px solid var(--gray-300);
|
556 |
+
border-radius: 8px;
|
557 |
+
overflow: hidden;
|
558 |
+
}
|
559 |
+
|
560 |
+
.refined-problem-tabs {
|
561 |
+
display: flex;
|
562 |
+
background-color: var(--gray-100);
|
563 |
+
border-bottom: 1px solid var(--gray-300);
|
564 |
+
}
|
565 |
+
|
566 |
+
.refined-problem-tab {
|
567 |
+
padding: 10px 15px;
|
568 |
+
cursor: pointer;
|
569 |
+
font-weight: 500;
|
570 |
+
border-right: 1px solid var(--gray-300);
|
571 |
+
}
|
572 |
+
|
573 |
+
.refined-problem-tab.active {
|
574 |
+
background-color: white;
|
575 |
+
border-bottom: 2px solid var(--primary);
|
576 |
+
}
|
577 |
+
|
578 |
+
.refined-problem-content {
|
579 |
+
padding: 15px;
|
580 |
+
background-color: white;
|
581 |
+
}
|
582 |
+
|
583 |
+
.refined-problem {
|
584 |
+
display: none;
|
585 |
+
}
|
586 |
+
|
587 |
+
.refined-problem.active {
|
588 |
+
display: block;
|
589 |
+
}
|
590 |
+
|
591 |
+
.refined-problem-title {
|
592 |
+
font-weight: 600;
|
593 |
+
margin-bottom: 10px;
|
594 |
+
color: var(--primary-dark);
|
595 |
+
}
|
596 |
+
|
597 |
+
.refined-problem-description {
|
598 |
+
line-height: 1.5;
|
599 |
+
}
|
600 |
+
|
601 |
+
.apply-problem-btn {
|
602 |
+
margin-top: 10px;
|
603 |
+
background-color: var(--primary);
|
604 |
+
color: white;
|
605 |
+
border: none;
|
606 |
+
border-radius: 4px;
|
607 |
+
padding: 5px 10px;
|
608 |
+
cursor: pointer;
|
609 |
+
font-size: 14px;
|
610 |
+
}
|
611 |
+
|
612 |
+
.apply-problem-btn:hover {
|
613 |
+
background-color: var(--primary-dark);
|
614 |
+
}
|
615 |
+
|
616 |
+
.enhance-problem-button {
|
617 |
+
background-color: var(--warning);
|
618 |
+
color: white;
|
619 |
+
}
|
620 |
+
|
621 |
+
.enhance-problem-button:hover {
|
622 |
+
background-color: #d97706;
|
623 |
+
}
|
624 |
+
|
625 |
+
.enhance-problem-button.disabled {
|
626 |
+
opacity: 0.6;
|
627 |
+
cursor: not-allowed;
|
628 |
+
}
|
templates/index.html
ADDED
@@ -0,0 +1,1252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Patentability</title>
|
7 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
8 |
+
<script>
|
9 |
+
// Array to store problem history versions
|
10 |
+
const problemHistory = [];
|
11 |
+
let currentHistoryIndex = -1;
|
12 |
+
// Store all refined problem suggestions
|
13 |
+
let storedRefinedProblems = {};
|
14 |
+
|
15 |
+
function generateQueries(event) {
|
16 |
+
event.preventDefault();
|
17 |
+
|
18 |
+
const userInput = document.getElementById('userInput').value.trim();
|
19 |
+
if (!userInput) {
|
20 |
+
alert('Please enter a technical problem description');
|
21 |
+
return;
|
22 |
+
}
|
23 |
+
|
24 |
+
// Show loading indicator
|
25 |
+
document.getElementById('loadingIndicator').style.display = 'block';
|
26 |
+
// Hide results if they were previously shown
|
27 |
+
document.getElementById('resultsContainer').style.display = 'none';
|
28 |
+
|
29 |
+
// Send message to Flask backend
|
30 |
+
fetch('/chat', {
|
31 |
+
method: 'POST',
|
32 |
+
body: new URLSearchParams({ 'message': userInput }),
|
33 |
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
34 |
+
})
|
35 |
+
.then(response => response.json())
|
36 |
+
.then(data => {
|
37 |
+
// Hide loading indicator
|
38 |
+
document.getElementById('loadingIndicator').style.display = 'none';
|
39 |
+
|
40 |
+
try {
|
41 |
+
// Parse the JSON string from the LLM response
|
42 |
+
let jsonData;
|
43 |
+
// First check if data.reply is already an object
|
44 |
+
if (typeof data.reply === 'object') {
|
45 |
+
jsonData = data.reply;
|
46 |
+
} else {
|
47 |
+
// Try to extract JSON if it's a string possibly with markdown code blocks
|
48 |
+
const jsonString = data.reply.replace(/```json|```/g, '').trim();
|
49 |
+
jsonData = JSON.parse(jsonString);
|
50 |
+
}
|
51 |
+
|
52 |
+
// Clear existing queries
|
53 |
+
const queriesContainer = document.getElementById('queriesContainer');
|
54 |
+
queriesContainer.innerHTML = '';
|
55 |
+
|
56 |
+
// Add each query from the response
|
57 |
+
Object.keys(jsonData).forEach(key => {
|
58 |
+
addQueryField(jsonData[key]);
|
59 |
+
});
|
60 |
+
|
61 |
+
// Show results container
|
62 |
+
document.getElementById('resultsContainer').style.display = 'block';
|
63 |
+
} catch (error) {
|
64 |
+
console.error('Error parsing JSON:', error);
|
65 |
+
alert('There was an error processing the response. Please try again.');
|
66 |
+
}
|
67 |
+
})
|
68 |
+
.catch(error => {
|
69 |
+
document.getElementById('loadingIndicator').style.display = 'none';
|
70 |
+
console.error('Error:', error);
|
71 |
+
alert('There was an error communicating with the server. Please try again.');
|
72 |
+
});
|
73 |
+
}
|
74 |
+
|
75 |
+
// Add a new query field with the given text (or empty if not provided)
|
76 |
+
function addQueryField(queryText = '') {
|
77 |
+
const queriesContainer = document.getElementById('queriesContainer');
|
78 |
+
const queryIndex = queriesContainer.children.length + 1;
|
79 |
+
|
80 |
+
// Create main container for this query item
|
81 |
+
const queryItem = document.createElement('div');
|
82 |
+
queryItem.className = 'query-item';
|
83 |
+
|
84 |
+
// Create container for query field and buttons
|
85 |
+
const queryContainer = document.createElement('div');
|
86 |
+
queryContainer.className = 'query-container';
|
87 |
+
|
88 |
+
// Input field
|
89 |
+
const queryField = document.createElement('input');
|
90 |
+
queryField.type = 'text';
|
91 |
+
queryField.className = 'query-field';
|
92 |
+
queryField.value = queryText;
|
93 |
+
queryField.placeholder = `Search Query ${queryIndex}`;
|
94 |
+
|
95 |
+
// Delete button
|
96 |
+
const deleteButton = document.createElement('button');
|
97 |
+
deleteButton.type = 'button';
|
98 |
+
deleteButton.className = 'action-button delete-button';
|
99 |
+
deleteButton.textContent = 'Delete';
|
100 |
+
deleteButton.onclick = function() {
|
101 |
+
queriesContainer.removeChild(queryItem);
|
102 |
+
// Update the placeholder numbers for remaining queries
|
103 |
+
updateQueryIndices();
|
104 |
+
};
|
105 |
+
// Search button
|
106 |
+
const searchButton = document.createElement('button');
|
107 |
+
searchButton.type = 'button';
|
108 |
+
searchButton.className = 'action-button search-button';
|
109 |
+
searchButton.textContent = 'Search';
|
110 |
+
searchButton.onclick = function() {
|
111 |
+
performSearch(queryField.value, queryItem);
|
112 |
+
};
|
113 |
+
|
114 |
+
// Add elements to container
|
115 |
+
queryContainer.appendChild(queryField);
|
116 |
+
queryContainer.appendChild(searchButton);
|
117 |
+
queryContainer.appendChild(deleteButton);
|
118 |
+
|
119 |
+
// Create loading indicator for this search
|
120 |
+
const searchLoading = document.createElement('div');
|
121 |
+
searchLoading.className = 'search-loading';
|
122 |
+
searchLoading.textContent = 'Searching... Please wait.';
|
123 |
+
|
124 |
+
// Create table for results
|
125 |
+
const resultsTable = document.createElement('table');
|
126 |
+
resultsTable.className = 'results-table';
|
127 |
+
|
128 |
+
// Add table header
|
129 |
+
const tableHeader = document.createElement('thead');
|
130 |
+
const headerRow = document.createElement('tr');
|
131 |
+
|
132 |
+
const typeHeader = document.createElement('th');
|
133 |
+
typeHeader.textContent = 'Type';
|
134 |
+
|
135 |
+
const titleHeader = document.createElement('th');
|
136 |
+
titleHeader.textContent = 'Title';
|
137 |
+
|
138 |
+
const bodyHeader = document.createElement('th');
|
139 |
+
bodyHeader.textContent = 'Description';
|
140 |
+
|
141 |
+
const urlHeader = document.createElement('th');
|
142 |
+
urlHeader.textContent = 'URL';
|
143 |
+
|
144 |
+
const scoreHeader = document.createElement('th');
|
145 |
+
scoreHeader.textContent = 'Score';
|
146 |
+
|
147 |
+
const justificationHeader = document.createElement('th');
|
148 |
+
justificationHeader.textContent = 'Justification';
|
149 |
+
|
150 |
+
headerRow.appendChild(typeHeader);
|
151 |
+
headerRow.appendChild(titleHeader);
|
152 |
+
headerRow.appendChild(bodyHeader);
|
153 |
+
headerRow.appendChild(urlHeader);
|
154 |
+
headerRow.appendChild(scoreHeader);
|
155 |
+
headerRow.appendChild(justificationHeader);
|
156 |
+
tableHeader.appendChild(headerRow);
|
157 |
+
|
158 |
+
// Add table body
|
159 |
+
const tableBody = document.createElement('tbody');
|
160 |
+
|
161 |
+
resultsTable.appendChild(tableHeader);
|
162 |
+
resultsTable.appendChild(tableBody);
|
163 |
+
|
164 |
+
// Add all elements to the query item
|
165 |
+
queryItem.appendChild(queryContainer);
|
166 |
+
queryItem.appendChild(searchLoading);
|
167 |
+
queryItem.appendChild(resultsTable);
|
168 |
+
|
169 |
+
// Add container to the queries list
|
170 |
+
queriesContainer.appendChild(queryItem);
|
171 |
+
}
|
172 |
+
|
173 |
+
// Perform search and update the results table
|
174 |
+
function performSearch(query, queryItemElement) {
|
175 |
+
if (!query.trim()) {
|
176 |
+
alert('Please enter a search query');
|
177 |
+
return;
|
178 |
+
}
|
179 |
+
|
180 |
+
const loadingElement = queryItemElement.querySelector('.search-loading');
|
181 |
+
const tableElement = queryItemElement.querySelector('.results-table');
|
182 |
+
const tableBody = tableElement.querySelector('tbody');
|
183 |
+
|
184 |
+
// Show loading and hide previous results
|
185 |
+
loadingElement.style.display = 'block';
|
186 |
+
tableElement.style.display = 'none';
|
187 |
+
|
188 |
+
// Clear previous results
|
189 |
+
tableBody.innerHTML = '';
|
190 |
+
|
191 |
+
// Get checkbox values
|
192 |
+
const pdfChecked = document.getElementById('pdfOption').checked;
|
193 |
+
const patentChecked = document.getElementById('patentOption').checked;
|
194 |
+
const webChecked = document.getElementById('webOption').checked;
|
195 |
+
|
196 |
+
|
197 |
+
// Create form data with query and checkbox values
|
198 |
+
const formData = new FormData();
|
199 |
+
formData.append('query', query);
|
200 |
+
formData.append('pdfOption', pdfChecked);
|
201 |
+
formData.append('patentOption', patentChecked);
|
202 |
+
formData.append('webOption', webChecked);
|
203 |
+
|
204 |
+
|
205 |
+
// Send search request to backend
|
206 |
+
fetch('/search', {
|
207 |
+
method: 'POST',
|
208 |
+
body: formData
|
209 |
+
})
|
210 |
+
.then(response => response.json())
|
211 |
+
.then(data => {
|
212 |
+
// Hide loading indicator
|
213 |
+
loadingElement.style.display = 'none';
|
214 |
+
|
215 |
+
if (data.results && data.results.length > 0) {
|
216 |
+
// Populate table with results
|
217 |
+
data.results.forEach(result => {
|
218 |
+
const row = document.createElement('tr');
|
219 |
+
|
220 |
+
const typeCell = document.createElement('td');
|
221 |
+
typeCell.textContent = result.type;
|
222 |
+
|
223 |
+
const titleCell = document.createElement('td');
|
224 |
+
titleCell.textContent = result.title;
|
225 |
+
|
226 |
+
const bodyCell = document.createElement('td');
|
227 |
+
bodyCell.textContent = result.body;
|
228 |
+
|
229 |
+
const urlCell = document.createElement('td');
|
230 |
+
const urlLink = document.createElement('a');
|
231 |
+
urlLink.href = result.url;
|
232 |
+
urlLink.textContent = result.url;
|
233 |
+
urlLink.className = 'url-link';
|
234 |
+
urlLink.target = '_blank';
|
235 |
+
urlCell.appendChild(urlLink);
|
236 |
+
|
237 |
+
// Add "Analyze" button to the URL cell
|
238 |
+
const analyzeButton = document.createElement('button');
|
239 |
+
analyzeButton.textContent = 'Analyze';
|
240 |
+
analyzeButton.className = 'action-button analyze-button';
|
241 |
+
analyzeButton.onclick = function(e) {
|
242 |
+
e.preventDefault();
|
243 |
+
analyzePaper(result.url, queryItemElement);
|
244 |
+
};
|
245 |
+
urlCell.appendChild(document.createElement('br'));
|
246 |
+
urlCell.appendChild(analyzeButton);
|
247 |
+
|
248 |
+
row.appendChild(typeCell);
|
249 |
+
row.appendChild(titleCell);
|
250 |
+
row.appendChild(bodyCell);
|
251 |
+
row.appendChild(urlCell);
|
252 |
+
|
253 |
+
tableBody.appendChild(row);
|
254 |
+
});
|
255 |
+
|
256 |
+
// Show the table
|
257 |
+
tableElement.style.display = 'table';
|
258 |
+
} else {
|
259 |
+
// No results
|
260 |
+
const row = document.createElement('tr');
|
261 |
+
const cell = document.createElement('td');
|
262 |
+
cell.colSpan = 4; // Updated to 4 since we now have 4 columns with the type column
|
263 |
+
cell.textContent = 'No results found.';
|
264 |
+
cell.style.textAlign = 'center';
|
265 |
+
row.appendChild(cell);
|
266 |
+
tableBody.appendChild(row);
|
267 |
+
tableElement.style.display = 'table';
|
268 |
+
}
|
269 |
+
})
|
270 |
+
.catch(error => {
|
271 |
+
loadingElement.style.display = 'none';
|
272 |
+
console.error('Error:', error);
|
273 |
+
|
274 |
+
// Show error in table
|
275 |
+
const row = document.createElement('tr');
|
276 |
+
const cell = document.createElement('td');
|
277 |
+
cell.colSpan = 4; // Updated to 4 since we now have 4 columns with the type column
|
278 |
+
cell.textContent = 'Error performing search. Please try again.';
|
279 |
+
cell.style.textAlign = 'center';
|
280 |
+
cell.style.color = 'red';
|
281 |
+
row.appendChild(cell);
|
282 |
+
tableBody.appendChild(row);
|
283 |
+
tableElement.style.display = 'table';
|
284 |
+
});
|
285 |
+
}
|
286 |
+
|
287 |
+
// Extract insights from document
|
288 |
+
function extractInsights(paperUrl, row) {
|
289 |
+
const patentBackground = document.getElementById('userInput').value.trim();
|
290 |
+
if (!patentBackground) {
|
291 |
+
alert('Please provide a patent background in the input field');
|
292 |
+
return;
|
293 |
+
}
|
294 |
+
|
295 |
+
const documentType = row.cells[0].textContent.toLowerCase();
|
296 |
+
|
297 |
+
// Create or get the insight cells
|
298 |
+
let insightsContainer;
|
299 |
+
if (row.querySelector('.insights-container')) {
|
300 |
+
insightsContainer = row.querySelector('.insights-container');
|
301 |
+
insightsContainer.innerHTML = '<div class="loading-spinner"></div><div>Extracting insights...</div>';
|
302 |
+
} else {
|
303 |
+
// Create insights cell that spans across all columns
|
304 |
+
const insightsRow = document.createElement('tr');
|
305 |
+
insightsRow.className = 'insights-row';
|
306 |
+
|
307 |
+
const insightsTd = document.createElement('td');
|
308 |
+
insightsTd.colSpan = row.cells.length;
|
309 |
+
|
310 |
+
insightsContainer = document.createElement('div');
|
311 |
+
insightsContainer.className = 'insights-container';
|
312 |
+
insightsContainer.innerHTML = '<div class="loading-spinner"></div><div>Extracting insights...</div>';
|
313 |
+
|
314 |
+
insightsTd.appendChild(insightsContainer);
|
315 |
+
insightsRow.appendChild(insightsTd);
|
316 |
+
|
317 |
+
// Insert after the current row
|
318 |
+
row.parentNode.insertBefore(insightsRow, row.nextSibling);
|
319 |
+
}
|
320 |
+
|
321 |
+
// Send request to extract insights
|
322 |
+
fetch('/post_insights', {
|
323 |
+
method: 'POST',
|
324 |
+
body: JSON.stringify({
|
325 |
+
'patent_background': patentBackground,
|
326 |
+
'pdf_url': paperUrl,
|
327 |
+
'data_type': documentType
|
328 |
+
}),
|
329 |
+
headers: { 'Content-Type': 'application/json' }
|
330 |
+
})
|
331 |
+
.then(response => response.json())
|
332 |
+
.then(data => {
|
333 |
+
if (data.error) {
|
334 |
+
insightsContainer.innerHTML = `<div class="error">Error: ${data.error}</div>`;
|
335 |
+
} else if (data.result && data.result.insights) {
|
336 |
+
// Create header with title and actions
|
337 |
+
const insightsHeader = document.createElement('div');
|
338 |
+
insightsHeader.className = 'insights-header';
|
339 |
+
|
340 |
+
const insightsTitle = document.createElement('div');
|
341 |
+
insightsTitle.className = 'insights-title';
|
342 |
+
insightsTitle.textContent = 'Document Insights';
|
343 |
+
|
344 |
+
const insightsActions = document.createElement('div');
|
345 |
+
insightsActions.className = 'insights-actions';
|
346 |
+
|
347 |
+
const selectAllBtn = document.createElement('button');
|
348 |
+
selectAllBtn.className = 'insights-button';
|
349 |
+
selectAllBtn.textContent = 'Select All';
|
350 |
+
selectAllBtn.onclick = function() {
|
351 |
+
const tags = insightsContainer.querySelectorAll('.insight-tag');
|
352 |
+
tags.forEach(tag => tag.classList.add('selected'));
|
353 |
+
row.dataset.selectedInsights = JSON.stringify(data.result.insights);
|
354 |
+
row.dataset.unselectedInsights = JSON.stringify([]);
|
355 |
+
};
|
356 |
+
|
357 |
+
const clearAllBtn = document.createElement('button');
|
358 |
+
clearAllBtn.className = 'insights-button';
|
359 |
+
clearAllBtn.textContent = 'Clear All';
|
360 |
+
clearAllBtn.onclick = function() {
|
361 |
+
const tags = insightsContainer.querySelectorAll('.insight-tag');
|
362 |
+
tags.forEach(tag => tag.classList.remove('selected'));
|
363 |
+
row.dataset.selectedInsights = JSON.stringify([]);
|
364 |
+
row.dataset.unselectedInsights = JSON.stringify(data.result.insights);
|
365 |
+
};
|
366 |
+
|
367 |
+
insightsActions.appendChild(selectAllBtn);
|
368 |
+
insightsActions.appendChild(clearAllBtn);
|
369 |
+
|
370 |
+
insightsHeader.appendChild(insightsTitle);
|
371 |
+
insightsHeader.appendChild(insightsActions);
|
372 |
+
|
373 |
+
// Create insight tags
|
374 |
+
const insightsList = document.createElement('div');
|
375 |
+
insightsList.className = 'insights-list';
|
376 |
+
|
377 |
+
// Clear the container and add the new elements
|
378 |
+
insightsContainer.innerHTML = '';
|
379 |
+
insightsContainer.appendChild(insightsHeader);
|
380 |
+
insightsContainer.appendChild(insightsList);
|
381 |
+
|
382 |
+
// Initialize selected insights
|
383 |
+
const selectedInsights = [];
|
384 |
+
const unselectedInsights = [];
|
385 |
+
|
386 |
+
// Add insight tags
|
387 |
+
data.result.insights.forEach(insight => {
|
388 |
+
const tagElement = document.createElement('div');
|
389 |
+
tagElement.className = 'insight-tag';
|
390 |
+
tagElement.textContent = insight;
|
391 |
+
tagElement.onclick = function() {
|
392 |
+
tagElement.classList.toggle('selected');
|
393 |
+
|
394 |
+
// Update selected insights
|
395 |
+
updateSelectedInsights(row, insightsContainer);
|
396 |
+
};
|
397 |
+
|
398 |
+
// Add to selected by default
|
399 |
+
tagElement.classList.add('selected');
|
400 |
+
selectedInsights.push(insight);
|
401 |
+
|
402 |
+
insightsList.appendChild(tagElement);
|
403 |
+
});
|
404 |
+
|
405 |
+
// Store initial selections
|
406 |
+
row.dataset.selectedInsights = JSON.stringify(selectedInsights);
|
407 |
+
row.dataset.unselectedInsights = JSON.stringify(unselectedInsights);
|
408 |
+
|
409 |
+
} else {
|
410 |
+
insightsContainer.innerHTML = '<div class="error">No insights found</div>';
|
411 |
+
}
|
412 |
+
})
|
413 |
+
.catch(error => {
|
414 |
+
console.error('Error:', error);
|
415 |
+
insightsContainer.innerHTML = `<div class="error">Error extracting insights: ${error.message}</div>`;
|
416 |
+
});
|
417 |
+
}
|
418 |
+
|
419 |
+
// Helper function to update selected insights stored in the row's dataset
|
420 |
+
function updateSelectedInsights(row, insightsContainer) {
|
421 |
+
const selectedInsights = [];
|
422 |
+
const unselectedInsights = [];
|
423 |
+
|
424 |
+
const tags = insightsContainer.querySelectorAll('.insight-tag');
|
425 |
+
tags.forEach(tag => {
|
426 |
+
if (tag.classList.contains('selected')) {
|
427 |
+
selectedInsights.push(tag.textContent);
|
428 |
+
} else {
|
429 |
+
unselectedInsights.push(tag.textContent);
|
430 |
+
}
|
431 |
+
});
|
432 |
+
|
433 |
+
row.dataset.selectedInsights = JSON.stringify(selectedInsights);
|
434 |
+
row.dataset.unselectedInsights = JSON.stringify(unselectedInsights);
|
435 |
+
}
|
436 |
+
|
437 |
+
// Collect all selected insights from all rows
|
438 |
+
function collectAllSelectedInsights() {
|
439 |
+
const allSelectedInsights = [];
|
440 |
+
const queryItems = document.querySelectorAll('.query-item');
|
441 |
+
|
442 |
+
queryItems.forEach(queryItem => {
|
443 |
+
const rows = queryItem.querySelectorAll('tbody tr:not(.insights-row)');
|
444 |
+
rows.forEach(row => {
|
445 |
+
if (row.dataset.selectedInsights) {
|
446 |
+
try {
|
447 |
+
const selectedInsights = JSON.parse(row.dataset.selectedInsights);
|
448 |
+
selectedInsights.forEach(insight => {
|
449 |
+
if (!allSelectedInsights.includes(insight)) {
|
450 |
+
allSelectedInsights.push(insight);
|
451 |
+
}
|
452 |
+
});
|
453 |
+
} catch (e) {
|
454 |
+
console.error('Error parsing selected insights:', e);
|
455 |
+
}
|
456 |
+
}
|
457 |
+
});
|
458 |
+
});
|
459 |
+
|
460 |
+
return allSelectedInsights;
|
461 |
+
}
|
462 |
+
|
463 |
+
// Enhance the problem using the selected insights
|
464 |
+
function enhanceProblem() {
|
465 |
+
const problemInput = document.getElementById('userInput');
|
466 |
+
const originalProblem = problemInput.value.trim();
|
467 |
+
|
468 |
+
if (!originalProblem) {
|
469 |
+
alert('Please provide a technical problem description first');
|
470 |
+
return;
|
471 |
+
}
|
472 |
+
|
473 |
+
const selectedInsights = collectAllSelectedInsights();
|
474 |
+
if (selectedInsights.length === 0) {
|
475 |
+
alert('Please select at least one insight to enhance the problem');
|
476 |
+
return;
|
477 |
+
}
|
478 |
+
|
479 |
+
// Get user comments if any
|
480 |
+
const userComments = document.getElementById('insightCommentArea')?.value || '';
|
481 |
+
|
482 |
+
// If we have stored refined problems for this exact problem, just show them
|
483 |
+
const currentProblemKey = JSON.stringify({
|
484 |
+
problem: originalProblem,
|
485 |
+
insights: selectedInsights.sort(),
|
486 |
+
comments: userComments
|
487 |
+
});
|
488 |
+
|
489 |
+
if (storedRefinedProblems[currentProblemKey]) {
|
490 |
+
showRefinedProblems(storedRefinedProblems[currentProblemKey]);
|
491 |
+
return;
|
492 |
+
}
|
493 |
+
|
494 |
+
// Show loading overlay
|
495 |
+
const loadingOverlay = document.getElementById('globalLoadingOverlay');
|
496 |
+
if (loadingOverlay) {
|
497 |
+
loadingOverlay.style.display = 'flex';
|
498 |
+
loadingOverlay.querySelector('.progress-text').textContent = 'Enhancing problem statement...';
|
499 |
+
}
|
500 |
+
|
501 |
+
// Send request to backend to refine the problem
|
502 |
+
fetch('/refine-problem', {
|
503 |
+
method: 'POST',
|
504 |
+
body: JSON.stringify({
|
505 |
+
'original_problem': originalProblem,
|
506 |
+
'insights': selectedInsights,
|
507 |
+
'user_comments': userComments
|
508 |
+
}),
|
509 |
+
headers: { 'Content-Type': 'application/json' }
|
510 |
+
})
|
511 |
+
.then(response => response.json())
|
512 |
+
.then(data => {
|
513 |
+
// Hide loading overlay
|
514 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
515 |
+
|
516 |
+
if (data.error) {
|
517 |
+
alert(`Error: ${data.error}`);
|
518 |
+
return;
|
519 |
+
}
|
520 |
+
|
521 |
+
if (data.result) {
|
522 |
+
// Add current problem to history if not already there
|
523 |
+
if (currentHistoryIndex === -1) {
|
524 |
+
problemHistory.push(originalProblem);
|
525 |
+
currentHistoryIndex = 0;
|
526 |
+
}
|
527 |
+
|
528 |
+
// Store the refined problems for future use
|
529 |
+
storedRefinedProblems[currentProblemKey] = data.result;
|
530 |
+
|
531 |
+
// Show refined problem options
|
532 |
+
showRefinedProblems(data.result);
|
533 |
+
}
|
534 |
+
})
|
535 |
+
.catch(error => {
|
536 |
+
console.error('Error:', error);
|
537 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
538 |
+
alert(`Error enhancing problem: ${error.message}`);
|
539 |
+
});
|
540 |
+
}
|
541 |
+
|
542 |
+
// Display the refined problem options
|
543 |
+
function showRefinedProblems(result) {
|
544 |
+
const refinedContainer = document.getElementById('refinedProblemContainer');
|
545 |
+
const tabs = document.getElementById('refinedProblemTabs');
|
546 |
+
const content = document.getElementById('refinedProblemContent');
|
547 |
+
|
548 |
+
// Clear previous content
|
549 |
+
tabs.innerHTML = '';
|
550 |
+
content.innerHTML = '';
|
551 |
+
|
552 |
+
// Add tabs and content for each refined problem
|
553 |
+
let isFirst = true;
|
554 |
+
for (const key in result) {
|
555 |
+
if (result.hasOwnProperty(key)) {
|
556 |
+
const problem = result[key];
|
557 |
+
|
558 |
+
// Create tab
|
559 |
+
const tab = document.createElement('div');
|
560 |
+
tab.className = `refined-problem-tab ${isFirst ? 'active' : ''}`;
|
561 |
+
tab.dataset.target = key;
|
562 |
+
tab.textContent = `Option ${key.split('_')[1]}`;
|
563 |
+
tab.onclick = function() {
|
564 |
+
document.querySelectorAll('.refined-problem-tab').forEach(t => t.classList.remove('active'));
|
565 |
+
document.querySelectorAll('.refined-problem').forEach(p => p.classList.remove('active'));
|
566 |
+
tab.classList.add('active');
|
567 |
+
document.getElementById(key).classList.add('active');
|
568 |
+
};
|
569 |
+
tabs.appendChild(tab);
|
570 |
+
|
571 |
+
// Create content
|
572 |
+
const problemDiv = document.createElement('div');
|
573 |
+
problemDiv.className = `refined-problem ${isFirst ? 'active' : ''}`;
|
574 |
+
problemDiv.id = key;
|
575 |
+
|
576 |
+
const title = document.createElement('div');
|
577 |
+
title.className = 'refined-problem-title';
|
578 |
+
title.textContent = problem.title;
|
579 |
+
|
580 |
+
const description = document.createElement('div');
|
581 |
+
description.className = 'refined-problem-description';
|
582 |
+
description.textContent = problem.description;
|
583 |
+
|
584 |
+
const applyButton = document.createElement('button');
|
585 |
+
applyButton.className = 'apply-problem-btn';
|
586 |
+
applyButton.textContent = 'Apply This Problem';
|
587 |
+
applyButton.onclick = function() {
|
588 |
+
applyRefinedProblem(problem.description);
|
589 |
+
};
|
590 |
+
|
591 |
+
problemDiv.appendChild(title);
|
592 |
+
problemDiv.appendChild(description);
|
593 |
+
problemDiv.appendChild(applyButton);
|
594 |
+
|
595 |
+
content.appendChild(problemDiv);
|
596 |
+
|
597 |
+
isFirst = false;
|
598 |
+
}
|
599 |
+
}
|
600 |
+
|
601 |
+
// Show the container
|
602 |
+
refinedContainer.style.display = 'block';
|
603 |
+
|
604 |
+
// Scroll to the container
|
605 |
+
refinedContainer.scrollIntoView({ behavior: 'smooth' });
|
606 |
+
}
|
607 |
+
|
608 |
+
// Apply the selected refined problem
|
609 |
+
function applyRefinedProblem(problemText) {
|
610 |
+
const problemInput = document.getElementById('userInput');
|
611 |
+
|
612 |
+
// Add current problem to history
|
613 |
+
problemHistory.push(problemInput.value);
|
614 |
+
currentHistoryIndex = problemHistory.length - 1; // Set to latest version
|
615 |
+
|
616 |
+
// Update problem text with the new version
|
617 |
+
problemInput.value = problemText;
|
618 |
+
|
619 |
+
// Now add the new version to history
|
620 |
+
problemHistory.push(problemText);
|
621 |
+
currentHistoryIndex = problemHistory.length - 1; // Update index to point to the newly added version
|
622 |
+
|
623 |
+
// Update history navigation display
|
624 |
+
updateHistoryNavigation();
|
625 |
+
|
626 |
+
// Display is kept visible, removed: document.getElementById('refinedProblemContainer').style.display = 'none';
|
627 |
+
|
628 |
+
// Focus on the problem input
|
629 |
+
problemInput.focus();
|
630 |
+
|
631 |
+
console.log("Problem history after applying:", problemHistory, "Current index:", currentHistoryIndex);
|
632 |
+
}
|
633 |
+
|
634 |
+
// Update the history navigation UI
|
635 |
+
function updateHistoryNavigation() {
|
636 |
+
const historyNav = document.getElementById('problemHistoryNav');
|
637 |
+
const prevBtn = historyNav.querySelector('.history-prev');
|
638 |
+
const nextBtn = historyNav.querySelector('.history-next');
|
639 |
+
const status = historyNav.querySelector('.history-status');
|
640 |
+
|
641 |
+
// Update buttons state
|
642 |
+
prevBtn.classList.toggle('disabled', currentHistoryIndex <= 0);
|
643 |
+
nextBtn.classList.toggle('disabled', currentHistoryIndex >= problemHistory.length - 1);
|
644 |
+
|
645 |
+
// Update status text
|
646 |
+
if (problemHistory.length > 0) {
|
647 |
+
status.textContent = `Version ${currentHistoryIndex + 1} of ${problemHistory.length}`;
|
648 |
+
historyNav.style.display = 'flex';
|
649 |
+
} else {
|
650 |
+
historyNav.style.display = 'none';
|
651 |
+
}
|
652 |
+
}
|
653 |
+
|
654 |
+
// Navigate to previous problem version
|
655 |
+
function navigateProblemHistory(direction) {
|
656 |
+
const problemInput = document.getElementById('userInput');
|
657 |
+
console.log("Current history index:", currentHistoryIndex, "Total history:", problemHistory.length);
|
658 |
+
|
659 |
+
if (direction === 'prev' && currentHistoryIndex > 0) {
|
660 |
+
currentHistoryIndex--;
|
661 |
+
problemInput.value = problemHistory[currentHistoryIndex];
|
662 |
+
console.log("Moving to previous version:", currentHistoryIndex);
|
663 |
+
} else if (direction === 'next' && currentHistoryIndex < problemHistory.length - 1) {
|
664 |
+
currentHistoryIndex++;
|
665 |
+
problemInput.value = problemHistory[currentHistoryIndex];
|
666 |
+
console.log("Moving to next version:", currentHistoryIndex);
|
667 |
+
}
|
668 |
+
|
669 |
+
updateHistoryNavigation();
|
670 |
+
}
|
671 |
+
|
672 |
+
function analyzePaper(paperUrl, queryItemElement) {
|
673 |
+
const patentBackground = document.getElementById('userInput').value.trim();
|
674 |
+
if (!patentBackground) {
|
675 |
+
alert('Please provide a patent background in the input field');
|
676 |
+
return;
|
677 |
+
}
|
678 |
+
|
679 |
+
// Find the row containing this URL
|
680 |
+
const rows = queryItemElement.querySelectorAll('tbody tr');
|
681 |
+
let targetRow;
|
682 |
+
let documentType = 'pdf'; // Default type
|
683 |
+
|
684 |
+
for (const row of rows) {
|
685 |
+
const urlLink = row.querySelector('.url-link');
|
686 |
+
if (urlLink && urlLink.href === paperUrl) {
|
687 |
+
targetRow = row;
|
688 |
+
// Get the document type from the first cell of the row
|
689 |
+
documentType = row.cells[0].textContent.toLowerCase();
|
690 |
+
break;
|
691 |
+
}
|
692 |
+
}
|
693 |
+
|
694 |
+
if (!targetRow) {
|
695 |
+
alert('Could not find the paper in the results table');
|
696 |
+
return;
|
697 |
+
}
|
698 |
+
|
699 |
+
// Check if we already have analysis columns
|
700 |
+
let scoreCell, justificationCell;
|
701 |
+
if (targetRow.cells.length <= 4) {
|
702 |
+
// We need to create the cells
|
703 |
+
scoreCell = document.createElement('td');
|
704 |
+
scoreCell.className = 'score-cell';
|
705 |
+
scoreCell.innerHTML = '<div class="loading-spinner"></div>';
|
706 |
+
|
707 |
+
justificationCell = document.createElement('td');
|
708 |
+
justificationCell.className = 'justification-cell';
|
709 |
+
justificationCell.innerHTML = 'Analyzing...';
|
710 |
+
|
711 |
+
targetRow.appendChild(scoreCell);
|
712 |
+
targetRow.appendChild(justificationCell);
|
713 |
+
} else {
|
714 |
+
// Use existing cells
|
715 |
+
scoreCell = targetRow.cells[4];
|
716 |
+
justificationCell = targetRow.cells[5];
|
717 |
+
scoreCell.innerHTML = '<div class="loading-spinner"></div>';
|
718 |
+
justificationCell.innerHTML = 'Analyzing...';
|
719 |
+
}
|
720 |
+
|
721 |
+
// Send analysis request to backend
|
722 |
+
fetch('/analyze', {
|
723 |
+
method: 'POST',
|
724 |
+
body: JSON.stringify({
|
725 |
+
'patent_background': patentBackground,
|
726 |
+
'pdf_url': paperUrl,
|
727 |
+
'data_type': documentType
|
728 |
+
}),
|
729 |
+
headers: { 'Content-Type': 'application/json' }
|
730 |
+
})
|
731 |
+
.then(response => response.json())
|
732 |
+
.then(data => {
|
733 |
+
if (data.error) {
|
734 |
+
scoreCell.innerHTML = 'Error';
|
735 |
+
justificationCell.innerHTML = data.error;
|
736 |
+
} else if (data.result) {
|
737 |
+
// Get score and justification from the result
|
738 |
+
const result = data.result;
|
739 |
+
const score = result.score !== undefined ? result.score : 'N/A';
|
740 |
+
const justification = result.justification || 'No justification provided';
|
741 |
+
|
742 |
+
// Update cells with results
|
743 |
+
scoreCell.innerHTML = score;
|
744 |
+
justificationCell.innerHTML = justification;
|
745 |
+
|
746 |
+
// Color-code the score
|
747 |
+
if (score >= 0 && score <= 5) {
|
748 |
+
const redComponent = Math.floor((score / 5) * 255);
|
749 |
+
const greenComponent = Math.floor(((5 - score) / 5) * 255);
|
750 |
+
scoreCell.style.backgroundColor = `rgb(${redComponent}, ${greenComponent}, 0)`;
|
751 |
+
scoreCell.style.color = 'white';
|
752 |
+
scoreCell.style.fontWeight = 'bold';
|
753 |
+
scoreCell.style.textAlign = 'center';
|
754 |
+
}
|
755 |
+
|
756 |
+
// Add "Extract Insights" button to the justify cell
|
757 |
+
const insightsButton = document.createElement('button');
|
758 |
+
insightsButton.textContent = 'Extract Insights';
|
759 |
+
insightsButton.className = 'action-button insights-button';
|
760 |
+
insightsButton.style.marginTop = '5px';
|
761 |
+
insightsButton.style.fontSize = '0.8em';
|
762 |
+
insightsButton.onclick = function(e) {
|
763 |
+
e.preventDefault();
|
764 |
+
extractInsights(paperUrl, targetRow);
|
765 |
+
};
|
766 |
+
justificationCell.appendChild(document.createElement('br'));
|
767 |
+
justificationCell.appendChild(insightsButton);
|
768 |
+
} else {
|
769 |
+
scoreCell.innerHTML = 'No data';
|
770 |
+
justificationCell.innerHTML = 'Analysis failed';
|
771 |
+
}
|
772 |
+
})
|
773 |
+
.catch(error => {
|
774 |
+
console.error('Error:', error);
|
775 |
+
scoreCell.innerHTML = 'Error';
|
776 |
+
justificationCell.innerHTML = 'Failed to analyze paper';
|
777 |
+
});
|
778 |
+
}
|
779 |
+
|
780 |
+
// Update the placeholder text numbers after deletions
|
781 |
+
function updateQueryIndices() {
|
782 |
+
const queryItems = document.getElementById('queriesContainer').children;
|
783 |
+
for (let i = 0; i < queryItems.length; i++) {
|
784 |
+
const queryField = queryItems[i].querySelector('.query-field');
|
785 |
+
queryField.placeholder = `Search Query ${i + 1}`;
|
786 |
+
}
|
787 |
+
}
|
788 |
+
|
789 |
+
// Get all queries as an array of strings
|
790 |
+
function getQueries() {
|
791 |
+
const queryFields = document.querySelectorAll('.query-field');
|
792 |
+
return Array.from(queryFields).map(field => field.value.trim());
|
793 |
+
}
|
794 |
+
|
795 |
+
// Analyze all unanalyzed papers in the results
|
796 |
+
function analyzeAllPapers() {
|
797 |
+
// Show loading overlay
|
798 |
+
const loadingOverlay = document.getElementById('globalLoadingOverlay');
|
799 |
+
if (loadingOverlay) loadingOverlay.style.display = 'flex';
|
800 |
+
|
801 |
+
// Get all query items
|
802 |
+
const queryItems = document.querySelectorAll('.query-item');
|
803 |
+
let totalToAnalyze = 0;
|
804 |
+
let completedAnalyses = 0;
|
805 |
+
|
806 |
+
// Count total papers that need analysis
|
807 |
+
queryItems.forEach(queryItem => {
|
808 |
+
const rows = queryItem.querySelectorAll('tbody tr');
|
809 |
+
rows.forEach(row => {
|
810 |
+
if (row.cells.length <= 4 || row.cells[4].textContent.trim() === 'Error' ||
|
811 |
+
row.cells[4].textContent.trim() === 'N/A' || row.cells[4].textContent.trim() === '') {
|
812 |
+
totalToAnalyze++;
|
813 |
+
}
|
814 |
+
});
|
815 |
+
});
|
816 |
+
|
817 |
+
if (totalToAnalyze === 0) {
|
818 |
+
alert('No papers need analysis');
|
819 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
820 |
+
return;
|
821 |
+
}
|
822 |
+
|
823 |
+
// Function to update progress
|
824 |
+
function updateProgress() {
|
825 |
+
completedAnalyses++;
|
826 |
+
if (loadingOverlay) {
|
827 |
+
const progressElement = loadingOverlay.querySelector('.progress-text');
|
828 |
+
if (progressElement) {
|
829 |
+
progressElement.textContent = `Analyzing papers: ${completedAnalyses}/${totalToAnalyze}`;
|
830 |
+
}
|
831 |
+
}
|
832 |
+
|
833 |
+
if (completedAnalyses >= totalToAnalyze) {
|
834 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
835 |
+
}
|
836 |
+
}
|
837 |
+
|
838 |
+
// Analyze each paper that needs it
|
839 |
+
queryItems.forEach(queryItem => {
|
840 |
+
const rows = queryItem.querySelectorAll('tbody tr');
|
841 |
+
rows.forEach(row => {
|
842 |
+
// Check if this row needs analysis
|
843 |
+
if (row.cells.length <= 4 || row.cells[4].textContent.trim() === 'Error' ||
|
844 |
+
row.cells[4].textContent.trim() === 'N/A' || row.cells[4].textContent.trim() === '') {
|
845 |
+
|
846 |
+
// Get the URL
|
847 |
+
const urlLink = row.querySelector('.url-link');
|
848 |
+
const documentType = row.cells[0].textContent.toLowerCase();
|
849 |
+
if (urlLink && urlLink.href) {
|
850 |
+
// Create a promise for this analysis
|
851 |
+
const promise = new Promise((resolve) => {
|
852 |
+
// Prepare for analysis
|
853 |
+
const patentBackground = document.getElementById('userInput').value.trim();
|
854 |
+
|
855 |
+
// Create score and justification cells if needed
|
856 |
+
let scoreCell, justificationCell;
|
857 |
+
if (row.cells.length <= 4) {
|
858 |
+
scoreCell = document.createElement('td');
|
859 |
+
scoreCell.className = 'score-cell';
|
860 |
+
scoreCell.innerHTML = '<div class="loading-spinner"></div>';
|
861 |
+
|
862 |
+
justificationCell = document.createElement('td');
|
863 |
+
justificationCell.className = 'justification-cell';
|
864 |
+
justificationCell.innerHTML = 'Analyzing...';
|
865 |
+
|
866 |
+
row.appendChild(scoreCell);
|
867 |
+
row.appendChild(justificationCell);
|
868 |
+
} else {
|
869 |
+
scoreCell = row.cells[4];
|
870 |
+
justificationCell = row.cells[5];
|
871 |
+
scoreCell.innerHTML = '<div class="loading-spinner"></div>';
|
872 |
+
justificationCell.innerHTML = 'Analyzing...';
|
873 |
+
}
|
874 |
+
|
875 |
+
// Send analysis request
|
876 |
+
fetch('/analyze', {
|
877 |
+
method: 'POST',
|
878 |
+
body: JSON.stringify({
|
879 |
+
'patent_background': patentBackground,
|
880 |
+
'pdf_url': urlLink.href,
|
881 |
+
'data_type': documentType
|
882 |
+
}),
|
883 |
+
headers: { 'Content-Type': 'application/json' }
|
884 |
+
})
|
885 |
+
.then(response => response.json())
|
886 |
+
.then(data => {
|
887 |
+
if (data.error) {
|
888 |
+
scoreCell.innerHTML = 'Error';
|
889 |
+
justificationCell.innerHTML = data.error;
|
890 |
+
} else if (data.result) {
|
891 |
+
// Get score and justification
|
892 |
+
const result = data.result;
|
893 |
+
const score = result.score !== undefined ? result.score : 'N/A';
|
894 |
+
const justification = result.justification || 'No justification provided';
|
895 |
+
|
896 |
+
// Update cells
|
897 |
+
scoreCell.innerHTML = score;
|
898 |
+
justificationCell.innerHTML = justification;
|
899 |
+
|
900 |
+
// Color-code score
|
901 |
+
if (score >= 0 && score <= 5) {
|
902 |
+
const redComponent = Math.floor((score / 5) * 255);
|
903 |
+
const greenComponent = Math.floor(((5 - score) / 5) * 255);
|
904 |
+
scoreCell.style.backgroundColor = `rgb(${redComponent}, ${greenComponent}, 0)`;
|
905 |
+
scoreCell.style.color = 'white';
|
906 |
+
scoreCell.style.fontWeight = 'bold';
|
907 |
+
scoreCell.style.textAlign = 'center';
|
908 |
+
}
|
909 |
+
} else {
|
910 |
+
scoreCell.innerHTML = 'No data';
|
911 |
+
justificationCell.innerHTML = 'Analysis failed';
|
912 |
+
}
|
913 |
+
resolve();
|
914 |
+
})
|
915 |
+
.catch(error => {
|
916 |
+
console.error('Error:', error);
|
917 |
+
scoreCell.innerHTML = 'Error';
|
918 |
+
justificationCell.innerHTML = 'Failed to analyze paper';
|
919 |
+
resolve();
|
920 |
+
});
|
921 |
+
});
|
922 |
+
|
923 |
+
// When this analysis is done, update the progress
|
924 |
+
promise.then(() => {
|
925 |
+
updateProgress();
|
926 |
+
});
|
927 |
+
} else {
|
928 |
+
// No URL found, count as completed
|
929 |
+
updateProgress();
|
930 |
+
}
|
931 |
+
}
|
932 |
+
});
|
933 |
+
});
|
934 |
+
}
|
935 |
+
|
936 |
+
// Remove rows with failed analyses
|
937 |
+
function removeFailedAnalyses() {
|
938 |
+
const queryItems = document.querySelectorAll('.query-item');
|
939 |
+
let removedCount = 0;
|
940 |
+
|
941 |
+
queryItems.forEach(queryItem => {
|
942 |
+
const tbody = queryItem.querySelector('tbody');
|
943 |
+
const rows = Array.from(tbody.querySelectorAll('tr'));
|
944 |
+
|
945 |
+
rows.forEach(row => {
|
946 |
+
if (row.cells.length > 4) {
|
947 |
+
const scoreText = row.cells[4].textContent.trim();
|
948 |
+
if (scoreText === 'Error' || scoreText === 'N/A' || scoreText === 'No data') {
|
949 |
+
tbody.removeChild(row);
|
950 |
+
removedCount++;
|
951 |
+
}
|
952 |
+
}
|
953 |
+
});
|
954 |
+
});
|
955 |
+
|
956 |
+
alert(`Removed ${removedCount} papers with failed analyses`);
|
957 |
+
}
|
958 |
+
|
959 |
+
// Export all tables to Excel
|
960 |
+
function exportToExcel() {
|
961 |
+
// Show loading overlay
|
962 |
+
const loadingOverlay = document.getElementById('globalLoadingOverlay');
|
963 |
+
if (loadingOverlay) {
|
964 |
+
loadingOverlay.style.display = 'flex';
|
965 |
+
loadingOverlay.querySelector('.progress-text').textContent = 'Generating Excel file...';
|
966 |
+
}
|
967 |
+
|
968 |
+
try {
|
969 |
+
// Collect all data from all tables
|
970 |
+
const allData = [];
|
971 |
+
const queryItems = document.querySelectorAll('.query-item');
|
972 |
+
|
973 |
+
queryItems.forEach(queryItem => {
|
974 |
+
// Get the search query text for this table
|
975 |
+
const queryText = queryItem.querySelector('.query-field').value;
|
976 |
+
|
977 |
+
// Get all rows in this table
|
978 |
+
const rows = queryItem.querySelectorAll('tbody tr:not(.insights-row)');
|
979 |
+
|
980 |
+
rows.forEach(row => {
|
981 |
+
// Skip empty rows or error rows
|
982 |
+
if (row.cells.length === 1 && row.cells[0].colSpan > 1) {
|
983 |
+
return; // Skip "No results found" rows
|
984 |
+
}
|
985 |
+
|
986 |
+
// Prepare object for this row
|
987 |
+
const rowData = {
|
988 |
+
'Topic': queryText,
|
989 |
+
'Type': row.cells[0].textContent,
|
990 |
+
'Title': row.cells[1].textContent,
|
991 |
+
'Description': row.cells[2].textContent,
|
992 |
+
'URL': row.querySelector('.url-link')?.href || ''
|
993 |
+
};
|
994 |
+
|
995 |
+
// Add score and justification if they exist
|
996 |
+
if (row.cells.length > 4) {
|
997 |
+
rowData['Score'] = row.cells[4].textContent;
|
998 |
+
rowData['Justification'] = row.cells[5].textContent.split('\n')[0]; // Only get the justification text
|
999 |
+
} else {
|
1000 |
+
rowData['Score'] = '';
|
1001 |
+
rowData['Justification'] = '';
|
1002 |
+
}
|
1003 |
+
|
1004 |
+
// Add selected and unselected insights if they exist
|
1005 |
+
if (row.dataset.selectedInsights) {
|
1006 |
+
try {
|
1007 |
+
const selectedInsights = JSON.parse(row.dataset.selectedInsights);
|
1008 |
+
rowData['Selected Insights'] = selectedInsights.join('; ');
|
1009 |
+
} catch (e) {
|
1010 |
+
rowData['Selected Insights'] = '';
|
1011 |
+
}
|
1012 |
+
} else {
|
1013 |
+
rowData['Selected Insights'] = '';
|
1014 |
+
}
|
1015 |
+
|
1016 |
+
if (row.dataset.unselectedInsights) {
|
1017 |
+
try {
|
1018 |
+
const unselectedInsights = JSON.parse(row.dataset.unselectedInsights);
|
1019 |
+
rowData['Unselected Insights'] = unselectedInsights.join('; ');
|
1020 |
+
} catch (e) {
|
1021 |
+
rowData['Unselected Insights'] = '';
|
1022 |
+
}
|
1023 |
+
} else {
|
1024 |
+
rowData['Unselected Insights'] = '';
|
1025 |
+
}
|
1026 |
+
|
1027 |
+
allData.push(rowData);
|
1028 |
+
});
|
1029 |
+
});
|
1030 |
+
|
1031 |
+
// Check if we have any data
|
1032 |
+
if (allData.length === 0) {
|
1033 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
1034 |
+
alert('No data to export. Please perform a search first.');
|
1035 |
+
return;
|
1036 |
+
}
|
1037 |
+
|
1038 |
+
// Get all problem versions
|
1039 |
+
const problemVersions = {};
|
1040 |
+
if (problemHistory.length > 0) {
|
1041 |
+
problemHistory.forEach((problem, index) => {
|
1042 |
+
problemVersions[`Problem Version ${index + 1}`] = problem;
|
1043 |
+
});
|
1044 |
+
} else {
|
1045 |
+
// If no history, just use the current problem
|
1046 |
+
const currentProblem = document.getElementById('userInput').value.trim();
|
1047 |
+
if (currentProblem) {
|
1048 |
+
problemVersions['Problem Version 1'] = currentProblem;
|
1049 |
+
}
|
1050 |
+
}
|
1051 |
+
|
1052 |
+
// Send to server for Excel generation
|
1053 |
+
fetch('/export-excel', {
|
1054 |
+
method: 'POST',
|
1055 |
+
body: JSON.stringify({
|
1056 |
+
'tableData': allData,
|
1057 |
+
'userQuery': document.getElementById('userInput').value,
|
1058 |
+
'problemVersions': problemVersions
|
1059 |
+
}),
|
1060 |
+
headers: { 'Content-Type': 'application/json' }
|
1061 |
+
})
|
1062 |
+
.then(response => {
|
1063 |
+
if (!response.ok) {
|
1064 |
+
throw new Error(`Server error: ${response.status}`);
|
1065 |
+
}
|
1066 |
+
return response.blob();
|
1067 |
+
})
|
1068 |
+
.then(blob => {
|
1069 |
+
// Hide loading overlay
|
1070 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
1071 |
+
|
1072 |
+
// Create URL for the blob
|
1073 |
+
const url = window.URL.createObjectURL(new Blob([blob], {
|
1074 |
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
1075 |
+
}));
|
1076 |
+
|
1077 |
+
// Create a link and trigger download
|
1078 |
+
const a = document.createElement('a');
|
1079 |
+
a.href = url;
|
1080 |
+
a.download = 'patent_search_results.xlsx';
|
1081 |
+
document.body.appendChild(a);
|
1082 |
+
a.click();
|
1083 |
+
|
1084 |
+
// Clean up
|
1085 |
+
window.URL.revokeObjectURL(url);
|
1086 |
+
document.body.removeChild(a);
|
1087 |
+
})
|
1088 |
+
.catch(error => {
|
1089 |
+
console.error('Error exporting to Excel:', error);
|
1090 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
1091 |
+
alert(`Error exporting to Excel: ${error.message}`);
|
1092 |
+
});
|
1093 |
+
} catch (error) {
|
1094 |
+
console.error('Error preparing Excel data:', error);
|
1095 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
1096 |
+
alert(`Error preparing data for export: ${error.message}`);
|
1097 |
+
}
|
1098 |
+
}
|
1099 |
+
|
1100 |
+
// Check if any insights are selected to enable/disable enhance button
|
1101 |
+
function checkSelectedInsights() {
|
1102 |
+
const selectedInsights = collectAllSelectedInsights();
|
1103 |
+
const enhanceButton = document.getElementById('enhanceProblemButton');
|
1104 |
+
|
1105 |
+
if (selectedInsights.length > 0) {
|
1106 |
+
enhanceButton.classList.remove('disabled');
|
1107 |
+
enhanceButton.disabled = false;
|
1108 |
+
} else {
|
1109 |
+
enhanceButton.classList.add('disabled');
|
1110 |
+
enhanceButton.disabled = true;
|
1111 |
+
}
|
1112 |
+
}
|
1113 |
+
|
1114 |
+
// Initialize comment area for insights
|
1115 |
+
function initializeCommentArea() {
|
1116 |
+
const container = document.getElementById('insightCommentContainer');
|
1117 |
+
if (!container) return;
|
1118 |
+
|
1119 |
+
const textarea = document.createElement('textarea');
|
1120 |
+
textarea.id = 'insightCommentArea';
|
1121 |
+
textarea.className = 'insight-comment-textarea';
|
1122 |
+
textarea.placeholder = 'Add additional suggestions for enhancing the problem (optional)...';
|
1123 |
+
|
1124 |
+
container.innerHTML = '';
|
1125 |
+
container.appendChild(textarea);
|
1126 |
+
}
|
1127 |
+
</script>
|
1128 |
+
</head>
|
1129 |
+
<body>
|
1130 |
+
<div class="container">
|
1131 |
+
<header class="header">
|
1132 |
+
<div class="logo">
|
1133 |
+
<div class="logo-icon">P</div>
|
1134 |
+
<h1>Patentability</h1>
|
1135 |
+
</div>
|
1136 |
+
<p>Enter a detailed description of your technical problem to generate search queries for finding relevant research papers.</p>
|
1137 |
+
</header>
|
1138 |
+
|
1139 |
+
<section class="card">
|
1140 |
+
<form id="queryForm" onsubmit="generateQueries(event)">
|
1141 |
+
<div class="form-group">
|
1142 |
+
<label for="userInput">Technical Problem Description:</label>
|
1143 |
+
<div class="problem-history">
|
1144 |
+
<div id="problemHistoryNav" class="problem-history-nav" style="display: none;">
|
1145 |
+
<div class="history-arrow history-prev disabled" onclick="navigateProblemHistory('prev')">←</div>
|
1146 |
+
<div class="history-arrow history-next disabled" onclick="navigateProblemHistory('next')">→</div>
|
1147 |
+
<div class="history-status"></div>
|
1148 |
+
</div>
|
1149 |
+
<textarea id="userInput" placeholder="Describe your technical problem in detail..." required></textarea>
|
1150 |
+
</div>
|
1151 |
+
</div>
|
1152 |
+
|
1153 |
+
<button type="submit" class="btn btn-primary">Generate Search Queries</button>
|
1154 |
+
</form>
|
1155 |
+
|
1156 |
+
<div id="loadingIndicator">
|
1157 |
+
<div class="loading-spinner"></div>
|
1158 |
+
<p>Generating search queries... Please wait.</p>
|
1159 |
+
</div>
|
1160 |
+
|
1161 |
+
<div id="insightCommentContainer" class="insight-comment-area"></div>
|
1162 |
+
|
1163 |
+
<div id="refinedProblemContainer" class="refined-problem-container" style="display: none;">
|
1164 |
+
<div id="refinedProblemTabs" class="refined-problem-tabs"></div>
|
1165 |
+
<div id="refinedProblemContent" class="refined-problem-content"></div>
|
1166 |
+
</div>
|
1167 |
+
</section>
|
1168 |
+
|
1169 |
+
<section class="search-options">
|
1170 |
+
<label>Search Options:</label>
|
1171 |
+
<div class="checkbox-group">
|
1172 |
+
<div class="checkbox-item">
|
1173 |
+
<input type="checkbox" id="pdfOption" name="searchOptions" value="pdf" checked>
|
1174 |
+
<label for="pdfOption">PDF</label>
|
1175 |
+
</div>
|
1176 |
+
<div class="checkbox-item">
|
1177 |
+
<input type="checkbox" id="patentOption" name="searchOptions" value="patent">
|
1178 |
+
<label for="patentOption">Patent</label>
|
1179 |
+
</div>
|
1180 |
+
<div class="checkbox-item">
|
1181 |
+
<input type="checkbox" id="webOption" name="searchOptions" value="web">
|
1182 |
+
<label for="webOption">Web</label>
|
1183 |
+
</div>
|
1184 |
+
</div>
|
1185 |
+
</section>
|
1186 |
+
|
1187 |
+
<section id="resultsContainer">
|
1188 |
+
<h2>Generated Search Queries</h2>
|
1189 |
+
|
1190 |
+
<div id="queriesContainer">
|
1191 |
+
<!-- Query fields will be added here dynamically -->
|
1192 |
+
</div>
|
1193 |
+
|
1194 |
+
<div class="button-container">
|
1195 |
+
<button type="button" class="btn btn-secondary" onclick="addQueryField()">
|
1196 |
+
<span>Add New Query</span>
|
1197 |
+
</button>
|
1198 |
+
</div>
|
1199 |
+
</section>
|
1200 |
+
</div>
|
1201 |
+
|
1202 |
+
<!-- Global action buttons (floating) -->
|
1203 |
+
<div class="floating-buttons">
|
1204 |
+
<button id="enhanceProblemButton" class="btn enhance-problem-button floating-button disabled" title="Enhance Problem using Selected Insights" onclick="enhanceProblem()" disabled>
|
1205 |
+
Enhance Problem
|
1206 |
+
</button>
|
1207 |
+
<button id="analyzeAllButton" class="btn btn-primary floating-button" title="Analyze All Unanalyzed Papers">
|
1208 |
+
Analyze All
|
1209 |
+
</button>
|
1210 |
+
<button id="removeFailedButton" class="btn btn-danger floating-button" title="Remove Papers with Failed Analyses">
|
1211 |
+
Remove Failed
|
1212 |
+
</button>
|
1213 |
+
<button id="exportExcelButton" class="btn btn-success floating-button" title="Export All Data to Excel">
|
1214 |
+
Export to Excel
|
1215 |
+
</button>
|
1216 |
+
</div>
|
1217 |
+
|
1218 |
+
<!-- Global loading overlay -->
|
1219 |
+
<div id="globalLoadingOverlay" class="loading-overlay">
|
1220 |
+
<div class="loading-content">
|
1221 |
+
<div class="loading-spinner"></div>
|
1222 |
+
<div class="progress-text">Processing...</div>
|
1223 |
+
</div>
|
1224 |
+
</div>
|
1225 |
+
|
1226 |
+
<script>
|
1227 |
+
// Add event listeners for floating buttons
|
1228 |
+
document.addEventListener('DOMContentLoaded', function() {
|
1229 |
+
// Initialize the comment area
|
1230 |
+
initializeCommentArea();
|
1231 |
+
|
1232 |
+
// Check for selected insights periodically to enable/disable enhance button
|
1233 |
+
setInterval(checkSelectedInsights, 1000);
|
1234 |
+
|
1235 |
+
// Analyze all button
|
1236 |
+
document.getElementById('analyzeAllButton').addEventListener('click', function() {
|
1237 |
+
analyzeAllPapers();
|
1238 |
+
});
|
1239 |
+
|
1240 |
+
// Remove failed button
|
1241 |
+
document.getElementById('removeFailedButton').addEventListener('click', function() {
|
1242 |
+
removeFailedAnalyses();
|
1243 |
+
});
|
1244 |
+
|
1245 |
+
// Export to Excel button
|
1246 |
+
document.getElementById('exportExcelButton').addEventListener('click', function() {
|
1247 |
+
exportToExcel();
|
1248 |
+
});
|
1249 |
+
});
|
1250 |
+
</script>
|
1251 |
+
</body>
|
1252 |
+
</html>
|