Spaces:
Sleeping
Sleeping
First version
Browse files- Dockerfile +13 -0
- app.py +627 -0
- requirements.txt +12 -0
- static/script.js +2139 -0
- static/style.css +1319 -0
- templates/index.html +186 -0
Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10.3
|
2 |
+
|
3 |
+
RUN useradd -m -u 1000 user
|
4 |
+
USER user
|
5 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
6 |
+
|
7 |
+
WORKDIR /app
|
8 |
+
|
9 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
10 |
+
RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --no-cache-dir --upgrade -r requirements.txt
|
11 |
+
|
12 |
+
COPY --chown=user . /app
|
13 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
@@ -0,0 +1,627 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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duckgo_search import DDGS
|
5 |
+
import httpx
|
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 |
+
from groq import Groq
|
14 |
+
import os
|
15 |
+
|
16 |
+
|
17 |
+
app = Flask(__name__)
|
18 |
+
|
19 |
+
search_prompt = """
|
20 |
+
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:
|
21 |
+
1. Be crafted to find research papers, articles, or academic resources that address similar issues or solutions.
|
22 |
+
2. Be focused and precise, avoiding generic or overly broad terms.
|
23 |
+
Provide the search queries in the following **JSON format**. There should be no extra text, only the search queries as values.
|
24 |
+
**Example Output:**
|
25 |
+
```json
|
26 |
+
{
|
27 |
+
"1": "user authentication 5G cryptographic keys identity management",
|
28 |
+
"2": "5G authentication security issues cryptography 3GPP key management"
|
29 |
+
}
|
30 |
+
```
|
31 |
+
"""
|
32 |
+
|
33 |
+
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.
|
34 |
+
# Instructions:
|
35 |
+
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.
|
36 |
+
Analyze the Document: Review the provided document. Focus on identifying any problems that are similar to those mentioned in the patent background.
|
37 |
+
Evaluate Coverage: Assess how well the document covers the problems mentioned in the patent. Use the following scoring system:
|
38 |
+
Score 5: The document explicitly discusses the same problems as the patent, indicating that the problems are not novel.
|
39 |
+
Score 4: The document discusses problems that are very similar to those in the patent, significantly impacting the novelty of the patent's problems.
|
40 |
+
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.
|
41 |
+
Score 2: The document mentions problems that are similar in some ways but are clearly different from those in the patent.
|
42 |
+
Score 1: The document touches upon related problems but does not directly address the specific problems mentioned in the patent.
|
43 |
+
Score 0: The document does not discuss any problems related to those in the patent.
|
44 |
+
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.
|
45 |
+
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.
|
46 |
+
# Output Format:
|
47 |
+
No details or explanations are required, just the results in the required **JSON** format with no additional word.
|
48 |
+
{
|
49 |
+
'score': [Your Score],
|
50 |
+
'justification': "[Your Justification]"
|
51 |
+
}
|
52 |
+
"""
|
53 |
+
|
54 |
+
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.
|
55 |
+
# Instructions:
|
56 |
+
1. Identify 3-5 key insights from the document that could enhance or inform the patent problem.
|
57 |
+
2. Each insight should be concise (max 10 words) but informative.
|
58 |
+
3. Focus on technical elements that could be valuable for improving the patent.
|
59 |
+
# Output Format:
|
60 |
+
Return only a JSON object with insights as an array, with no additional text:
|
61 |
+
{
|
62 |
+
"insights": [
|
63 |
+
"Security vulnerability in authentication handshake",
|
64 |
+
"Novel quantum encryption protocol",
|
65 |
+
"Lightweight implementation for IoT devices",
|
66 |
+
"Privacy-preserving key exchange mechanism",
|
67 |
+
"Real-time threat detection algorithm"
|
68 |
+
]
|
69 |
+
}
|
70 |
+
"""
|
71 |
+
|
72 |
+
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.
|
73 |
+
# Instructions:
|
74 |
+
1. Carefully review the initial technical problem.
|
75 |
+
2. Consider the selected insights from technical documents that could enhance the problem formulation.
|
76 |
+
3. If any user comments are provided, incorporate those suggestions into your refinement process.
|
77 |
+
4. Generate TWO distinct refined problem statements that:
|
78 |
+
- Integrate the selected insights in a meaningful way
|
79 |
+
- Make the problem more sophisticated and technically interesting
|
80 |
+
- Increase the novelty and inventive potential of any solution
|
81 |
+
- Add appropriate constraints and technical requirements
|
82 |
+
- Maintain coherence and technical feasibility
|
83 |
+
- Suggest innovative directions without fully solving the problem
|
84 |
+
# Output Format:
|
85 |
+
Return the results in **strictly valid JSON** format with no additional text.
|
86 |
+
All string values (especially multiline descriptions) must:
|
87 |
+
- Be enclosed in double quotes
|
88 |
+
- Escape internal double quotes with backslashes (e.g., \")
|
89 |
+
- Replace newline characters with "\\n" (double backslash-n for JSON)
|
90 |
+
- Avoid unescaped Markdown if it breaks JSON syntax
|
91 |
+
Reference json:
|
92 |
+
{
|
93 |
+
"refined_problem_1": {
|
94 |
+
"title": "Brief descriptive title for the first refined problem",
|
95 |
+
"description": "Comprehensive description of the first refined problem that integrates insights and adds sophistication"
|
96 |
+
},
|
97 |
+
"refined_problem_2": {
|
98 |
+
"title": "Brief descriptive title for the second refined problem",
|
99 |
+
"description": "Alternative comprehensive description that takes a different approach to refining the problem"
|
100 |
+
}
|
101 |
+
}
|
102 |
+
"""
|
103 |
+
|
104 |
+
def ask_llm(user_message, model='llama-3.3-70b-versatile', system_prompt="You are a helpful assistant."):
|
105 |
+
client = Groq(api_key="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", http_client=httpx.Client(verify=False))
|
106 |
+
|
107 |
+
response = client.chat.completions.create(
|
108 |
+
model=model,
|
109 |
+
messages=[
|
110 |
+
{
|
111 |
+
"role": "system",
|
112 |
+
"content": system_prompt
|
113 |
+
},
|
114 |
+
{
|
115 |
+
"role": "user",
|
116 |
+
"content": user_message
|
117 |
+
}
|
118 |
+
],
|
119 |
+
stream=False,
|
120 |
+
)
|
121 |
+
|
122 |
+
return response.choices[0].message.content
|
123 |
+
|
124 |
+
def ask_ollama(user_message, model='llama-3.3-70b-versatile', system_prompt=search_prompt):
|
125 |
+
client = Groq(api_key="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", http_client=httpx.Client(verify=False))
|
126 |
+
|
127 |
+
response = client.chat.completions.create(
|
128 |
+
model=model,
|
129 |
+
messages=[
|
130 |
+
{
|
131 |
+
"role": "system",
|
132 |
+
"content": system_prompt
|
133 |
+
},
|
134 |
+
{
|
135 |
+
"role": "user",
|
136 |
+
"content": user_message
|
137 |
+
}
|
138 |
+
],
|
139 |
+
stream=False,
|
140 |
+
)
|
141 |
+
|
142 |
+
ai_reply = response.choices[0].message.content
|
143 |
+
print(f"AI REPLY json:\n{ai_reply}")
|
144 |
+
|
145 |
+
# Process the response to ensure we return valid JSON
|
146 |
+
try:
|
147 |
+
# First, try to parse it directly in case it's already valid JSON
|
148 |
+
print(f"AI REPLY:\n{ai_reply}")
|
149 |
+
return ast.literal_eval(ai_reply.replace('json\n', '').replace('```', ''))
|
150 |
+
except Exception as e:
|
151 |
+
print(f"ERROR:\n{e}")
|
152 |
+
# If it's not valid JSON, try to extract JSON from the text
|
153 |
+
return {
|
154 |
+
"1": "Error parsing response. Please try again.",
|
155 |
+
"2": "Error parsing response. Please try again."
|
156 |
+
}
|
157 |
+
|
158 |
+
def search_web(topic, max_references=5, data_type="pdf"):
|
159 |
+
"""Search the web using DuckDuckGo and return results."""
|
160 |
+
doc_list = []
|
161 |
+
with DDGS(verify=False) as ddgs:
|
162 |
+
i = 0
|
163 |
+
for r in ddgs.text(topic, region='wt-wt', safesearch='On', timelimit='n'):
|
164 |
+
if i >= max_references:
|
165 |
+
break
|
166 |
+
doc_list.append({"type": data_type, "title": r['title'], "body": r['body'], "url": r['href']})
|
167 |
+
i += 1
|
168 |
+
return doc_list
|
169 |
+
|
170 |
+
def analyze_pdf_novelty(patent_background, url, data_type="pdf"):
|
171 |
+
"""Extract full document text from PDF or background from patent and evaluate novelty"""
|
172 |
+
try:
|
173 |
+
# Disable SSL warnings
|
174 |
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
175 |
+
# Extract text based on the type
|
176 |
+
if data_type == "pdf":
|
177 |
+
headers = {
|
178 |
+
"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",
|
179 |
+
"Accept": "application/pdf"
|
180 |
+
}
|
181 |
+
|
182 |
+
response = requests.get(url, headers=headers, timeout=20, verify=False)
|
183 |
+
if response.status_code != 200:
|
184 |
+
print(f"Failed to download PDF (status code: {response.status_code})")
|
185 |
+
return {"error": f"Failed to download PDF (status code: {response.status_code})"}
|
186 |
+
|
187 |
+
# Extract full document text (limited to 6000 characters)
|
188 |
+
try:
|
189 |
+
pdf_document = fitz.open(stream=response.content, filetype="pdf")
|
190 |
+
if pdf_document.page_count == 0:
|
191 |
+
return {"error": "PDF has no pages"}
|
192 |
+
|
193 |
+
text = ""
|
194 |
+
for page_num in range(min(5, pdf_document.page_count)): # Limit to first 5 pages
|
195 |
+
page = pdf_document.load_page(page_num)
|
196 |
+
text += page.get_text() + " "
|
197 |
+
if len(text) >= 6000:
|
198 |
+
break
|
199 |
+
|
200 |
+
text = text[:6000] # Limit to 6000 characters
|
201 |
+
except Exception as e:
|
202 |
+
return {"error": f"Error processing PDF: {str(e)}"}
|
203 |
+
|
204 |
+
elif data_type == "patent":
|
205 |
+
# Extract background from patent
|
206 |
+
print("extract from patent")
|
207 |
+
try:
|
208 |
+
response = requests.get(url, timeout=20, verify=False)
|
209 |
+
if response.status_code != 200:
|
210 |
+
print(f"Failed to access patent (status code: {response.status_code})")
|
211 |
+
return {"error": f"Failed to access patent (status code: {response.status_code})"}
|
212 |
+
content = response.content.decode('utf-8').replace("\n", "")
|
213 |
+
soup = BeautifulSoup(content, 'html.parser')
|
214 |
+
section = soup.find('section', itemprop='description', itemscope='')
|
215 |
+
matches = re.findall(r"background(.*?)(?:summary|description of the drawing)", str(section), re.DOTALL | re.IGNORECASE)
|
216 |
+
if matches:
|
217 |
+
text = BeautifulSoup(matches[0], "html.parser").get_text(separator=" ").strip()
|
218 |
+
else:
|
219 |
+
text = "Background section not found in patent."
|
220 |
+
except Exception as e:
|
221 |
+
return {"error": f"Error processing patent: {str(e)}"}
|
222 |
+
elif data_type == "web":
|
223 |
+
try:
|
224 |
+
headers = {
|
225 |
+
"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",
|
226 |
+
"Accept": "application/pdf"
|
227 |
+
}
|
228 |
+
response = requests.get(url, headers=headers, timeout=20, verify=False)
|
229 |
+
response.raise_for_status()
|
230 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
231 |
+
full_text = soup.get_text()
|
232 |
+
text = re.sub(r'\n+', ' ', full_text)[:5000]
|
233 |
+
except requests.RequestException as e:
|
234 |
+
return {"error": f"Error fetching the page: {str(e)}"}
|
235 |
+
else:
|
236 |
+
return {"error": "Unknown document type"}
|
237 |
+
|
238 |
+
# Analyze with Ollama for novelty assessment
|
239 |
+
result = ask_ollama(
|
240 |
+
user_message=f"Patent background:\n{patent_background}\n\nDocument content:\n{text}",
|
241 |
+
system_prompt=infringement_prompt
|
242 |
+
)
|
243 |
+
|
244 |
+
# # Extract insights
|
245 |
+
# insights = ask_ollama(
|
246 |
+
# user_message=f"Document content:\n{text}",
|
247 |
+
# system_prompt=insight_prompt
|
248 |
+
# )
|
249 |
+
|
250 |
+
# # Combine results
|
251 |
+
# result['insights'] = insights.get('insights', [])
|
252 |
+
|
253 |
+
return result
|
254 |
+
|
255 |
+
except Exception as e:
|
256 |
+
return {"error": f"Error: {str(e)}"}
|
257 |
+
|
258 |
+
|
259 |
+
def extract_insights(patent_background, url, data_type="pdf"):
|
260 |
+
"""Extract full document text from PDF or background from patent and evaluate novelty"""
|
261 |
+
try:
|
262 |
+
# Disable SSL warnings
|
263 |
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
264 |
+
# Extract text based on the type
|
265 |
+
if data_type == "pdf":
|
266 |
+
headers = {
|
267 |
+
"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",
|
268 |
+
"Accept": "application/pdf"
|
269 |
+
}
|
270 |
+
|
271 |
+
response = requests.get(url, headers=headers, timeout=20, verify=False)
|
272 |
+
if response.status_code != 200:
|
273 |
+
print(f"Failed to download PDF (status code: {response.status_code})")
|
274 |
+
return {"error": f"Failed to download PDF (status code: {response.status_code})"}
|
275 |
+
|
276 |
+
# Extract full document text (limited to 6000 characters)
|
277 |
+
try:
|
278 |
+
pdf_document = fitz.open(stream=response.content, filetype="pdf")
|
279 |
+
if pdf_document.page_count == 0:
|
280 |
+
return {"error": "PDF has no pages"}
|
281 |
+
|
282 |
+
text = ""
|
283 |
+
for page_num in range(min(5, pdf_document.page_count)): # Limit to first 5 pages
|
284 |
+
page = pdf_document.load_page(page_num)
|
285 |
+
text += page.get_text() + " "
|
286 |
+
if len(text) >= 6000:
|
287 |
+
break
|
288 |
+
|
289 |
+
text = text[:6000] # Limit to 6000 characters
|
290 |
+
except Exception as e:
|
291 |
+
return {"error": f"Error processing PDF: {str(e)}"}
|
292 |
+
|
293 |
+
elif data_type == "patent":
|
294 |
+
# Extract background from patent
|
295 |
+
print("extract from patent")
|
296 |
+
try:
|
297 |
+
response = requests.get(url, timeout=20, verify=False)
|
298 |
+
if response.status_code != 200:
|
299 |
+
print(f"Failed to access patent (status code: {response.status_code})")
|
300 |
+
return {"error": f"Failed to access patent (status code: {response.status_code})"}
|
301 |
+
content = response.content.decode('utf-8').replace("\n", "")
|
302 |
+
soup = BeautifulSoup(content, 'html.parser')
|
303 |
+
section = soup.find('section', itemprop='description', itemscope='')
|
304 |
+
matches = re.findall(r"background(.*?)(?:summary|description of the drawing)", str(section), re.DOTALL | re.IGNORECASE)
|
305 |
+
if matches:
|
306 |
+
text = BeautifulSoup(matches[0], "html.parser").get_text(separator=" ").strip()
|
307 |
+
else:
|
308 |
+
text = "Background section not found in patent."
|
309 |
+
except Exception as e:
|
310 |
+
return {"error": f"Error processing patent: {str(e)}"}
|
311 |
+
elif data_type == "web":
|
312 |
+
try:
|
313 |
+
headers = {
|
314 |
+
"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",
|
315 |
+
"Accept": "application/pdf"
|
316 |
+
}
|
317 |
+
response = requests.get(url, headers=headers, timeout=20, verify=False)
|
318 |
+
response.raise_for_status()
|
319 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
320 |
+
full_text = soup.get_text()
|
321 |
+
text = re.sub(r'\n+', ' ', full_text)[:5000]
|
322 |
+
except requests.RequestException as e:
|
323 |
+
return {"error": f"Error fetching the page: {str(e)}"}
|
324 |
+
else:
|
325 |
+
return {"error": "Unknown document type"}
|
326 |
+
|
327 |
+
# Extract insights
|
328 |
+
insights = ask_ollama(
|
329 |
+
user_message=f"Document content:\n{text}",
|
330 |
+
system_prompt=insight_prompt
|
331 |
+
)
|
332 |
+
|
333 |
+
return insights
|
334 |
+
|
335 |
+
except Exception as e:
|
336 |
+
return {"error": f"Error: {str(e)}"}
|
337 |
+
|
338 |
+
@app.route('/')
|
339 |
+
def home():
|
340 |
+
return render_template('index.html')
|
341 |
+
|
342 |
+
@app.route('/chat', methods=['POST'])
|
343 |
+
def chat():
|
344 |
+
user_message = request.form.get('message')
|
345 |
+
ai_reply = ask_ollama(user_message)
|
346 |
+
return jsonify({'reply': ai_reply})
|
347 |
+
|
348 |
+
@app.route('/search', methods=['POST'])
|
349 |
+
def search():
|
350 |
+
query = request.form.get('query')
|
351 |
+
pdf_checked = request.form.get('pdfOption') == 'true'
|
352 |
+
patent_checked = request.form.get('patentOption') == 'true'
|
353 |
+
web_checked = request.form.get('webOption') == 'true' or request.form.get('webOption') == 'on'
|
354 |
+
|
355 |
+
if not query:
|
356 |
+
return jsonify({'error': 'No query provided', 'results': []})
|
357 |
+
|
358 |
+
all_results = []
|
359 |
+
|
360 |
+
try:
|
361 |
+
# Handle various combinations
|
362 |
+
if pdf_checked:
|
363 |
+
pdf_query = f"{query} filetype:pdf"
|
364 |
+
pdf_results = search_web(pdf_query, max_references=5, data_type="pdf")
|
365 |
+
all_results.extend(pdf_results)
|
366 |
+
|
367 |
+
if patent_checked:
|
368 |
+
patent_query = f"{query} site:patents.google.com"
|
369 |
+
patent_results = search_web(patent_query, max_references=5, data_type="patent")
|
370 |
+
all_results.extend(patent_results)
|
371 |
+
|
372 |
+
if web_checked:
|
373 |
+
# For web, we don't add anything to the query
|
374 |
+
web_results = search_web(query, max_references=5, data_type="web")
|
375 |
+
all_results.extend(web_results)
|
376 |
+
|
377 |
+
# If nothing is checked, default to web search
|
378 |
+
if not (pdf_checked or patent_checked or web_checked):
|
379 |
+
web_results = search_web(query, max_references=5, data_type="web")
|
380 |
+
all_results.extend(web_results)
|
381 |
+
|
382 |
+
return jsonify({'results': all_results})
|
383 |
+
except Exception as e:
|
384 |
+
print(f"Error performing search: {e}")
|
385 |
+
return jsonify({'error': str(e), 'results': []})
|
386 |
+
|
387 |
+
@app.route('/analyze', methods=['POST'])
|
388 |
+
def analyze():
|
389 |
+
data = request.json
|
390 |
+
if not data or 'patent_background' not in data or 'pdf_url' not in data:
|
391 |
+
return jsonify({'error': 'Missing required parameters', 'result': None})
|
392 |
+
|
393 |
+
try:
|
394 |
+
patent_background = data['patent_background']
|
395 |
+
url = data['pdf_url']
|
396 |
+
data_type = data.get('data_type', 'pdf') # Default to pdf if not specified
|
397 |
+
|
398 |
+
result = analyze_pdf_novelty(patent_background, url, data_type)
|
399 |
+
return jsonify({'result': result})
|
400 |
+
except Exception as e:
|
401 |
+
print(f"Error analyzing document: {e}")
|
402 |
+
return jsonify({'error': str(e), 'result': None})
|
403 |
+
|
404 |
+
@app.route('/post_insights', methods=['POST'])
|
405 |
+
def post_insights():
|
406 |
+
data = request.json
|
407 |
+
if not data or 'patent_background' not in data or 'pdf_url' not in data:
|
408 |
+
return jsonify({'error': 'Missing required parameters', 'result': None})
|
409 |
+
|
410 |
+
try:
|
411 |
+
patent_background = data['patent_background']
|
412 |
+
url = data['pdf_url']
|
413 |
+
data_type = data.get('data_type', 'pdf') # Default to pdf if not specified
|
414 |
+
|
415 |
+
result = extract_insights(patent_background, url, data_type)
|
416 |
+
return jsonify({'result': result})
|
417 |
+
except Exception as e:
|
418 |
+
print(f"Error analyzing document: {e}")
|
419 |
+
return jsonify({'error': str(e), 'result': None})
|
420 |
+
|
421 |
+
@app.route('/refine-problem', methods=['POST'])
|
422 |
+
def refine_problem():
|
423 |
+
data = request.json
|
424 |
+
if not data or 'original_problem' not in data or 'insights' not in data:
|
425 |
+
return jsonify({'error': 'Missing required parameters', 'result': None})
|
426 |
+
|
427 |
+
try:
|
428 |
+
original_problem = data['original_problem']
|
429 |
+
insights = data['insights']
|
430 |
+
user_comments = data.get('user_comments', '')
|
431 |
+
|
432 |
+
# Prepare the message for the LLM
|
433 |
+
message = f"""Initial Technical Problem:
|
434 |
+
{original_problem}
|
435 |
+
Selected Insights:
|
436 |
+
{', '.join(insights)}
|
437 |
+
User Comments/Suggestions:
|
438 |
+
{user_comments}
|
439 |
+
"""
|
440 |
+
|
441 |
+
# Get refined problem suggestions from the LLM
|
442 |
+
result = ask_ollama(
|
443 |
+
user_message=message,
|
444 |
+
system_prompt=refine_problem_prompt
|
445 |
+
)
|
446 |
+
|
447 |
+
return jsonify({'result': result})
|
448 |
+
except Exception as e:
|
449 |
+
print(f"Error refining problem: {e}")
|
450 |
+
return jsonify({'error': str(e), 'result': None})
|
451 |
+
|
452 |
+
@app.route('/export-excel', methods=['POST'])
|
453 |
+
def export_excel():
|
454 |
+
try:
|
455 |
+
data = request.json
|
456 |
+
if not data or 'tableData' not in data:
|
457 |
+
return jsonify({'error': 'No table data provided'})
|
458 |
+
|
459 |
+
# Create pandas DataFrame from the data
|
460 |
+
df = pd.DataFrame(data['tableData'])
|
461 |
+
|
462 |
+
# Get the user query
|
463 |
+
user_query = data.get('userQuery', 'No query provided')
|
464 |
+
|
465 |
+
# Get problem versions if available
|
466 |
+
problem_versions = data.get('problemVersions', {})
|
467 |
+
|
468 |
+
# Create a BytesIO object to store the Excel file
|
469 |
+
output = io.BytesIO()
|
470 |
+
|
471 |
+
# Create Excel file with xlsxwriter engine
|
472 |
+
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
|
473 |
+
# Write the data to a sheet named 'Results'
|
474 |
+
df.to_excel(writer, sheet_name='Results', index=False)
|
475 |
+
|
476 |
+
# Get workbook and worksheet objects
|
477 |
+
workbook = writer.book
|
478 |
+
worksheet = writer.sheets['Results']
|
479 |
+
|
480 |
+
# Add a sheet for the query
|
481 |
+
query_sheet = workbook.add_worksheet('Query')
|
482 |
+
query_sheet.write(0, 0, 'Patent Query')
|
483 |
+
query_sheet.write(1, 0, user_query)
|
484 |
+
|
485 |
+
# Add a sheet for problem versions if available
|
486 |
+
if problem_versions:
|
487 |
+
versions_sheet = workbook.add_worksheet('Problem Versions')
|
488 |
+
versions_sheet.write(0, 0, 'Version')
|
489 |
+
versions_sheet.write(0, 1, 'Problem Statement')
|
490 |
+
|
491 |
+
row = 1
|
492 |
+
for version, text in problem_versions.items():
|
493 |
+
versions_sheet.write(row, 0, version)
|
494 |
+
versions_sheet.write(row, 1, text)
|
495 |
+
row += 1
|
496 |
+
|
497 |
+
# Set column width for problem versions
|
498 |
+
versions_sheet.set_column(0, 0, 20)
|
499 |
+
versions_sheet.set_column(1, 1, 100)
|
500 |
+
|
501 |
+
# Adjust column widths
|
502 |
+
for i, col in enumerate(df.columns):
|
503 |
+
# Get maximum column width
|
504 |
+
max_len = max(
|
505 |
+
df[col].astype(str).map(len).max(),
|
506 |
+
len(col)
|
507 |
+
) + 2
|
508 |
+
# Set column width (limit to 100 to avoid issues)
|
509 |
+
worksheet.set_column(i, i, min(max_len, 100))
|
510 |
+
|
511 |
+
# Seek to the beginning of the BytesIO object
|
512 |
+
output.seek(0)
|
513 |
+
|
514 |
+
# Return the Excel file
|
515 |
+
return send_file(
|
516 |
+
output,
|
517 |
+
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
518 |
+
as_attachment=True,
|
519 |
+
download_name='patent_search_results.xlsx'
|
520 |
+
)
|
521 |
+
|
522 |
+
except Exception as e:
|
523 |
+
print(f"Error exporting Excel: {e}")
|
524 |
+
return jsonify({'error': str(e)})
|
525 |
+
|
526 |
+
@app.route('/ai-select-insights', methods=['POST'])
|
527 |
+
def ai_select_insights():
|
528 |
+
data = request.json
|
529 |
+
if not data or 'patent_background' not in data or 'insights' not in data:
|
530 |
+
return jsonify({'error': 'Missing required parameters', 'selected_insights': []})
|
531 |
+
|
532 |
+
try:
|
533 |
+
patent_background = data['patent_background']
|
534 |
+
insights = data['insights']
|
535 |
+
|
536 |
+
if not insights or len(insights) == 0:
|
537 |
+
return jsonify({'error': 'No insights provided', 'selected_insights': []})
|
538 |
+
|
539 |
+
# Prepare the prompt for the LLM
|
540 |
+
ai_select_prompt = """You are an expert in patent analysis and technology innovation. Your task is to select the most relevant insights from a list that would help enhance the patentability of an invention.
|
541 |
+
|
542 |
+
INSTRUCTIONS:
|
543 |
+
|
544 |
+
1. Review the patent background description carefully.
|
545 |
+
|
546 |
+
2. Analyze each insight in the provided list and determine its relevance to the patent background.
|
547 |
+
|
548 |
+
3. Select ONLY THE MOST RELEVANT insights that are:
|
549 |
+
- Directly relevant to the patent's technical area
|
550 |
+
- Provide unique perspectives or identify novel challenges
|
551 |
+
- Could significantly enhance the patentability or scope of the invention
|
552 |
+
- Are technically substantive and not obvious
|
553 |
+
|
554 |
+
4. Ignore insights that are generic, obvious, or would weaken the patent case.
|
555 |
+
|
556 |
+
5. SELECT A MAXIMUM OF 7 INSIGHTS, even fewer if only a few are truly relevant.
|
557 |
+
|
558 |
+
6. Return ONLY the selected insights in a valid JSON array.
|
559 |
+
|
560 |
+
OUTPUT FORMAT:
|
561 |
+
Return only a valid JSON array of strings, each containing the exact text of a selected insight.
|
562 |
+
Example: ["Insight 1", "Insight 3", "Insight 5"]"""
|
563 |
+
|
564 |
+
# Prepare message content
|
565 |
+
message = f"""PATENT BACKGROUND:
|
566 |
+
{patent_background}
|
567 |
+
|
568 |
+
ALL AVAILABLE INSIGHTS:
|
569 |
+
{json.dumps(insights)}"""
|
570 |
+
|
571 |
+
ai_reply = ask_llm(message, system_prompt=ai_select_prompt)
|
572 |
+
print(f"AI SELECTION RESPONSE: {ai_reply}")
|
573 |
+
|
574 |
+
# Parse the JSON array from the response
|
575 |
+
# First strip markdown code blocks if present
|
576 |
+
cleaned_reply = ai_reply.replace('```json', '').replace('```', '').strip()
|
577 |
+
|
578 |
+
try:
|
579 |
+
selected_insights = json.loads(cleaned_reply)
|
580 |
+
|
581 |
+
# Validate that the response is a list
|
582 |
+
if not isinstance(selected_insights, list):
|
583 |
+
return jsonify({'error': 'Invalid response format from AI', 'selected_insights': []})
|
584 |
+
|
585 |
+
# Make sure all selected insights actually exist in the original list
|
586 |
+
validated_insights = [insight for insight in selected_insights if insight in insights]
|
587 |
+
|
588 |
+
return jsonify({'selected_insights': validated_insights})
|
589 |
+
|
590 |
+
except json.JSONDecodeError as e:
|
591 |
+
print(f"JSON parsing error: {e}")
|
592 |
+
return jsonify({'error': f'Failed to parse AI response: {e}', 'selected_insights': []})
|
593 |
+
|
594 |
+
except Exception as e:
|
595 |
+
print(f"Error in AI insight selection: {e}")
|
596 |
+
return jsonify({'error': str(e), 'selected_insights': []})
|
597 |
+
|
598 |
+
@app.route('/generate-key-issues', methods=['POST'])
|
599 |
+
def generate_key_issues():
|
600 |
+
data = request.json
|
601 |
+
if not data or 'query' not in data:
|
602 |
+
return jsonify({'error': 'No query provided', 'key_issues': []})
|
603 |
+
|
604 |
+
try:
|
605 |
+
query = data['query']
|
606 |
+
|
607 |
+
# Make a request to the external API
|
608 |
+
API_URL = "https://organizedprogrammers-fastapi-kig.hf.space/"
|
609 |
+
endpoint = f"{API_URL}/key-issue-format"
|
610 |
+
api_data = {"query": query}
|
611 |
+
|
612 |
+
response = requests.post(endpoint, json=api_data, verify=False)
|
613 |
+
if response.status_code == 200:
|
614 |
+
result = response.json()
|
615 |
+
return jsonify(result)
|
616 |
+
else:
|
617 |
+
return jsonify({
|
618 |
+
'error': f"API Error: {response.status_code}",
|
619 |
+
'key_issues': []
|
620 |
+
})
|
621 |
+
|
622 |
+
except Exception as e:
|
623 |
+
print(f"Error generating key issues: {e}")
|
624 |
+
return jsonify({'error': str(e), 'key_issues': []})
|
625 |
+
|
626 |
+
if __name__ == '__main__':
|
627 |
+
app.run(host="0.0.0.0", port=7860)
|
requirements.txt
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Flask
|
2 |
+
duckduckgo-search
|
3 |
+
httpx
|
4 |
+
requests
|
5 |
+
beautifulsoup4
|
6 |
+
PyMuPDF
|
7 |
+
urllib3
|
8 |
+
pandas
|
9 |
+
groq
|
10 |
+
astor
|
11 |
+
openpyxl
|
12 |
+
xlsxwriter
|
static/script.js
ADDED
@@ -0,0 +1,2139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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em history versions
|
2 |
+
const problemHistory = [];
|
3 |
+
let currentHistoryIndex = -1;
|
4 |
+
// Store all refined problem suggestions
|
5 |
+
let storedRefinedProblems = {};
|
6 |
+
document.getElementById("tab1").style.display = "block";
|
7 |
+
|
8 |
+
function openTab(evt, tabName) {
|
9 |
+
var i, tabcontent, tablinks;
|
10 |
+
tabcontent = document.getElementsByClassName("tabcontent");
|
11 |
+
for (i = 0; i < tabcontent.length; i++) {
|
12 |
+
tabcontent[i].style.display = "none";
|
13 |
+
}
|
14 |
+
tablinks = document.getElementsByClassName("tablinks");
|
15 |
+
for (i = 0; i < tablinks.length; i++) {
|
16 |
+
tablinks[i].className = tablinks[i].className.replace(" active", "");
|
17 |
+
}
|
18 |
+
document.getElementById(tabName).style.display = "block";
|
19 |
+
evt.currentTarget.className += " active";
|
20 |
+
}
|
21 |
+
|
22 |
+
function navigateProblemHistory(direction) {
|
23 |
+
const problemInput = document.getElementById('userProblemDescription');
|
24 |
+
console.log("Current history index:", currentHistoryIndex, "Total history:", problemHistory.length);
|
25 |
+
|
26 |
+
if (direction === 'prev' && currentHistoryIndex > 0) {
|
27 |
+
currentHistoryIndex--;
|
28 |
+
problemInput.value = problemHistory[currentHistoryIndex];
|
29 |
+
console.log("Moving to previous version:", currentHistoryIndex);
|
30 |
+
} else if (direction === 'next' && currentHistoryIndex < problemHistory.length - 1) {
|
31 |
+
currentHistoryIndex++;
|
32 |
+
problemInput.value = problemHistory[currentHistoryIndex];
|
33 |
+
console.log("Moving to next version:", currentHistoryIndex);
|
34 |
+
}
|
35 |
+
|
36 |
+
updateHistoryNavigation();
|
37 |
+
}
|
38 |
+
|
39 |
+
function generateQueries(event) {
|
40 |
+
event.preventDefault();
|
41 |
+
|
42 |
+
const userInput = document.getElementById('userInput').value.trim();
|
43 |
+
if (!userInput) {
|
44 |
+
alert('Please enter a technical problem description');
|
45 |
+
return;
|
46 |
+
}
|
47 |
+
|
48 |
+
// Show loading indicator
|
49 |
+
document.querySelector(".progress-text").innerHTML = "Generating key issues ... Please wait."
|
50 |
+
document.getElementById('globalLoadingOverlay').style.display = 'flex';
|
51 |
+
|
52 |
+
// Send message to Flask backend
|
53 |
+
fetch('https://organizedprogrammers-fastapi-kig.hf.space/key-issue-format', {
|
54 |
+
method: 'POST',
|
55 |
+
body: JSON.stringify({ 'query': userInput }),
|
56 |
+
headers: { 'Content-Type': 'application/json' }
|
57 |
+
})
|
58 |
+
.then(response => response.json())
|
59 |
+
.then(data => {
|
60 |
+
// Hide loading indicator
|
61 |
+
document.getElementById('globalLoadingOverlay').style.display = 'none';
|
62 |
+
|
63 |
+
// Check if we have key issues in the response
|
64 |
+
if (data.key_issues && data.key_issues.length > 0) {
|
65 |
+
// Display the key issues
|
66 |
+
displayKeyIssues(data.key_issues);
|
67 |
+
} else if (data.error) {
|
68 |
+
alert('Error: ' + data.error);
|
69 |
+
} else {
|
70 |
+
alert('No key issues found. Please try a different query.');
|
71 |
+
}
|
72 |
+
})
|
73 |
+
.catch(error => {
|
74 |
+
document.getElementById('globalLoadingOverlay').style.display = 'none';
|
75 |
+
console.error('Error:', error);
|
76 |
+
alert('There was an error communicating with the server. Please try again.');
|
77 |
+
});
|
78 |
+
}
|
79 |
+
|
80 |
+
function performSearch(query, queryItemElement) {
|
81 |
+
if (!query.trim()) {
|
82 |
+
alert('Please enter a search query');
|
83 |
+
return;
|
84 |
+
}
|
85 |
+
|
86 |
+
const loadingElement = queryItemElement.querySelector('.search-loading');
|
87 |
+
const tableElement = queryItemElement.querySelector('.results-table');
|
88 |
+
const tableBody = tableElement.querySelector('tbody');
|
89 |
+
|
90 |
+
// Show loading and hide previous results
|
91 |
+
loadingElement.style.display = 'block';
|
92 |
+
tableElement.style.display = 'none';
|
93 |
+
|
94 |
+
// Clear previous results
|
95 |
+
tableBody.innerHTML = '';
|
96 |
+
|
97 |
+
// Get checkbox values
|
98 |
+
const pdfChecked = document.getElementById('pdfOption').checked;
|
99 |
+
const patentChecked = document.getElementById('patentOption').checked;
|
100 |
+
const webChecked = document.getElementById('webOption').checked;
|
101 |
+
|
102 |
+
|
103 |
+
// Create form data with query and checkbox values
|
104 |
+
const formData = new FormData();
|
105 |
+
formData.append('query', query);
|
106 |
+
formData.append('pdfOption', pdfChecked);
|
107 |
+
formData.append('patentOption', patentChecked);
|
108 |
+
formData.append('webOption', webChecked);
|
109 |
+
|
110 |
+
|
111 |
+
// Send search request to backend
|
112 |
+
fetch('/search', {
|
113 |
+
method: 'POST',
|
114 |
+
body: formData
|
115 |
+
})
|
116 |
+
.then(response => response.json())
|
117 |
+
.then(data => {
|
118 |
+
// Hide loading indicator
|
119 |
+
loadingElement.style.display = 'none';
|
120 |
+
|
121 |
+
if (data.results && data.results.length > 0) {
|
122 |
+
// Populate table with results
|
123 |
+
data.results.forEach(result => {
|
124 |
+
const row = document.createElement('tr');
|
125 |
+
|
126 |
+
const typeCell = document.createElement('td');
|
127 |
+
typeCell.textContent = result.type;
|
128 |
+
|
129 |
+
const titleCell = document.createElement('td');
|
130 |
+
titleCell.textContent = result.title;
|
131 |
+
|
132 |
+
const bodyCell = document.createElement('td');
|
133 |
+
bodyCell.textContent = result.body;
|
134 |
+
|
135 |
+
const urlCell = document.createElement('td');
|
136 |
+
const urlLink = document.createElement('a');
|
137 |
+
urlLink.href = result.url;
|
138 |
+
urlLink.textContent = result.url;
|
139 |
+
urlLink.className = 'url-link';
|
140 |
+
urlLink.target = '_blank';
|
141 |
+
urlCell.appendChild(urlLink);
|
142 |
+
|
143 |
+
// Add "Analyze" button to the URL cell
|
144 |
+
const analyzeButton = document.createElement('button');
|
145 |
+
analyzeButton.textContent = 'Analyze';
|
146 |
+
analyzeButton.className = 'action-button analyze-button';
|
147 |
+
analyzeButton.onclick = function(e) {
|
148 |
+
e.preventDefault();
|
149 |
+
analyzePaper(result.url, queryItemElement);
|
150 |
+
};
|
151 |
+
urlCell.appendChild(document.createElement('br'));
|
152 |
+
urlCell.appendChild(analyzeButton);
|
153 |
+
|
154 |
+
row.appendChild(typeCell);
|
155 |
+
row.appendChild(titleCell);
|
156 |
+
row.appendChild(bodyCell);
|
157 |
+
row.appendChild(urlCell);
|
158 |
+
|
159 |
+
tableBody.appendChild(row);
|
160 |
+
});
|
161 |
+
|
162 |
+
// Show the table
|
163 |
+
tableElement.style.display = 'table';
|
164 |
+
} else {
|
165 |
+
// No results
|
166 |
+
const row = document.createElement('tr');
|
167 |
+
const cell = document.createElement('td');
|
168 |
+
cell.colSpan = 4; // Updated to 4 since we now have 4 columns with the type column
|
169 |
+
cell.textContent = 'No results found.';
|
170 |
+
cell.style.textAlign = 'center';
|
171 |
+
row.appendChild(cell);
|
172 |
+
tableBody.appendChild(row);
|
173 |
+
tableElement.style.display = 'table';
|
174 |
+
}
|
175 |
+
})
|
176 |
+
.catch(error => {
|
177 |
+
loadingElement.style.display = 'none';
|
178 |
+
console.error('Error:', error);
|
179 |
+
|
180 |
+
// Show error in table
|
181 |
+
const row = document.createElement('tr');
|
182 |
+
const cell = document.createElement('td');
|
183 |
+
cell.colSpan = 4; // Updated to 4 since we now have 4 columns with the type column
|
184 |
+
cell.textContent = 'Error performing search. Please try again.';
|
185 |
+
cell.style.textAlign = 'center';
|
186 |
+
cell.style.color = 'red';
|
187 |
+
row.appendChild(cell);
|
188 |
+
tableBody.appendChild(row);
|
189 |
+
tableElement.style.display = 'table';
|
190 |
+
});
|
191 |
+
}
|
192 |
+
|
193 |
+
function analyzePaper(paperUrl, queryItemElement) {
|
194 |
+
const patentBackground = document.getElementById('userProblemDescription').value.trim();
|
195 |
+
if (!patentBackground) {
|
196 |
+
alert('Please provide a patent background in the input field');
|
197 |
+
return;
|
198 |
+
}
|
199 |
+
|
200 |
+
// Find the row containing this URL
|
201 |
+
const rows = queryItemElement.querySelectorAll('tbody tr');
|
202 |
+
let targetRow;
|
203 |
+
let documentType = 'pdf'; // Default type
|
204 |
+
|
205 |
+
for (const row of rows) {
|
206 |
+
const urlLink = row.querySelector('.url-link');
|
207 |
+
if (urlLink && urlLink.href === paperUrl) {
|
208 |
+
targetRow = row;
|
209 |
+
// Get the document type from the first cell of the row
|
210 |
+
documentType = row.cells[0].textContent.toLowerCase();
|
211 |
+
break;
|
212 |
+
}
|
213 |
+
}
|
214 |
+
|
215 |
+
if (!targetRow) {
|
216 |
+
alert('Could not find the paper in the results table');
|
217 |
+
return;
|
218 |
+
}
|
219 |
+
|
220 |
+
// Check if we already have analysis columns
|
221 |
+
let scoreCell, justificationCell;
|
222 |
+
if (targetRow.cells.length <= 4) {
|
223 |
+
// We need to create the cells
|
224 |
+
scoreCell = document.createElement('td');
|
225 |
+
scoreCell.className = 'score-cell';
|
226 |
+
scoreCell.innerHTML = '<div class="loading-spinner"></div>';
|
227 |
+
|
228 |
+
justificationCell = document.createElement('td');
|
229 |
+
justificationCell.className = 'justification-cell';
|
230 |
+
justificationCell.innerHTML = 'Analyzing...';
|
231 |
+
|
232 |
+
targetRow.appendChild(scoreCell);
|
233 |
+
targetRow.appendChild(justificationCell);
|
234 |
+
} else {
|
235 |
+
// Use existing cells
|
236 |
+
scoreCell = targetRow.cells[4];
|
237 |
+
justificationCell = targetRow.cells[5];
|
238 |
+
scoreCell.innerHTML = '<div class="loading-spinner"></div>';
|
239 |
+
justificationCell.innerHTML = 'Analyzing...';
|
240 |
+
}
|
241 |
+
|
242 |
+
// Send analysis request to backend
|
243 |
+
fetch('/analyze', {
|
244 |
+
method: 'POST',
|
245 |
+
body: JSON.stringify({
|
246 |
+
'patent_background': patentBackground,
|
247 |
+
'pdf_url': paperUrl,
|
248 |
+
'data_type': documentType
|
249 |
+
}),
|
250 |
+
headers: { 'Content-Type': 'application/json' }
|
251 |
+
})
|
252 |
+
.then(response => response.json())
|
253 |
+
.then(data => {
|
254 |
+
if (data.error) {
|
255 |
+
scoreCell.innerHTML = 'Error';
|
256 |
+
justificationCell.innerHTML = data.error;
|
257 |
+
} else if (data.result) {
|
258 |
+
// Get score and justification from the result
|
259 |
+
const result = data.result;
|
260 |
+
const score = result.score !== undefined ? result.score : 'N/A';
|
261 |
+
const justification = result.justification || 'No justification provided';
|
262 |
+
|
263 |
+
// Update cells with results
|
264 |
+
scoreCell.innerHTML = score;
|
265 |
+
justificationCell.innerHTML = justification;
|
266 |
+
|
267 |
+
// Color-code the score
|
268 |
+
if (score >= 0 && score <= 5) {
|
269 |
+
const redComponent = Math.floor((score / 5) * 255);
|
270 |
+
const greenComponent = Math.floor(((5 - score) / 5) * 255);
|
271 |
+
scoreCell.style.backgroundColor = `rgb(${redComponent}, ${greenComponent}, 0)`;
|
272 |
+
scoreCell.style.color = 'white';
|
273 |
+
scoreCell.style.fontWeight = 'bold';
|
274 |
+
scoreCell.style.textAlign = 'center';
|
275 |
+
}
|
276 |
+
|
277 |
+
// Add "Extract Insights" button to the justify cell
|
278 |
+
const insightsButton = document.createElement('button');
|
279 |
+
insightsButton.textContent = 'Extract Insights';
|
280 |
+
insightsButton.className = 'action-button insights-button';
|
281 |
+
insightsButton.style.marginTop = '5px';
|
282 |
+
insightsButton.style.fontSize = '0.8em';
|
283 |
+
insightsButton.onclick = function(e) {
|
284 |
+
e.preventDefault();
|
285 |
+
extractInsights(paperUrl, targetRow);
|
286 |
+
};
|
287 |
+
justificationCell.appendChild(document.createElement('br'));
|
288 |
+
justificationCell.appendChild(insightsButton);
|
289 |
+
} else {
|
290 |
+
scoreCell.innerHTML = 'No data';
|
291 |
+
justificationCell.innerHTML = 'Analysis failed';
|
292 |
+
}
|
293 |
+
})
|
294 |
+
.catch(error => {
|
295 |
+
console.error('Error:', error);
|
296 |
+
scoreCell.innerHTML = 'Error';
|
297 |
+
justificationCell.innerHTML = 'Failed to analyze paper';
|
298 |
+
});
|
299 |
+
}
|
300 |
+
|
301 |
+
function extractInsights(paperUrl, row) {
|
302 |
+
const patentBackground = document.getElementById('userProblemDescription').value.trim();
|
303 |
+
if (!patentBackground) {
|
304 |
+
alert('Please provide a patent background in the input field');
|
305 |
+
return;
|
306 |
+
}
|
307 |
+
|
308 |
+
const documentType = row.cells[0].textContent.toLowerCase();
|
309 |
+
|
310 |
+
// Check if there's already an insights row for this document
|
311 |
+
let insightsRow = row.nextElementSibling;
|
312 |
+
if (insightsRow && insightsRow.className === 'insights-row') {
|
313 |
+
// Insights row already exists, get the container
|
314 |
+
insightsContainer = insightsRow.querySelector('.insights-container');
|
315 |
+
insightsContainer.innerHTML = '<div class="loading-spinner"></div><div>Extracting insights...</div>';
|
316 |
+
} else {
|
317 |
+
// Create insights row that spans across all columns
|
318 |
+
insightsRow = document.createElement('tr');
|
319 |
+
insightsRow.className = 'insights-row';
|
320 |
+
|
321 |
+
const insightsTd = document.createElement('td');
|
322 |
+
insightsTd.colSpan = row.cells.length;
|
323 |
+
|
324 |
+
insightsContainer = document.createElement('div');
|
325 |
+
insightsContainer.className = 'insights-container';
|
326 |
+
insightsContainer.innerHTML = '<div class="loading-spinner"></div><div>Extracting insights...</div>';
|
327 |
+
|
328 |
+
insightsTd.appendChild(insightsContainer);
|
329 |
+
insightsRow.appendChild(insightsTd);
|
330 |
+
|
331 |
+
// Insert after the current row
|
332 |
+
row.parentNode.insertBefore(insightsRow, row.nextSibling);
|
333 |
+
}
|
334 |
+
|
335 |
+
// Store the row reference as a data attribute on the container for later access
|
336 |
+
insightsContainer.dataset.parentRow = row.rowIndex;
|
337 |
+
|
338 |
+
// Send request to extract insights
|
339 |
+
fetch('/post_insights', {
|
340 |
+
method: 'POST',
|
341 |
+
body: JSON.stringify({
|
342 |
+
'patent_background': patentBackground,
|
343 |
+
'pdf_url': paperUrl,
|
344 |
+
'data_type': documentType
|
345 |
+
}),
|
346 |
+
headers: { 'Content-Type': 'application/json' }
|
347 |
+
})
|
348 |
+
.then(response => response.json())
|
349 |
+
.then(data => {
|
350 |
+
if (data.error) {
|
351 |
+
insightsContainer.innerHTML = `<div class="error">Error: ${data.error}</div>`;
|
352 |
+
} else if (data.result && data.result.insights) {
|
353 |
+
// Create header with title and actions
|
354 |
+
const insightsHeader = document.createElement('div');
|
355 |
+
insightsHeader.className = 'insights-header';
|
356 |
+
|
357 |
+
const insightsTitle = document.createElement('div');
|
358 |
+
insightsTitle.className = 'insights-title';
|
359 |
+
insightsTitle.textContent = 'Document Insights';
|
360 |
+
|
361 |
+
const insightsActions = document.createElement('div');
|
362 |
+
insightsActions.className = 'insights-actions';
|
363 |
+
|
364 |
+
// Store the insights for this specific container
|
365 |
+
const containerInsights = [...data.result.insights];
|
366 |
+
insightsContainer.dataset.allInsights = JSON.stringify(containerInsights);
|
367 |
+
|
368 |
+
const selectAllBtn = document.createElement('button');
|
369 |
+
selectAllBtn.className = 'insights-button select-all-btn';
|
370 |
+
selectAllBtn.textContent = 'Select All';
|
371 |
+
// Use a closure to ensure the button has access to the correct container and row
|
372 |
+
selectAllBtn.addEventListener('click', function() {
|
373 |
+
const container = this.closest('.insights-container');
|
374 |
+
const parentRow = row;
|
375 |
+
const allInsights = JSON.parse(container.dataset.allInsights || '[]');
|
376 |
+
|
377 |
+
const tags = container.querySelectorAll('.insight-tag');
|
378 |
+
tags.forEach(tag => tag.classList.add('selected'));
|
379 |
+
|
380 |
+
parentRow.dataset.selectedInsights = JSON.stringify(allInsights);
|
381 |
+
parentRow.dataset.unselectedInsights = JSON.stringify([]);
|
382 |
+
|
383 |
+
// Trigger check for enabling/disabling enhance button
|
384 |
+
checkSelectedInsights();
|
385 |
+
});
|
386 |
+
|
387 |
+
const clearAllBtn = document.createElement('button');
|
388 |
+
clearAllBtn.className = 'insights-button clear-all-btn';
|
389 |
+
clearAllBtn.textContent = 'Clear All';
|
390 |
+
// Use a closure to ensure the button has access to the correct container and row
|
391 |
+
clearAllBtn.addEventListener('click', function() {
|
392 |
+
const container = this.closest('.insights-container');
|
393 |
+
const parentRow = row;
|
394 |
+
const allInsights = JSON.parse(container.dataset.allInsights || '[]');
|
395 |
+
|
396 |
+
const tags = container.querySelectorAll('.insight-tag');
|
397 |
+
tags.forEach(tag => tag.classList.remove('selected'));
|
398 |
+
|
399 |
+
parentRow.dataset.selectedInsights = JSON.stringify([]);
|
400 |
+
parentRow.dataset.unselectedInsights = JSON.stringify(allInsights);
|
401 |
+
|
402 |
+
// Trigger check for enabling/disabling enhance button
|
403 |
+
checkSelectedInsights();
|
404 |
+
});
|
405 |
+
|
406 |
+
insightsActions.appendChild(selectAllBtn);
|
407 |
+
insightsActions.appendChild(clearAllBtn);
|
408 |
+
|
409 |
+
insightsHeader.appendChild(insightsTitle);
|
410 |
+
insightsHeader.appendChild(insightsActions);
|
411 |
+
|
412 |
+
// Create insight tags
|
413 |
+
const insightsList = document.createElement('div');
|
414 |
+
insightsList.className = 'insights-list';
|
415 |
+
|
416 |
+
// Clear the container and add the new elements
|
417 |
+
insightsContainer.innerHTML = '';
|
418 |
+
insightsContainer.appendChild(insightsHeader);
|
419 |
+
insightsContainer.appendChild(insightsList);
|
420 |
+
|
421 |
+
// Initialize selected insights
|
422 |
+
const selectedInsights = [];
|
423 |
+
const unselectedInsights = [];
|
424 |
+
|
425 |
+
// Add insight tags
|
426 |
+
data.result.insights.forEach(insight => {
|
427 |
+
const tagElement = document.createElement('div');
|
428 |
+
tagElement.className = 'insight-tag';
|
429 |
+
tagElement.textContent = insight;
|
430 |
+
tagElement.addEventListener('click', function() {
|
431 |
+
this.classList.toggle('selected');
|
432 |
+
|
433 |
+
// Update selected insights
|
434 |
+
updateSelectedInsights(row, insightsContainer);
|
435 |
+
|
436 |
+
// Trigger check for enabling/disabling enhance button
|
437 |
+
checkSelectedInsights();
|
438 |
+
});
|
439 |
+
|
440 |
+
// Add to unselected by default
|
441 |
+
// tagElement.classList.add('selected');
|
442 |
+
unselectedInsights.push(insight);
|
443 |
+
|
444 |
+
insightsList.appendChild(tagElement);
|
445 |
+
});
|
446 |
+
|
447 |
+
// Store initial selections
|
448 |
+
row.dataset.selectedInsights = JSON.stringify(selectedInsights);
|
449 |
+
row.dataset.unselectedInsights = JSON.stringify(unselectedInsights);
|
450 |
+
|
451 |
+
// Trigger check for enabling/disabling enhance button immediately
|
452 |
+
checkSelectedInsights();
|
453 |
+
|
454 |
+
} else {
|
455 |
+
insightsContainer.innerHTML = '<div class="error">No insights found</div>';
|
456 |
+
}
|
457 |
+
})
|
458 |
+
.catch(error => {
|
459 |
+
console.error('Error:', error);
|
460 |
+
insightsContainer.innerHTML = `<div class="error">Error extracting insights: ${error.message}</div>`;
|
461 |
+
});
|
462 |
+
}
|
463 |
+
|
464 |
+
function updateSelectedInsights(row, insightsContainer) {
|
465 |
+
const selectedInsights = [];
|
466 |
+
const unselectedInsights = [];
|
467 |
+
|
468 |
+
const tags = insightsContainer.querySelectorAll('.insight-tag');
|
469 |
+
tags.forEach(tag => {
|
470 |
+
if (tag.classList.contains('selected')) {
|
471 |
+
selectedInsights.push(tag.textContent);
|
472 |
+
} else {
|
473 |
+
unselectedInsights.push(tag.textContent);
|
474 |
+
}
|
475 |
+
});
|
476 |
+
|
477 |
+
row.dataset.selectedInsights = JSON.stringify(selectedInsights);
|
478 |
+
row.dataset.unselectedInsights = JSON.stringify(unselectedInsights);
|
479 |
+
}
|
480 |
+
|
481 |
+
function checkSelectedInsights() {
|
482 |
+
const selectedInsights = collectAllSelectedInsights();
|
483 |
+
const enhanceButton = document.getElementById('enhanceProblemButton');
|
484 |
+
|
485 |
+
if (selectedInsights.length > 0) {
|
486 |
+
enhanceButton.classList.remove('disabled');
|
487 |
+
enhanceButton.disabled = false;
|
488 |
+
} else {
|
489 |
+
enhanceButton.classList.add('disabled');
|
490 |
+
enhanceButton.disabled = true;
|
491 |
+
}
|
492 |
+
}
|
493 |
+
|
494 |
+
function collectAllSelectedInsights() {
|
495 |
+
const allSelectedInsights = [];
|
496 |
+
const queryItems = document.querySelectorAll('.query-item');
|
497 |
+
|
498 |
+
queryItems.forEach(queryItem => {
|
499 |
+
const rows = queryItem.querySelectorAll('tbody tr:not(.insights-row)');
|
500 |
+
rows.forEach(row => {
|
501 |
+
if (row.dataset.selectedInsights) {
|
502 |
+
try {
|
503 |
+
const selectedInsights = JSON.parse(row.dataset.selectedInsights);
|
504 |
+
selectedInsights.forEach(insight => {
|
505 |
+
if (!allSelectedInsights.includes(insight)) {
|
506 |
+
allSelectedInsights.push(insight);
|
507 |
+
}
|
508 |
+
});
|
509 |
+
} catch (e) {
|
510 |
+
console.error('Error parsing selected insights:', e);
|
511 |
+
}
|
512 |
+
}
|
513 |
+
});
|
514 |
+
});
|
515 |
+
|
516 |
+
return allSelectedInsights;
|
517 |
+
}
|
518 |
+
|
519 |
+
function exportToExcel() {
|
520 |
+
// Show loading overlay
|
521 |
+
const loadingOverlay = document.getElementById('globalLoadingOverlay');
|
522 |
+
if (loadingOverlay) {
|
523 |
+
loadingOverlay.style.display = 'flex';
|
524 |
+
loadingOverlay.querySelector('.progress-text').textContent = 'Generating Excel file...';
|
525 |
+
}
|
526 |
+
|
527 |
+
try {
|
528 |
+
// Collect all data from all tables
|
529 |
+
const allData = [];
|
530 |
+
const queryItems = document.querySelectorAll('.query-item');
|
531 |
+
|
532 |
+
queryItems.forEach(queryItem => {
|
533 |
+
// Get the search query text for this table
|
534 |
+
const queryText = queryItem.querySelector('.query-field').value;
|
535 |
+
|
536 |
+
// Get all rows in this table
|
537 |
+
const rows = queryItem.querySelectorAll('tbody tr:not(.insights-row)');
|
538 |
+
|
539 |
+
rows.forEach(row => {
|
540 |
+
// Skip empty rows or error rows
|
541 |
+
if (row.cells.length === 1 && row.cells[0].colSpan > 1) {
|
542 |
+
return; // Skip "No results found" rows
|
543 |
+
}
|
544 |
+
|
545 |
+
// Prepare object for this row
|
546 |
+
const rowData = {
|
547 |
+
'Topic': queryText,
|
548 |
+
'Type': row.cells[0].textContent,
|
549 |
+
'Title': row.cells[1].textContent,
|
550 |
+
'Description': row.cells[2].textContent,
|
551 |
+
'URL': row.querySelector('.url-link')?.href || ''
|
552 |
+
};
|
553 |
+
|
554 |
+
// Add score and justification if they exist
|
555 |
+
if (row.cells.length > 4) {
|
556 |
+
rowData['Score'] = row.cells[4].textContent;
|
557 |
+
rowData['Justification'] = row.cells[5].textContent.split('\n')[0]; // Only get the justification text
|
558 |
+
} else {
|
559 |
+
rowData['Score'] = '';
|
560 |
+
rowData['Justification'] = '';
|
561 |
+
}
|
562 |
+
|
563 |
+
// Add selected and unselected insights if they exist
|
564 |
+
if (row.dataset.selectedInsights) {
|
565 |
+
try {
|
566 |
+
const selectedInsights = JSON.parse(row.dataset.selectedInsights);
|
567 |
+
rowData['Selected Insights'] = selectedInsights.join('; ');
|
568 |
+
} catch (e) {
|
569 |
+
rowData['Selected Insights'] = '';
|
570 |
+
}
|
571 |
+
} else {
|
572 |
+
rowData['Selected Insights'] = '';
|
573 |
+
}
|
574 |
+
|
575 |
+
if (row.dataset.unselectedInsights) {
|
576 |
+
try {
|
577 |
+
const unselectedInsights = JSON.parse(row.dataset.unselectedInsights);
|
578 |
+
rowData['Unselected Insights'] = unselectedInsights.join('; ');
|
579 |
+
} catch (e) {
|
580 |
+
rowData['Unselected Insights'] = '';
|
581 |
+
}
|
582 |
+
} else {
|
583 |
+
rowData['Unselected Insights'] = '';
|
584 |
+
}
|
585 |
+
|
586 |
+
allData.push(rowData);
|
587 |
+
});
|
588 |
+
});
|
589 |
+
|
590 |
+
// Check if we have any data
|
591 |
+
if (allData.length === 0) {
|
592 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
593 |
+
alert('No data to export. Please perform a search first.');
|
594 |
+
return;
|
595 |
+
}
|
596 |
+
|
597 |
+
// Get all problem versions
|
598 |
+
const problemVersions = {};
|
599 |
+
if (problemHistory.length > 0) {
|
600 |
+
problemHistory.forEach((problem, index) => {
|
601 |
+
problemVersions[`Problem Version ${index + 1}`] = problem;
|
602 |
+
});
|
603 |
+
} else {
|
604 |
+
// If no history, just use the current problem
|
605 |
+
const currentProblem = document.getElementById('userProblemDescription').value.trim();
|
606 |
+
if (currentProblem) {
|
607 |
+
problemVersions['Problem Version 1'] = currentProblem;
|
608 |
+
}
|
609 |
+
}
|
610 |
+
|
611 |
+
// Send to server for Excel generation
|
612 |
+
fetch('/export-excel', {
|
613 |
+
method: 'POST',
|
614 |
+
body: JSON.stringify({
|
615 |
+
'tableData': allData,
|
616 |
+
'userQuery': document.getElementById('userProblemDescription').value,
|
617 |
+
'problemVersions': problemVersions
|
618 |
+
}),
|
619 |
+
headers: { 'Content-Type': 'application/json' }
|
620 |
+
})
|
621 |
+
.then(response => {
|
622 |
+
if (!response.ok) {
|
623 |
+
throw new Error(`Server error: ${response.status}`);
|
624 |
+
}
|
625 |
+
return response.blob();
|
626 |
+
})
|
627 |
+
.then(blob => {
|
628 |
+
// Hide loading overlay
|
629 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
630 |
+
|
631 |
+
// Create URL for the blob
|
632 |
+
const url = window.URL.createObjectURL(new Blob([blob], {
|
633 |
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
634 |
+
}));
|
635 |
+
|
636 |
+
// Create a link and trigger download
|
637 |
+
const a = document.createElement('a');
|
638 |
+
a.href = url;
|
639 |
+
a.download = 'patent_search_results.xlsx';
|
640 |
+
document.body.appendChild(a);
|
641 |
+
a.click();
|
642 |
+
|
643 |
+
// Clean up
|
644 |
+
window.URL.revokeObjectURL(url);
|
645 |
+
document.body.removeChild(a);
|
646 |
+
})
|
647 |
+
.catch(error => {
|
648 |
+
console.error('Error exporting to Excel:', error);
|
649 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
650 |
+
alert(`Error exporting to Excel: ${error.message}`);
|
651 |
+
});
|
652 |
+
} catch (error) {
|
653 |
+
console.error('Error preparing Excel data:', error);
|
654 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
655 |
+
alert(`Error preparing data for export: ${error.message}`);
|
656 |
+
}
|
657 |
+
}
|
658 |
+
|
659 |
+
function hasSearchResults() {
|
660 |
+
const resultsContainer = document.getElementById('resultsContainer');
|
661 |
+
const hasResults = resultsContainer && resultsContainer.style.display !== 'none';
|
662 |
+
const hasTables = document.querySelectorAll('.results-table[style*="display: table"]').length > 0;
|
663 |
+
return hasResults && hasTables;
|
664 |
+
}
|
665 |
+
|
666 |
+
|
667 |
+
function analyzeAllPapers() {
|
668 |
+
// Show loading overlay
|
669 |
+
const loadingOverlay = document.getElementById('globalLoadingOverlay');
|
670 |
+
if (loadingOverlay) loadingOverlay.style.display = 'flex';
|
671 |
+
if (loadingOverlay) loadingOverlay.querySelector('.progress-text').textContent = 'Analyzing all papers...';
|
672 |
+
|
673 |
+
// Get all query items
|
674 |
+
const queryItems = document.querySelectorAll('.query-item');
|
675 |
+
let totalToAnalyze = 0;
|
676 |
+
let completedAnalyses = 0;
|
677 |
+
|
678 |
+
// Count total papers that need analysis
|
679 |
+
queryItems.forEach(queryItem => {
|
680 |
+
const rows = queryItem.querySelectorAll('tbody tr');
|
681 |
+
rows.forEach(row => {
|
682 |
+
if (row.cells.length <= 4 || row.cells[4].textContent.trim() === 'Error' ||
|
683 |
+
row.cells[4].textContent.trim() === 'N/A' || row.cells[4].textContent.trim() === '') {
|
684 |
+
totalToAnalyze++;
|
685 |
+
}
|
686 |
+
});
|
687 |
+
});
|
688 |
+
|
689 |
+
if (totalToAnalyze === 0) {
|
690 |
+
alert('No papers need analysis');
|
691 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
692 |
+
return;
|
693 |
+
}
|
694 |
+
|
695 |
+
// Function to update progress
|
696 |
+
function updateProgress() {
|
697 |
+
completedAnalyses++;
|
698 |
+
if (loadingOverlay) {
|
699 |
+
const progressElement = loadingOverlay.querySelector('.progress-text');
|
700 |
+
if (progressElement) {
|
701 |
+
progressElement.textContent = `Analyzing papers: ${completedAnalyses}/${totalToAnalyze}`;
|
702 |
+
}
|
703 |
+
}
|
704 |
+
|
705 |
+
if (completedAnalyses >= totalToAnalyze) {
|
706 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
707 |
+
}
|
708 |
+
}
|
709 |
+
|
710 |
+
// Analyze each paper that needs it
|
711 |
+
queryItems.forEach(queryItem => {
|
712 |
+
const rows = queryItem.querySelectorAll('tbody tr');
|
713 |
+
rows.forEach(row => {
|
714 |
+
// Check if this row needs analysis
|
715 |
+
if (row.cells.length <= 4 || row.cells[4].textContent.trim() === 'Error' ||
|
716 |
+
row.cells[4].textContent.trim() === 'N/A' || row.cells[4].textContent.trim() === '') {
|
717 |
+
|
718 |
+
// Get the URL
|
719 |
+
const urlLink = row.querySelector('.url-link');
|
720 |
+
const documentType = row.cells[0].textContent.toLowerCase();
|
721 |
+
if (urlLink && urlLink.href) {
|
722 |
+
// Create a promise for this analysis
|
723 |
+
const promise = new Promise((resolve) => {
|
724 |
+
// Prepare for analysis
|
725 |
+
const patentBackground = document.getElementById('userProblemDescription').value.trim();
|
726 |
+
|
727 |
+
// Create score and justification cells if needed
|
728 |
+
let scoreCell, justificationCell;
|
729 |
+
if (row.cells.length <= 4) {
|
730 |
+
scoreCell = document.createElement('td');
|
731 |
+
scoreCell.className = 'score-cell';
|
732 |
+
scoreCell.innerHTML = '<div class="loading-spinner"></div>';
|
733 |
+
|
734 |
+
justificationCell = document.createElement('td');
|
735 |
+
justificationCell.className = 'justification-cell';
|
736 |
+
justificationCell.innerHTML = 'Analyzing...';
|
737 |
+
|
738 |
+
row.appendChild(scoreCell);
|
739 |
+
row.appendChild(justificationCell);
|
740 |
+
} else {
|
741 |
+
scoreCell = row.cells[4];
|
742 |
+
justificationCell = row.cells[5];
|
743 |
+
scoreCell.innerHTML = '<div class="loading-spinner"></div>';
|
744 |
+
justificationCell.innerHTML = 'Analyzing...';
|
745 |
+
}
|
746 |
+
|
747 |
+
// Send analysis request
|
748 |
+
fetch('/analyze', {
|
749 |
+
method: 'POST',
|
750 |
+
body: JSON.stringify({
|
751 |
+
'patent_background': patentBackground,
|
752 |
+
'pdf_url': urlLink.href,
|
753 |
+
'data_type': documentType
|
754 |
+
}),
|
755 |
+
headers: { 'Content-Type': 'application/json' }
|
756 |
+
})
|
757 |
+
.then(response => response.json())
|
758 |
+
.then(data => {
|
759 |
+
if (data.error) {
|
760 |
+
scoreCell.innerHTML = 'Error';
|
761 |
+
justificationCell.innerHTML = data.error;
|
762 |
+
} else if (data.result) {
|
763 |
+
// Get score and justification
|
764 |
+
const result = data.result;
|
765 |
+
const score = result.score !== undefined ? result.score : 'N/A';
|
766 |
+
const justification = result.justification || 'No justification provided';
|
767 |
+
|
768 |
+
// Update cells
|
769 |
+
scoreCell.innerHTML = score;
|
770 |
+
justificationCell.innerHTML = justification;
|
771 |
+
|
772 |
+
// Color-code score
|
773 |
+
if (score >= 0 && score <= 5) {
|
774 |
+
const redComponent = Math.floor((score / 5) * 255);
|
775 |
+
const greenComponent = Math.floor(((5 - score) / 5) * 255);
|
776 |
+
scoreCell.style.backgroundColor = `rgb(${redComponent}, ${greenComponent}, 0)`;
|
777 |
+
scoreCell.style.color = 'white';
|
778 |
+
scoreCell.style.fontWeight = 'bold';
|
779 |
+
scoreCell.style.textAlign = 'center';
|
780 |
+
}
|
781 |
+
|
782 |
+
// Add "Extract Insights" button to the justify cell - for Analyze All function
|
783 |
+
const insightsButton = document.createElement('button');
|
784 |
+
insightsButton.textContent = 'Extract Insights';
|
785 |
+
insightsButton.className = 'action-button insights-button';
|
786 |
+
insightsButton.style.marginTop = '5px';
|
787 |
+
insightsButton.style.fontSize = '0.8em';
|
788 |
+
insightsButton.onclick = function(e) {
|
789 |
+
e.preventDefault();
|
790 |
+
extractInsights(urlLink.href, row);
|
791 |
+
};
|
792 |
+
justificationCell.appendChild(document.createElement('br'));
|
793 |
+
justificationCell.appendChild(insightsButton);
|
794 |
+
} else {
|
795 |
+
scoreCell.innerHTML = 'No data';
|
796 |
+
justificationCell.innerHTML = 'Analysis failed';
|
797 |
+
}
|
798 |
+
resolve();
|
799 |
+
})
|
800 |
+
.catch(error => {
|
801 |
+
console.error('Error:', error);
|
802 |
+
scoreCell.innerHTML = 'Error';
|
803 |
+
justificationCell.innerHTML = 'Failed to analyze paper';
|
804 |
+
resolve();
|
805 |
+
});
|
806 |
+
});
|
807 |
+
|
808 |
+
// When this analysis is done, update the progress
|
809 |
+
promise.then(() => {
|
810 |
+
updateProgress();
|
811 |
+
});
|
812 |
+
} else {
|
813 |
+
// No URL found, count as completed
|
814 |
+
updateProgress();
|
815 |
+
}
|
816 |
+
}
|
817 |
+
});
|
818 |
+
});
|
819 |
+
}
|
820 |
+
|
821 |
+
function removeFailedAnalyses() {
|
822 |
+
const queryItems = document.querySelectorAll('.query-item');
|
823 |
+
let removedCount = 0;
|
824 |
+
|
825 |
+
queryItems.forEach(queryItem => {
|
826 |
+
const tbody = queryItem.querySelector('tbody');
|
827 |
+
const rows = Array.from(tbody.querySelectorAll('tr'));
|
828 |
+
|
829 |
+
rows.forEach(row => {
|
830 |
+
if (row.cells.length > 4) {
|
831 |
+
const scoreText = row.cells[4].textContent.trim();
|
832 |
+
if (scoreText === 'Error' || scoreText === 'N/A' || scoreText === 'No data') {
|
833 |
+
tbody.removeChild(row);
|
834 |
+
removedCount++;
|
835 |
+
}
|
836 |
+
}
|
837 |
+
});
|
838 |
+
});
|
839 |
+
|
840 |
+
// Create and display a simple notification instead of alert
|
841 |
+
const notification = document.createElement('div');
|
842 |
+
notification.className = 'simple-notification';
|
843 |
+
notification.textContent = `Removed ${removedCount} papers with failed analyses`;
|
844 |
+
notification.style.position = 'fixed';
|
845 |
+
notification.style.top = '20px';
|
846 |
+
notification.style.right = '20px';
|
847 |
+
notification.style.background = '#4CAF50';
|
848 |
+
notification.style.color = 'white';
|
849 |
+
notification.style.padding = '15px';
|
850 |
+
notification.style.borderRadius = '5px';
|
851 |
+
notification.style.boxShadow = '0 2px 5px rgba(0,0,0,0.2)';
|
852 |
+
notification.style.zIndex = '10000';
|
853 |
+
|
854 |
+
// Add notification to the body
|
855 |
+
document.body.appendChild(notification);
|
856 |
+
|
857 |
+
// Remove notification after 3 seconds
|
858 |
+
setTimeout(() => {
|
859 |
+
if (notification.parentNode) {
|
860 |
+
notification.parentNode.removeChild(notification);
|
861 |
+
}
|
862 |
+
}, 3000);
|
863 |
+
}
|
864 |
+
|
865 |
+
function extractAllInsights() {
|
866 |
+
const patentBackground = document.getElementById('userProblemDescription').value.trim();
|
867 |
+
if (!patentBackground) {
|
868 |
+
alert('Please provide a patent background in the input field');
|
869 |
+
return;
|
870 |
+
}
|
871 |
+
|
872 |
+
// Show loading overlay
|
873 |
+
const loadingOverlay = document.getElementById('globalLoadingOverlay');
|
874 |
+
if (loadingOverlay) {
|
875 |
+
loadingOverlay.style.display = 'flex';
|
876 |
+
loadingOverlay.querySelector('.progress-text').textContent = 'Extracting insights from all documents...';
|
877 |
+
}
|
878 |
+
|
879 |
+
// Get all query items
|
880 |
+
const queryItems = document.querySelectorAll('.query-item');
|
881 |
+
let totalDocuments = 0;
|
882 |
+
let completedDocuments = 0;
|
883 |
+
|
884 |
+
// Count total analyzed documents that need insights extraction
|
885 |
+
const analyzedRows = [];
|
886 |
+
queryItems.forEach(queryItem => {
|
887 |
+
const rows = queryItem.querySelectorAll('tbody tr:not(.insights-row)');
|
888 |
+
rows.forEach(row => {
|
889 |
+
// Only include rows that have been analyzed (have score and justification cells)
|
890 |
+
if (row.cells.length > 4 && row.cells[4].textContent.trim() !== 'Error' &&
|
891 |
+
row.cells[4].textContent.trim() !== 'N/A' && row.cells[4].textContent.trim() !== '') {
|
892 |
+
analyzedRows.push(row);
|
893 |
+
totalDocuments++;
|
894 |
+
}
|
895 |
+
});
|
896 |
+
});
|
897 |
+
|
898 |
+
if (totalDocuments === 0) {
|
899 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
900 |
+
alert('No analyzed documents found. Please analyze documents first.');
|
901 |
+
return;
|
902 |
+
}
|
903 |
+
|
904 |
+
// Function to update progress
|
905 |
+
function updateProgress() {
|
906 |
+
completedDocuments++;
|
907 |
+
if (loadingOverlay) {
|
908 |
+
const progressElement = loadingOverlay.querySelector('.progress-text');
|
909 |
+
if (progressElement) {
|
910 |
+
progressElement.textContent = `Extracting insights: ${completedDocuments}/${totalDocuments}`;
|
911 |
+
}
|
912 |
+
}
|
913 |
+
|
914 |
+
if (completedDocuments >= totalDocuments) {
|
915 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
916 |
+
checkSelectedInsights(); // Update enhance button state based on selected insights
|
917 |
+
}
|
918 |
+
}
|
919 |
+
|
920 |
+
// Process each analyzed document sequentially to avoid overwhelming the server
|
921 |
+
function processNextDocument(index) {
|
922 |
+
if (index >= analyzedRows.length) {
|
923 |
+
return; // All documents processed
|
924 |
+
}
|
925 |
+
|
926 |
+
const row = analyzedRows[index];
|
927 |
+
const urlLink = row.querySelector('.url-link');
|
928 |
+
const documentType = row.cells[0].textContent.toLowerCase();
|
929 |
+
|
930 |
+
if (!urlLink || !urlLink.href) {
|
931 |
+
updateProgress();
|
932 |
+
processNextDocument(index + 1);
|
933 |
+
return;
|
934 |
+
}
|
935 |
+
|
936 |
+
// Check if there's already an insights row for this document
|
937 |
+
let insightsRow = row.nextElementSibling;
|
938 |
+
if (insightsRow && insightsRow.className === 'insights-row') {
|
939 |
+
// Insights row already exists, get the container
|
940 |
+
insightsContainer = insightsRow.querySelector('.insights-container');
|
941 |
+
insightsContainer.innerHTML = '<div class="loading-spinner"></div><div>Extracting insights...</div>';
|
942 |
+
} else {
|
943 |
+
// Create insights row that spans across all columns
|
944 |
+
insightsRow = document.createElement('tr');
|
945 |
+
insightsRow.className = 'insights-row';
|
946 |
+
|
947 |
+
const insightsTd = document.createElement('td');
|
948 |
+
insightsTd.colSpan = row.cells.length;
|
949 |
+
|
950 |
+
insightsContainer = document.createElement('div');
|
951 |
+
insightsContainer.className = 'insights-container';
|
952 |
+
insightsContainer.innerHTML = '<div class="loading-spinner"></div><div>Extracting insights...</div>';
|
953 |
+
|
954 |
+
insightsTd.appendChild(insightsContainer);
|
955 |
+
insightsRow.appendChild(insightsTd);
|
956 |
+
|
957 |
+
// Insert after the current row
|
958 |
+
row.parentNode.insertBefore(insightsRow, row.nextSibling);
|
959 |
+
}
|
960 |
+
|
961 |
+
// Store the row reference as a data attribute on the container for later access
|
962 |
+
insightsContainer.dataset.parentRow = row.rowIndex;
|
963 |
+
|
964 |
+
// Send request to extract insights
|
965 |
+
fetch('/post_insights', {
|
966 |
+
method: 'POST',
|
967 |
+
body: JSON.stringify({
|
968 |
+
'patent_background': patentBackground,
|
969 |
+
'pdf_url': urlLink.href,
|
970 |
+
'data_type': documentType
|
971 |
+
}),
|
972 |
+
headers: { 'Content-Type': 'application/json' }
|
973 |
+
})
|
974 |
+
.then(response => response.json())
|
975 |
+
.then(data => {
|
976 |
+
if (data.error) {
|
977 |
+
insightsContainer.innerHTML = `<div class="error">Error: ${data.error}</div>`;
|
978 |
+
} else if (data.result && data.result.insights) {
|
979 |
+
// Create header with title and actions
|
980 |
+
const insightsHeader = document.createElement('div');
|
981 |
+
insightsHeader.className = 'insights-header';
|
982 |
+
|
983 |
+
const insightsTitle = document.createElement('div');
|
984 |
+
insightsTitle.className = 'insights-title';
|
985 |
+
insightsTitle.textContent = 'Document Insights';
|
986 |
+
|
987 |
+
const insightsActions = document.createElement('div');
|
988 |
+
insightsActions.className = 'insights-actions';
|
989 |
+
|
990 |
+
// Store the insights for this specific container
|
991 |
+
const containerInsights = [...data.result.insights];
|
992 |
+
insightsContainer.dataset.allInsights = JSON.stringify(containerInsights);
|
993 |
+
|
994 |
+
const selectAllBtn = document.createElement('button');
|
995 |
+
selectAllBtn.className = 'insights-button select-all-btn';
|
996 |
+
selectAllBtn.textContent = 'Select All';
|
997 |
+
selectAllBtn.addEventListener('click', function() {
|
998 |
+
const container = this.closest('.insights-container');
|
999 |
+
const parentRow = row;
|
1000 |
+
const allInsights = JSON.parse(container.dataset.allInsights || '[]');
|
1001 |
+
|
1002 |
+
const tags = container.querySelectorAll('.insight-tag');
|
1003 |
+
tags.forEach(tag => tag.classList.add('selected'));
|
1004 |
+
|
1005 |
+
parentRow.dataset.selectedInsights = JSON.stringify(allInsights);
|
1006 |
+
parentRow.dataset.unselectedInsights = JSON.stringify([]);
|
1007 |
+
|
1008 |
+
checkSelectedInsights();
|
1009 |
+
});
|
1010 |
+
|
1011 |
+
const clearAllBtn = document.createElement('button');
|
1012 |
+
clearAllBtn.className = 'insights-button clear-all-btn';
|
1013 |
+
clearAllBtn.textContent = 'Clear All';
|
1014 |
+
clearAllBtn.addEventListener('click', function() {
|
1015 |
+
const container = this.closest('.insights-container');
|
1016 |
+
const parentRow = row;
|
1017 |
+
const allInsights = JSON.parse(container.dataset.allInsights || '[]');
|
1018 |
+
|
1019 |
+
const tags = container.querySelectorAll('.insight-tag');
|
1020 |
+
tags.forEach(tag => tag.classList.remove('selected'));
|
1021 |
+
|
1022 |
+
parentRow.dataset.selectedInsights = JSON.stringify([]);
|
1023 |
+
parentRow.dataset.unselectedInsights = JSON.stringify(allInsights);
|
1024 |
+
|
1025 |
+
checkSelectedInsights();
|
1026 |
+
});
|
1027 |
+
|
1028 |
+
insightsActions.appendChild(selectAllBtn);
|
1029 |
+
insightsActions.appendChild(clearAllBtn);
|
1030 |
+
|
1031 |
+
insightsHeader.appendChild(insightsTitle);
|
1032 |
+
insightsHeader.appendChild(insightsActions);
|
1033 |
+
|
1034 |
+
// Create insight tags
|
1035 |
+
const insightsList = document.createElement('div');
|
1036 |
+
insightsList.className = 'insights-list';
|
1037 |
+
|
1038 |
+
// Clear the container and add the new elements
|
1039 |
+
insightsContainer.innerHTML = '';
|
1040 |
+
insightsContainer.appendChild(insightsHeader);
|
1041 |
+
insightsContainer.appendChild(insightsList);
|
1042 |
+
|
1043 |
+
// Initialize selected insights
|
1044 |
+
const selectedInsights = [];
|
1045 |
+
const unselectedInsights = [];
|
1046 |
+
|
1047 |
+
// Add insight tags
|
1048 |
+
data.result.insights.forEach(insight => {
|
1049 |
+
const tagElement = document.createElement('div');
|
1050 |
+
tagElement.className = 'insight-tag';
|
1051 |
+
tagElement.textContent = insight;
|
1052 |
+
tagElement.addEventListener('click', function() {
|
1053 |
+
this.classList.toggle('selected');
|
1054 |
+
updateSelectedInsights(row, insightsContainer);
|
1055 |
+
checkSelectedInsights();
|
1056 |
+
});
|
1057 |
+
|
1058 |
+
// Add to unselected by default
|
1059 |
+
// tagElement.classList.add('selected');
|
1060 |
+
unselectedInsights.push(insight);
|
1061 |
+
|
1062 |
+
insightsList.appendChild(tagElement);
|
1063 |
+
});
|
1064 |
+
|
1065 |
+
// Store initial selections
|
1066 |
+
row.dataset.selectedInsights = JSON.stringify(selectedInsights);
|
1067 |
+
row.dataset.unselectedInsights = JSON.stringify(unselectedInsights);
|
1068 |
+
|
1069 |
+
} else {
|
1070 |
+
insightsContainer.innerHTML = '<div class="error">No insights found</div>';
|
1071 |
+
}
|
1072 |
+
|
1073 |
+
// Process next document
|
1074 |
+
updateProgress();
|
1075 |
+
processNextDocument(index + 1);
|
1076 |
+
})
|
1077 |
+
.catch(error => {
|
1078 |
+
console.error('Error:', error);
|
1079 |
+
insightsContainer.innerHTML = `<div class="error">Error extracting insights: ${error.message}</div>`;
|
1080 |
+
|
1081 |
+
// Continue with next document even if this one failed
|
1082 |
+
updateProgress();
|
1083 |
+
processNextDocument(index + 1);
|
1084 |
+
});
|
1085 |
+
}
|
1086 |
+
|
1087 |
+
// Start processing documents
|
1088 |
+
processNextDocument(0);
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
|
1092 |
+
function groupInsightsByScore() {
|
1093 |
+
// Get all query items
|
1094 |
+
const queryItems = document.querySelectorAll('.query-item');
|
1095 |
+
let hasInsights = false;
|
1096 |
+
|
1097 |
+
// Create structure to hold insights grouped by score
|
1098 |
+
const insightsByScore = {
|
1099 |
+
5: { insights: [], sources: [] },
|
1100 |
+
4: { insights: [], sources: [] },
|
1101 |
+
3: { insights: [], sources: [] },
|
1102 |
+
2: { insights: [], sources: [] },
|
1103 |
+
1: { insights: [], sources: [] },
|
1104 |
+
0: { insights: [], sources: [] }
|
1105 |
+
};
|
1106 |
+
|
1107 |
+
// Collect all insights from all documents and group by score
|
1108 |
+
queryItems.forEach(queryItem => {
|
1109 |
+
const rows = queryItem.querySelectorAll('tbody tr:not(.insights-row)');
|
1110 |
+
rows.forEach(row => {
|
1111 |
+
// Skip if no score or insights
|
1112 |
+
if (row.cells.length <= 4 || !row.dataset.selectedInsights) {
|
1113 |
+
return;
|
1114 |
+
}
|
1115 |
+
|
1116 |
+
// Get the score
|
1117 |
+
const scoreText = row.cells[4].textContent.trim();
|
1118 |
+
if (scoreText === 'Error' || scoreText === 'N/A' || isNaN(parseFloat(scoreText))) {
|
1119 |
+
return;
|
1120 |
+
}
|
1121 |
+
|
1122 |
+
const score = Math.round(parseFloat(scoreText));
|
1123 |
+
const urlLink = row.querySelector('.url-link');
|
1124 |
+
|
1125 |
+
if (!urlLink) return;
|
1126 |
+
|
1127 |
+
// Get insights from this document
|
1128 |
+
try {
|
1129 |
+
const selectedInsights = JSON.parse(row.dataset.selectedInsights || '[]');
|
1130 |
+
const unselectedInsights = JSON.parse(row.dataset.unselectedInsights || '[]');
|
1131 |
+
const allInsights = [...selectedInsights, ...unselectedInsights];
|
1132 |
+
|
1133 |
+
// Add insights to the appropriate score group
|
1134 |
+
if (score >= 0 && score <= 5 && allInsights.length > 0) {
|
1135 |
+
hasInsights = true;
|
1136 |
+
|
1137 |
+
// For all insights in this document
|
1138 |
+
allInsights.forEach(insight => {
|
1139 |
+
// Check if this insight is already in the group
|
1140 |
+
const existingIndex = insightsByScore[score].insights.findIndex(i => i === insight);
|
1141 |
+
|
1142 |
+
if (existingIndex === -1) {
|
1143 |
+
// New insight
|
1144 |
+
insightsByScore[score].insights.push(insight);
|
1145 |
+
insightsByScore[score].sources.push({
|
1146 |
+
url: urlLink.href,
|
1147 |
+
title: row.cells[1].textContent.trim().substring(0, 30) + '...',
|
1148 |
+
selected: selectedInsights.includes(insight)
|
1149 |
+
});
|
1150 |
+
}
|
1151 |
+
});
|
1152 |
+
}
|
1153 |
+
} catch (e) {
|
1154 |
+
console.error('Error parsing insights:', e);
|
1155 |
+
}
|
1156 |
+
});
|
1157 |
+
});
|
1158 |
+
|
1159 |
+
if (!hasInsights) {
|
1160 |
+
alert('No insights found. Please analyze documents and extract insights first.');
|
1161 |
+
return;
|
1162 |
+
}
|
1163 |
+
|
1164 |
+
// Create or get the grouped insights container
|
1165 |
+
let container = document.getElementById('groupedInsightsContainer');
|
1166 |
+
if (!container) {
|
1167 |
+
container = document.createElement('div');
|
1168 |
+
container.id = 'groupedInsightsContainer';
|
1169 |
+
container.className = 'grouped-insights-container';
|
1170 |
+
|
1171 |
+
// Insert after the problem input card
|
1172 |
+
const card = document.querySelector("#tab2 .card");
|
1173 |
+
card.parentNode.insertBefore(container, card.nextSibling);
|
1174 |
+
}
|
1175 |
+
|
1176 |
+
// Create header
|
1177 |
+
const header = document.createElement('div');
|
1178 |
+
header.className = 'grouped-insights-header';
|
1179 |
+
header.innerHTML = `
|
1180 |
+
<div>Insights Grouped by Score</div>
|
1181 |
+
<div class="grouped-insights-actions">
|
1182 |
+
<button class="ai-select-btn pulse" id="aiSelectButton" onclick="aiSelectInsights()">AI Select Insights</button>
|
1183 |
+
<div class="grouped-insights-close" onclick="closeGroupedInsights()">×</div>
|
1184 |
+
</div>
|
1185 |
+
`;
|
1186 |
+
|
1187 |
+
// Create content area
|
1188 |
+
const content = document.createElement('div');
|
1189 |
+
content.className = 'grouped-insights-content';
|
1190 |
+
|
1191 |
+
// Create score groups
|
1192 |
+
for (let score = 5; score >= 0; score--) {
|
1193 |
+
const insights = insightsByScore[score].insights;
|
1194 |
+
const sources = insightsByScore[score].sources;
|
1195 |
+
|
1196 |
+
if (insights.length === 0) continue;
|
1197 |
+
|
1198 |
+
const scoreGroup = document.createElement('div');
|
1199 |
+
scoreGroup.className = 'score-group';
|
1200 |
+
scoreGroup.dataset.score = score;
|
1201 |
+
|
1202 |
+
// Create score header
|
1203 |
+
const scoreHeader = document.createElement('div');
|
1204 |
+
scoreHeader.className = 'score-group-header';
|
1205 |
+
|
1206 |
+
let scoreColor = '';
|
1207 |
+
if (score >= 0 && score <= 5) {
|
1208 |
+
const redComponent = Math.floor((score / 5) * 255);
|
1209 |
+
const greenComponent = Math.floor(((5 - score) / 5) * 255);
|
1210 |
+
scoreColor = `background-color: rgb(${redComponent}, ${greenComponent}, 0); color: white;`;
|
1211 |
+
}
|
1212 |
+
|
1213 |
+
scoreHeader.innerHTML = `
|
1214 |
+
<div>
|
1215 |
+
<span style="display: inline-block; width: 25px; height: 25px; text-align: center; border-radius: 50%; ${scoreColor} font-weight: bold;">${score}</span>
|
1216 |
+
<span style="margin-left: 8px;">Score ${score} Insights (${insights.length})</span>
|
1217 |
+
</div>
|
1218 |
+
<div class="score-group-actions">
|
1219 |
+
<button class="insights-button select-score-all-btn" onclick="selectAllInScore(${score})">Select All</button>
|
1220 |
+
<button class="insights-button clear-score-all-btn" onclick="clearAllInScore(${score})">Clear All</button>
|
1221 |
+
</div>
|
1222 |
+
`;
|
1223 |
+
|
1224 |
+
// Create insights list
|
1225 |
+
const insightsList = document.createElement('div');
|
1226 |
+
insightsList.className = 'score-insights-list';
|
1227 |
+
|
1228 |
+
// Add each insight
|
1229 |
+
insights.forEach((insight, index) => {
|
1230 |
+
const source = sources[index];
|
1231 |
+
const tagElement = document.createElement('div');
|
1232 |
+
tagElement.className = `grouped-insight-tag${source.selected ? ' selected' : ''}`;
|
1233 |
+
tagElement.dataset.score = score;
|
1234 |
+
tagElement.dataset.index = index;
|
1235 |
+
tagElement.dataset.source = source.url;
|
1236 |
+
|
1237 |
+
// Create insight text with source link
|
1238 |
+
tagElement.innerHTML = `
|
1239 |
+
${insight}
|
1240 |
+
<a href="${source.url}" target="_blank" class="insight-source" title="${source.title}">${score}</a>
|
1241 |
+
`;
|
1242 |
+
|
1243 |
+
// Add click event to toggle selection
|
1244 |
+
tagElement.addEventListener('click', function(e) {
|
1245 |
+
// Prevent clicking on the source link from toggling selection
|
1246 |
+
if (e.target.classList.contains('insight-source')) return;
|
1247 |
+
|
1248 |
+
this.classList.toggle('selected');
|
1249 |
+
updateGroupedInsightSelections();
|
1250 |
+
});
|
1251 |
+
|
1252 |
+
insightsList.appendChild(tagElement);
|
1253 |
+
});
|
1254 |
+
|
1255 |
+
// Add header and list to score group
|
1256 |
+
scoreGroup.appendChild(scoreHeader);
|
1257 |
+
scoreGroup.appendChild(insightsList);
|
1258 |
+
|
1259 |
+
// Add score group to content
|
1260 |
+
content.appendChild(scoreGroup);
|
1261 |
+
}
|
1262 |
+
|
1263 |
+
// Clear the container and add new content
|
1264 |
+
container.innerHTML = '';
|
1265 |
+
container.appendChild(header);
|
1266 |
+
container.appendChild(content);
|
1267 |
+
|
1268 |
+
// Show the container
|
1269 |
+
container.style.display = 'block';
|
1270 |
+
|
1271 |
+
// Collapse all accordions
|
1272 |
+
const accordions = document.querySelectorAll('.accordion-section');
|
1273 |
+
accordions.forEach(accordion => {
|
1274 |
+
const header = accordion.querySelector('.accordion-header');
|
1275 |
+
const body = accordion.querySelector('.accordion-body');
|
1276 |
+
if (header && body && !header.classList.contains('collapsed')) {
|
1277 |
+
header.classList.add('collapsed');
|
1278 |
+
body.classList.add('collapsed');
|
1279 |
+
|
1280 |
+
// Update the toggle icon
|
1281 |
+
const toggleIcon = header.querySelector('.toggle-icon');
|
1282 |
+
if (toggleIcon) toggleIcon.textContent = '▶';
|
1283 |
+
}
|
1284 |
+
});
|
1285 |
+
|
1286 |
+
// Scroll to the insights container
|
1287 |
+
container.scrollIntoView({ behavior: 'smooth' });
|
1288 |
+
|
1289 |
+
// Remove the pulse animation after a few seconds
|
1290 |
+
setTimeout(() => {
|
1291 |
+
const aiSelectBtn = document.getElementById('aiSelectButton');
|
1292 |
+
if (aiSelectBtn) {
|
1293 |
+
aiSelectBtn.classList.remove('pulse');
|
1294 |
+
}
|
1295 |
+
}, 5000);
|
1296 |
+
}
|
1297 |
+
|
1298 |
+
function enhanceProblem() {
|
1299 |
+
const problemInput = document.getElementById('userProblemDescription');
|
1300 |
+
const originalProblem = problemInput.value.trim();
|
1301 |
+
|
1302 |
+
if (!originalProblem) {
|
1303 |
+
alert('Please provide a technical problem description first');
|
1304 |
+
return;
|
1305 |
+
}
|
1306 |
+
|
1307 |
+
const selectedInsights = collectAllSelectedInsights();
|
1308 |
+
if (selectedInsights.length === 0) {
|
1309 |
+
alert('Please select at least one insight to enhance the problem');
|
1310 |
+
return;
|
1311 |
+
}
|
1312 |
+
|
1313 |
+
// Get user comments if any
|
1314 |
+
const userComments = document.getElementById('insightCommentArea')?.value || '';
|
1315 |
+
|
1316 |
+
// If we have stored refined problems for this exact problem, just show them
|
1317 |
+
const currentProblemKey = JSON.stringify({
|
1318 |
+
problem: originalProblem,
|
1319 |
+
insights: selectedInsights.sort(),
|
1320 |
+
comments: userComments
|
1321 |
+
});
|
1322 |
+
|
1323 |
+
if (storedRefinedProblems[currentProblemKey]) {
|
1324 |
+
showRefinedProblems(storedRefinedProblems[currentProblemKey]);
|
1325 |
+
return;
|
1326 |
+
}
|
1327 |
+
|
1328 |
+
// Show loading overlay
|
1329 |
+
const loadingOverlay = document.getElementById('globalLoadingOverlay');
|
1330 |
+
if (loadingOverlay) {
|
1331 |
+
loadingOverlay.style.display = 'flex';
|
1332 |
+
loadingOverlay.querySelector('.progress-text').textContent = 'Enhancing problem statement...';
|
1333 |
+
}
|
1334 |
+
|
1335 |
+
// Send request to backend to refine the problem
|
1336 |
+
fetch('/refine-problem', {
|
1337 |
+
method: 'POST',
|
1338 |
+
body: JSON.stringify({
|
1339 |
+
'original_problem': originalProblem,
|
1340 |
+
'insights': selectedInsights,
|
1341 |
+
'user_comments': userComments
|
1342 |
+
}),
|
1343 |
+
headers: { 'Content-Type': 'application/json' }
|
1344 |
+
})
|
1345 |
+
.then(response => response.json())
|
1346 |
+
.then(data => {
|
1347 |
+
// Hide loading overlay
|
1348 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
1349 |
+
|
1350 |
+
if (data.error) {
|
1351 |
+
alert(`Error: ${data.error}`);
|
1352 |
+
return;
|
1353 |
+
}
|
1354 |
+
|
1355 |
+
if (data.result) {
|
1356 |
+
// Add current problem to history if not already there
|
1357 |
+
if (currentHistoryIndex === -1) {
|
1358 |
+
problemHistory.push(originalProblem);
|
1359 |
+
currentHistoryIndex = 0;
|
1360 |
+
}
|
1361 |
+
|
1362 |
+
// Store the refined problems for future use
|
1363 |
+
storedRefinedProblems[currentProblemKey] = data.result;
|
1364 |
+
|
1365 |
+
// Show refined problem options
|
1366 |
+
showRefinedProblems(data.result);
|
1367 |
+
}
|
1368 |
+
})
|
1369 |
+
.catch(error => {
|
1370 |
+
console.error('Error:', error);
|
1371 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
1372 |
+
alert(`Error enhancing problem: ${error.message}`);
|
1373 |
+
});
|
1374 |
+
}
|
1375 |
+
|
1376 |
+
function closeGroupedInsights() {
|
1377 |
+
const container = document.getElementById('groupedInsightsContainer');
|
1378 |
+
if (container) {
|
1379 |
+
container.style.display = 'none';
|
1380 |
+
}
|
1381 |
+
}
|
1382 |
+
|
1383 |
+
// Select all insights for a specific score
|
1384 |
+
function selectAllInScore(score) {
|
1385 |
+
const container = document.getElementById('groupedInsightsContainer');
|
1386 |
+
const tags = container.querySelectorAll(`.grouped-insight-tag[data-score="${score}"]`);
|
1387 |
+
|
1388 |
+
tags.forEach(tag => {
|
1389 |
+
tag.classList.add('selected');
|
1390 |
+
});
|
1391 |
+
|
1392 |
+
updateGroupedInsightSelections();
|
1393 |
+
}
|
1394 |
+
|
1395 |
+
// Clear all insights for a specific score
|
1396 |
+
function clearAllInScore(score) {
|
1397 |
+
const container = document.getElementById('groupedInsightsContainer');
|
1398 |
+
const tags = container.querySelectorAll(`.grouped-insight-tag[data-score="${score}"]`);
|
1399 |
+
|
1400 |
+
tags.forEach(tag => {
|
1401 |
+
tag.classList.remove('selected');
|
1402 |
+
});
|
1403 |
+
|
1404 |
+
updateGroupedInsightSelections();
|
1405 |
+
}
|
1406 |
+
|
1407 |
+
function updateGroupedInsightSelections() {
|
1408 |
+
// Get all selected insights from the grouped view
|
1409 |
+
const container = document.getElementById('groupedInsightsContainer');
|
1410 |
+
const selectedTags = container.querySelectorAll('.grouped-insight-tag.selected');
|
1411 |
+
|
1412 |
+
// Create a mapping of URL to selected insights
|
1413 |
+
const selectionsBySource = {};
|
1414 |
+
|
1415 |
+
// Process each selected tag
|
1416 |
+
selectedTags.forEach(tag => {
|
1417 |
+
const insight = tag.textContent.trim().replace(/\d+$/, '').trim(); // Remove the score number at the end
|
1418 |
+
const sourceUrl = tag.dataset.source;
|
1419 |
+
|
1420 |
+
if (!selectionsBySource[sourceUrl]) {
|
1421 |
+
selectionsBySource[sourceUrl] = [];
|
1422 |
+
}
|
1423 |
+
|
1424 |
+
selectionsBySource[sourceUrl].push(insight);
|
1425 |
+
});
|
1426 |
+
|
1427 |
+
// Now update the original document rows
|
1428 |
+
const queryItems = document.querySelectorAll('.query-item');
|
1429 |
+
queryItems.forEach(queryItem => {
|
1430 |
+
const rows = queryItem.querySelectorAll('tbody tr:not(.insights-row)');
|
1431 |
+
rows.forEach(row => {
|
1432 |
+
const urlLink = row.querySelector('.url-link');
|
1433 |
+
if (!urlLink) return;
|
1434 |
+
|
1435 |
+
const sourceUrl = urlLink.href;
|
1436 |
+
|
1437 |
+
// If we have selections for this source
|
1438 |
+
if (selectionsBySource[sourceUrl]) {
|
1439 |
+
// Get all insights for this row
|
1440 |
+
try {
|
1441 |
+
// Combine selected and unselected to get all insights
|
1442 |
+
const currentSelected = JSON.parse(row.dataset.selectedInsights || '[]');
|
1443 |
+
const currentUnselected = JSON.parse(row.dataset.unselectedInsights || '[]');
|
1444 |
+
const allInsights = [...currentSelected, ...currentUnselected];
|
1445 |
+
|
1446 |
+
// New selected and unselected based on grouped view
|
1447 |
+
const newSelected = [];
|
1448 |
+
const newUnselected = [];
|
1449 |
+
|
1450 |
+
// Process each insight
|
1451 |
+
allInsights.forEach(insight => {
|
1452 |
+
if (selectionsBySource[sourceUrl].includes(insight)) {
|
1453 |
+
newSelected.push(insight);
|
1454 |
+
} else {
|
1455 |
+
newUnselected.push(insight);
|
1456 |
+
}
|
1457 |
+
});
|
1458 |
+
|
1459 |
+
// Update the dataset
|
1460 |
+
row.dataset.selectedInsights = JSON.stringify(newSelected);
|
1461 |
+
row.dataset.unselectedInsights = JSON.stringify(newUnselected);
|
1462 |
+
} catch (e) {
|
1463 |
+
console.error('Error updating insights selections:', e);
|
1464 |
+
}
|
1465 |
+
}
|
1466 |
+
});
|
1467 |
+
});
|
1468 |
+
|
1469 |
+
// Update enhance button state
|
1470 |
+
checkSelectedInsights();
|
1471 |
+
}
|
1472 |
+
|
1473 |
+
function showRefinedProblems(result) {
|
1474 |
+
const refinedContainer = document.getElementById('refinedProblemContainer');
|
1475 |
+
const tabs = document.getElementById('refinedProblemTabs');
|
1476 |
+
const content = document.getElementById('refinedProblemContent');
|
1477 |
+
|
1478 |
+
// Clear previous content
|
1479 |
+
tabs.innerHTML = '';
|
1480 |
+
content.innerHTML = '';
|
1481 |
+
|
1482 |
+
// Add tabs and content for each refined problem
|
1483 |
+
let isFirst = true;
|
1484 |
+
for (const key in result) {
|
1485 |
+
if (result.hasOwnProperty(key)) {
|
1486 |
+
const problem = result[key];
|
1487 |
+
|
1488 |
+
// Create tab
|
1489 |
+
const tab = document.createElement('div');
|
1490 |
+
tab.className = `refined-problem-tab ${isFirst ? 'active' : ''}`;
|
1491 |
+
tab.dataset.target = key;
|
1492 |
+
tab.textContent = `Option ${key.split('_')[1]}`;
|
1493 |
+
tab.onclick = function() {
|
1494 |
+
document.querySelectorAll('.refined-problem-tab').forEach(t => t.classList.remove('active'));
|
1495 |
+
document.querySelectorAll('.refined-problem').forEach(p => p.classList.remove('active'));
|
1496 |
+
tab.classList.add('active');
|
1497 |
+
document.getElementById(key).classList.add('active');
|
1498 |
+
};
|
1499 |
+
tabs.appendChild(tab);
|
1500 |
+
|
1501 |
+
// Create content
|
1502 |
+
const problemDiv = document.createElement('div');
|
1503 |
+
problemDiv.className = `refined-problem ${isFirst ? 'active' : ''}`;
|
1504 |
+
problemDiv.id = key;
|
1505 |
+
|
1506 |
+
const title = document.createElement('div');
|
1507 |
+
title.className = 'refined-problem-title';
|
1508 |
+
title.textContent = problem.title;
|
1509 |
+
|
1510 |
+
const description = document.createElement('div');
|
1511 |
+
description.className = 'refined-problem-description';
|
1512 |
+
description.textContent = problem.description;
|
1513 |
+
|
1514 |
+
const applyButton = document.createElement('button');
|
1515 |
+
applyButton.className = 'apply-problem-btn';
|
1516 |
+
applyButton.textContent = 'Apply This Problem';
|
1517 |
+
applyButton.onclick = function() {
|
1518 |
+
applyRefinedProblem(problem.description);
|
1519 |
+
};
|
1520 |
+
|
1521 |
+
problemDiv.appendChild(title);
|
1522 |
+
problemDiv.appendChild(description);
|
1523 |
+
problemDiv.appendChild(applyButton);
|
1524 |
+
|
1525 |
+
content.appendChild(problemDiv);
|
1526 |
+
|
1527 |
+
isFirst = false;
|
1528 |
+
}
|
1529 |
+
}
|
1530 |
+
|
1531 |
+
// Show the container
|
1532 |
+
refinedContainer.style.display = 'block';
|
1533 |
+
|
1534 |
+
// Scroll to the container
|
1535 |
+
refinedContainer.scrollIntoView({ behavior: 'smooth' });
|
1536 |
+
}
|
1537 |
+
|
1538 |
+
function applyRefinedProblem(problemText) {
|
1539 |
+
const problemInput = document.getElementById('userProblemDescription');
|
1540 |
+
|
1541 |
+
// Add current problem to history
|
1542 |
+
problemHistory.push(problemInput.value);
|
1543 |
+
currentHistoryIndex = problemHistory.length - 1; // Set to latest version
|
1544 |
+
|
1545 |
+
// Update problem text with the new version
|
1546 |
+
problemInput.value = problemText;
|
1547 |
+
|
1548 |
+
// Now add the new version to history
|
1549 |
+
problemHistory.push(problemText);
|
1550 |
+
currentHistoryIndex = problemHistory.length - 1; // Update index to point to the newly added version
|
1551 |
+
|
1552 |
+
// Update history navigation display
|
1553 |
+
updateHistoryNavigation();
|
1554 |
+
|
1555 |
+
// Display is kept visible, removed: document.getElementById('refinedProblemContainer').style.display = 'none';
|
1556 |
+
|
1557 |
+
// Focus on the problem input
|
1558 |
+
problemInput.focus();
|
1559 |
+
|
1560 |
+
console.log("Problem history after applying:", problemHistory, "Current index:", currentHistoryIndex);
|
1561 |
+
}
|
1562 |
+
|
1563 |
+
function updateHistoryNavigation() {
|
1564 |
+
const historyNav = document.getElementById('problemHistoryNav');
|
1565 |
+
const prevBtn = historyNav.querySelector('.history-prev');
|
1566 |
+
const nextBtn = historyNav.querySelector('.history-next');
|
1567 |
+
const status = historyNav.querySelector('.history-status');
|
1568 |
+
|
1569 |
+
// Update buttons state
|
1570 |
+
prevBtn.classList.toggle('disabled', currentHistoryIndex <= 0);
|
1571 |
+
nextBtn.classList.toggle('disabled', currentHistoryIndex >= problemHistory.length - 1);
|
1572 |
+
|
1573 |
+
// Update status text
|
1574 |
+
if (problemHistory.length > 0) {
|
1575 |
+
status.textContent = `Version ${currentHistoryIndex + 1} of ${problemHistory.length}`;
|
1576 |
+
historyNav.style.display = 'flex';
|
1577 |
+
} else {
|
1578 |
+
historyNav.style.display = 'none';
|
1579 |
+
}
|
1580 |
+
}
|
1581 |
+
|
1582 |
+
function aiSelectInsights() {
|
1583 |
+
const patentBackground = document.getElementById('userProblemDescription').value.trim();
|
1584 |
+
if (!patentBackground) {
|
1585 |
+
alert('Please provide a patent background in the input field');
|
1586 |
+
return;
|
1587 |
+
}
|
1588 |
+
|
1589 |
+
// Change button appearance to show it's working
|
1590 |
+
const aiSelectBtn = document.getElementById('aiSelectButton');
|
1591 |
+
if (aiSelectBtn) {
|
1592 |
+
aiSelectBtn.disabled = true;
|
1593 |
+
aiSelectBtn.textContent = 'AI Selecting...';
|
1594 |
+
aiSelectBtn.style.opacity = '0.7';
|
1595 |
+
}
|
1596 |
+
|
1597 |
+
// Show loading overlay
|
1598 |
+
const loadingOverlay = document.getElementById('globalLoadingOverlay');
|
1599 |
+
if (loadingOverlay) {
|
1600 |
+
loadingOverlay.style.display = 'flex';
|
1601 |
+
loadingOverlay.querySelector('.progress-text').textContent = 'AI selecting the most relevant insights...';
|
1602 |
+
}
|
1603 |
+
|
1604 |
+
// Get all insights from all score groups
|
1605 |
+
const container = document.getElementById('groupedInsightsContainer');
|
1606 |
+
const insightTags = container.querySelectorAll('.grouped-insight-tag');
|
1607 |
+
const insights = Array.from(insightTags).map(tag => {
|
1608 |
+
return tag.textContent.trim().replace(/\d+$/, '').trim(); // Remove the score number
|
1609 |
+
});
|
1610 |
+
|
1611 |
+
if (insights.length === 0) {
|
1612 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
1613 |
+
alert('No insights found');
|
1614 |
+
return;
|
1615 |
+
}
|
1616 |
+
|
1617 |
+
// Send request to backend to get AI selection
|
1618 |
+
fetch('/ai-select-insights', {
|
1619 |
+
method: 'POST',
|
1620 |
+
body: JSON.stringify({
|
1621 |
+
'patent_background': patentBackground,
|
1622 |
+
'insights': insights
|
1623 |
+
}),
|
1624 |
+
headers: { 'Content-Type': 'application/json' }
|
1625 |
+
})
|
1626 |
+
.then(response => response.json())
|
1627 |
+
.then(data => {
|
1628 |
+
// Reset button appearance
|
1629 |
+
if (aiSelectBtn) {
|
1630 |
+
aiSelectBtn.disabled = false;
|
1631 |
+
aiSelectBtn.textContent = 'AI Select Insights';
|
1632 |
+
aiSelectBtn.style.opacity = '1';
|
1633 |
+
}
|
1634 |
+
|
1635 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
1636 |
+
|
1637 |
+
if (data.error) {
|
1638 |
+
alert(`Error: ${data.error}`);
|
1639 |
+
return;
|
1640 |
+
}
|
1641 |
+
|
1642 |
+
if (data.selected_insights && data.selected_insights.length > 0) {
|
1643 |
+
// First clear all selections
|
1644 |
+
insightTags.forEach(tag => {
|
1645 |
+
tag.classList.remove('selected');
|
1646 |
+
});
|
1647 |
+
|
1648 |
+
// Then select the recommended insights
|
1649 |
+
insightTags.forEach(tag => {
|
1650 |
+
const insightText = tag.textContent.trim().replace(/\d+$/, '').trim();
|
1651 |
+
if (data.selected_insights.includes(insightText)) {
|
1652 |
+
tag.classList.add('selected');
|
1653 |
+
}
|
1654 |
+
});
|
1655 |
+
|
1656 |
+
// Update the original document rows
|
1657 |
+
updateGroupedInsightSelections();
|
1658 |
+
|
1659 |
+
// Remove alert notification - user can see the selected insights visually
|
1660 |
+
// alert(`AI selected ${data.selected_insights.length} insights from ${insights.length} available insights`);
|
1661 |
+
} else {
|
1662 |
+
alert('AI could not identify any relevant insights to select');
|
1663 |
+
}
|
1664 |
+
})
|
1665 |
+
.catch(error => {
|
1666 |
+
console.error('Error:', error);
|
1667 |
+
|
1668 |
+
// Reset button appearance
|
1669 |
+
if (aiSelectBtn) {
|
1670 |
+
aiSelectBtn.disabled = false;
|
1671 |
+
aiSelectBtn.textContent = 'AI Select Insights';
|
1672 |
+
aiSelectBtn.style.opacity = '1';
|
1673 |
+
}
|
1674 |
+
|
1675 |
+
if (loadingOverlay) loadingOverlay.style.display = 'none';
|
1676 |
+
alert(`Error using AI to select insights: ${error.message}`);
|
1677 |
+
});
|
1678 |
+
}
|
1679 |
+
|
1680 |
+
function generateSearchQueries() {
|
1681 |
+
function addQueryField(queryText = '', container = null) {
|
1682 |
+
const queriesContainer = container || document.getElementById('queriesContainer');
|
1683 |
+
|
1684 |
+
// Count existing query items in this container for indexing
|
1685 |
+
const queryItems = container ?
|
1686 |
+
container.querySelectorAll('.query-item') :
|
1687 |
+
document.getElementById('queriesContainer').querySelectorAll('.query-item');
|
1688 |
+
|
1689 |
+
const queryIndex = queryItems.length + 1;
|
1690 |
+
|
1691 |
+
// Create main container for this query item
|
1692 |
+
const queryItem = document.createElement('div');
|
1693 |
+
queryItem.className = 'query-item';
|
1694 |
+
|
1695 |
+
// Create container for query field and buttons
|
1696 |
+
const queryContainer = document.createElement('div');
|
1697 |
+
queryContainer.className = 'query-container';
|
1698 |
+
|
1699 |
+
// Input field
|
1700 |
+
const queryField = document.createElement('input');
|
1701 |
+
queryField.type = 'text';
|
1702 |
+
queryField.className = 'query-field';
|
1703 |
+
queryField.value = queryText;
|
1704 |
+
queryField.placeholder = `Search Query ${queryIndex}`;
|
1705 |
+
|
1706 |
+
// Delete button
|
1707 |
+
const deleteButton = document.createElement('button');
|
1708 |
+
deleteButton.type = 'button';
|
1709 |
+
deleteButton.className = 'action-button delete-button';
|
1710 |
+
deleteButton.textContent = 'Delete';
|
1711 |
+
deleteButton.onclick = function() {
|
1712 |
+
queryItem.parentNode.removeChild(queryItem);
|
1713 |
+
|
1714 |
+
// Update the placeholder numbers for remaining queries within this container
|
1715 |
+
const parent = container || document.getElementById('queriesContainer');
|
1716 |
+
const items = parent.querySelectorAll('.query-item');
|
1717 |
+
items.forEach((item, idx) => {
|
1718 |
+
const field = item.querySelector('.query-field');
|
1719 |
+
if (field) field.placeholder = `Search Query ${idx + 1}`;
|
1720 |
+
});
|
1721 |
+
};
|
1722 |
+
|
1723 |
+
// Search button
|
1724 |
+
const searchButton = document.createElement('button');
|
1725 |
+
searchButton.type = 'button';
|
1726 |
+
searchButton.className = 'action-button search-button';
|
1727 |
+
searchButton.textContent = 'Search';
|
1728 |
+
searchButton.onclick = function() {
|
1729 |
+
performSearch(queryField.value, queryItem);
|
1730 |
+
};
|
1731 |
+
|
1732 |
+
// Add elements to container
|
1733 |
+
queryContainer.appendChild(queryField);
|
1734 |
+
queryContainer.appendChild(searchButton);
|
1735 |
+
queryContainer.appendChild(deleteButton);
|
1736 |
+
|
1737 |
+
// Create loading indicator for this search
|
1738 |
+
const searchLoading = document.createElement('div');
|
1739 |
+
searchLoading.className = 'search-loading';
|
1740 |
+
searchLoading.textContent = 'Searching... Please wait.';
|
1741 |
+
|
1742 |
+
// Create table for results
|
1743 |
+
const resultsTable = document.createElement('table');
|
1744 |
+
resultsTable.className = 'results-table';
|
1745 |
+
|
1746 |
+
// Add table header
|
1747 |
+
const tableHeader = document.createElement('thead');
|
1748 |
+
const headerRow = document.createElement('tr');
|
1749 |
+
|
1750 |
+
const typeHeader = document.createElement('th');
|
1751 |
+
typeHeader.textContent = 'Type';
|
1752 |
+
|
1753 |
+
const titleHeader = document.createElement('th');
|
1754 |
+
titleHeader.textContent = 'Title';
|
1755 |
+
|
1756 |
+
const bodyHeader = document.createElement('th');
|
1757 |
+
bodyHeader.textContent = 'Description';
|
1758 |
+
|
1759 |
+
const urlHeader = document.createElement('th');
|
1760 |
+
urlHeader.textContent = 'URL';
|
1761 |
+
|
1762 |
+
const scoreHeader = document.createElement('th');
|
1763 |
+
scoreHeader.textContent = 'Score';
|
1764 |
+
|
1765 |
+
const justificationHeader = document.createElement('th');
|
1766 |
+
justificationHeader.textContent = 'Justification';
|
1767 |
+
|
1768 |
+
headerRow.appendChild(typeHeader);
|
1769 |
+
headerRow.appendChild(titleHeader);
|
1770 |
+
headerRow.appendChild(bodyHeader);
|
1771 |
+
headerRow.appendChild(urlHeader);
|
1772 |
+
headerRow.appendChild(scoreHeader);
|
1773 |
+
headerRow.appendChild(justificationHeader);
|
1774 |
+
tableHeader.appendChild(headerRow);
|
1775 |
+
|
1776 |
+
// Add table body
|
1777 |
+
const tableBody = document.createElement('tbody');
|
1778 |
+
|
1779 |
+
resultsTable.appendChild(tableHeader);
|
1780 |
+
resultsTable.appendChild(tableBody);
|
1781 |
+
|
1782 |
+
// Add all elements to the query item
|
1783 |
+
queryItem.appendChild(queryContainer);
|
1784 |
+
queryItem.appendChild(searchLoading);
|
1785 |
+
queryItem.appendChild(resultsTable);
|
1786 |
+
|
1787 |
+
// Add container to the queries list
|
1788 |
+
queriesContainer.appendChild(queryItem);
|
1789 |
+
}
|
1790 |
+
|
1791 |
+
function createAccordionSection(timestamp) {
|
1792 |
+
const accordionSection = document.createElement('div');
|
1793 |
+
accordionSection.className = 'accordion-section';
|
1794 |
+
|
1795 |
+
const accordionHeader = document.createElement('div');
|
1796 |
+
accordionHeader.className = 'accordion-header';
|
1797 |
+
accordionHeader.innerHTML = `
|
1798 |
+
<span>Search Results <span class="query-timestamp">${timestamp}</span></span>
|
1799 |
+
<span class="toggle-icon">▼</span>
|
1800 |
+
`;
|
1801 |
+
accordionHeader.onclick = function() {
|
1802 |
+
this.classList.toggle('collapsed');
|
1803 |
+
const body = this.nextElementSibling;
|
1804 |
+
body.classList.toggle('collapsed');
|
1805 |
+
|
1806 |
+
// Update the toggle icon
|
1807 |
+
const toggleIcon = this.querySelector('.toggle-icon');
|
1808 |
+
if (body.classList.contains('collapsed')) {
|
1809 |
+
toggleIcon.textContent = '▶';
|
1810 |
+
} else {
|
1811 |
+
toggleIcon.textContent = '▼';
|
1812 |
+
}
|
1813 |
+
};
|
1814 |
+
|
1815 |
+
const accordionBody = document.createElement('div');
|
1816 |
+
accordionBody.className = 'accordion-body';
|
1817 |
+
|
1818 |
+
const accordionContent = document.createElement('div');
|
1819 |
+
accordionContent.className = 'accordion-content';
|
1820 |
+
accordionBody.appendChild(accordionContent);
|
1821 |
+
|
1822 |
+
accordionSection.appendChild(accordionHeader);
|
1823 |
+
accordionSection.appendChild(accordionBody);
|
1824 |
+
|
1825 |
+
return accordionSection;
|
1826 |
+
}
|
1827 |
+
|
1828 |
+
const userInput = document.getElementById('userProblemDescription').value.trim();
|
1829 |
+
if (!userInput) {
|
1830 |
+
alert('Please enter a technical problem description');
|
1831 |
+
return;
|
1832 |
+
}
|
1833 |
+
|
1834 |
+
// Show loading indicator
|
1835 |
+
document.getElementById('loadingIndicator').style.display = 'block';
|
1836 |
+
|
1837 |
+
// Collapse all existing query sections
|
1838 |
+
const existingAccordions = document.querySelectorAll('.accordion-section');
|
1839 |
+
existingAccordions.forEach(accordion => {
|
1840 |
+
const header = accordion.querySelector('.accordion-header');
|
1841 |
+
const body = accordion.querySelector('.accordion-body');
|
1842 |
+
if (header && body && !header.classList.contains('collapsed')) {
|
1843 |
+
header.classList.add('collapsed');
|
1844 |
+
body.classList.add('collapsed');
|
1845 |
+
}
|
1846 |
+
});
|
1847 |
+
|
1848 |
+
// Send message to Flask backend
|
1849 |
+
fetch('/chat', {
|
1850 |
+
method: 'POST',
|
1851 |
+
body: new URLSearchParams({ 'message': userInput }),
|
1852 |
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
1853 |
+
})
|
1854 |
+
.then(response => response.json())
|
1855 |
+
.then(data => {
|
1856 |
+
// Hide loading indicator
|
1857 |
+
document.getElementById('loadingIndicator').style.display = 'none';
|
1858 |
+
|
1859 |
+
try {
|
1860 |
+
// Parse the JSON string from the LLM response
|
1861 |
+
let jsonData;
|
1862 |
+
// First check if data.reply is already an object
|
1863 |
+
if (typeof data.reply === 'object') {
|
1864 |
+
jsonData = data.reply;
|
1865 |
+
} else {
|
1866 |
+
// Try to extract JSON if it's a string possibly with markdown code blocks
|
1867 |
+
const jsonString = data.reply.replace(/```json|```/g, '').trim();
|
1868 |
+
jsonData = JSON.parse(jsonString);
|
1869 |
+
}
|
1870 |
+
|
1871 |
+
// Create a new accordion section for these search results
|
1872 |
+
const timestamp = new Date().toLocaleString();
|
1873 |
+
const accordionSection = createAccordionSection(timestamp);
|
1874 |
+
|
1875 |
+
// Add each query from the response to this accordion
|
1876 |
+
Object.keys(jsonData).forEach(key => {
|
1877 |
+
addQueryField(jsonData[key], accordionSection.querySelector('.accordion-content'));
|
1878 |
+
});
|
1879 |
+
|
1880 |
+
// Add the accordion to the container
|
1881 |
+
const queriesContainer = document.getElementById('queriesContainer');
|
1882 |
+
queriesContainer.insertBefore(accordionSection, queriesContainer.firstChild);
|
1883 |
+
|
1884 |
+
// Show results container
|
1885 |
+
document.getElementById('resultsContainer').style.display = 'block';
|
1886 |
+
} catch (error) {
|
1887 |
+
console.error('Error parsing JSON:', error);
|
1888 |
+
alert('There was an error processing the response. Please try again.');
|
1889 |
+
}
|
1890 |
+
})
|
1891 |
+
.catch(error => {
|
1892 |
+
document.getElementById('loadingIndicator').style.display = 'none';
|
1893 |
+
console.error('Error:', error);
|
1894 |
+
alert('There was an error communicating with the server. Please try again.');
|
1895 |
+
});
|
1896 |
+
}
|
1897 |
+
|
1898 |
+
function displayKeyIssues(keyIssues) {
|
1899 |
+
// Get or create the key issues container
|
1900 |
+
let keyIssuesContainer = document.getElementById('keyIssuesContainer');
|
1901 |
+
if (!keyIssuesContainer) {
|
1902 |
+
keyIssuesContainer = document.createElement('div');
|
1903 |
+
keyIssuesContainer.id = 'keyIssuesContainer';
|
1904 |
+
keyIssuesContainer.className = 'key-issues-container';
|
1905 |
+
document.getElementById('resultsContainer').appendChild(keyIssuesContainer);
|
1906 |
+
}
|
1907 |
+
|
1908 |
+
// Clear previous content
|
1909 |
+
keyIssuesContainer.innerHTML = '';
|
1910 |
+
|
1911 |
+
// Create header
|
1912 |
+
const header = document.createElement('h3');
|
1913 |
+
header.textContent = 'Key Issues';
|
1914 |
+
keyIssuesContainer.appendChild(header);
|
1915 |
+
|
1916 |
+
// Create issues list
|
1917 |
+
const issuesList = document.createElement('div');
|
1918 |
+
issuesList.className = 'key-issues-list';
|
1919 |
+
|
1920 |
+
const KIsubmitButton = document.createElement('button');
|
1921 |
+
KIsubmitButton.className = "btn btn-primary";
|
1922 |
+
KIsubmitButton.id = "key-issues-submit-btn";
|
1923 |
+
KIsubmitButton.textContent = "Generate problem descriptions";
|
1924 |
+
KIsubmitButton.style.marginTop = "10px";
|
1925 |
+
KIsubmitButton.onclick = generateProblemDescriptions;
|
1926 |
+
|
1927 |
+
const centerButton = document.createElement("center");
|
1928 |
+
centerButton.appendChild(KIsubmitButton);
|
1929 |
+
|
1930 |
+
|
1931 |
+
// Add each key issue
|
1932 |
+
keyIssues.forEach(issue => {
|
1933 |
+
const issueCard = document.createElement('div');
|
1934 |
+
issueCard.className = 'key-issue-card';
|
1935 |
+
issueCard.dataset.id = issue.id;
|
1936 |
+
|
1937 |
+
const issueTitle = document.createElement('div');
|
1938 |
+
issueTitle.className = 'key-issue-title';
|
1939 |
+
issueTitle.textContent = issue.title;
|
1940 |
+
|
1941 |
+
const issueDescription = document.createElement('div');
|
1942 |
+
issueDescription.className = 'key-issue-description';
|
1943 |
+
issueDescription.textContent = issue.description;
|
1944 |
+
|
1945 |
+
const challengesTitle = document.createElement('div');
|
1946 |
+
challengesTitle.style.fontWeight = 'bold';
|
1947 |
+
challengesTitle.style.marginTop = '10px';
|
1948 |
+
challengesTitle.textContent = 'Challenges:';
|
1949 |
+
|
1950 |
+
const challengesList = document.createElement('ul');
|
1951 |
+
challengesList.className = 'key-issue-challenges';
|
1952 |
+
|
1953 |
+
issue.challenges.forEach(challenge => {
|
1954 |
+
const challengeItem = document.createElement('li');
|
1955 |
+
challengeItem.textContent = challenge;
|
1956 |
+
challengesList.appendChild(challengeItem);
|
1957 |
+
});
|
1958 |
+
|
1959 |
+
const impactTitle = document.createElement('div');
|
1960 |
+
impactTitle.style.fontWeight = 'bold';
|
1961 |
+
impactTitle.style.marginTop = '10px';
|
1962 |
+
impactTitle.textContent = 'Potential Impact:';
|
1963 |
+
|
1964 |
+
const issueImpact = document.createElement('div');
|
1965 |
+
issueImpact.className = 'key-issue-impact';
|
1966 |
+
issueImpact.textContent = issue.potential_impact;
|
1967 |
+
|
1968 |
+
// Add click handler to toggle selection
|
1969 |
+
issueCard.addEventListener('click', function() {
|
1970 |
+
this.classList.toggle('selected');
|
1971 |
+
});
|
1972 |
+
|
1973 |
+
// Append all elements
|
1974 |
+
issueCard.appendChild(issueTitle);
|
1975 |
+
issueCard.appendChild(issueDescription);
|
1976 |
+
issueCard.appendChild(challengesTitle);
|
1977 |
+
issueCard.appendChild(challengesList);
|
1978 |
+
issueCard.appendChild(impactTitle);
|
1979 |
+
issueCard.appendChild(issueImpact);
|
1980 |
+
|
1981 |
+
issuesList.appendChild(issueCard);
|
1982 |
+
});
|
1983 |
+
|
1984 |
+
keyIssuesContainer.appendChild(issuesList);
|
1985 |
+
keyIssuesContainer.appendChild(centerButton);
|
1986 |
+
keyIssuesContainer.style.display = "block";
|
1987 |
+
}
|
1988 |
+
|
1989 |
+
function generateProblemDescriptions(){
|
1990 |
+
let result = {
|
1991 |
+
descriptions: {},
|
1992 |
+
challenges: {}
|
1993 |
+
};
|
1994 |
+
|
1995 |
+
const selectedCards = document.querySelectorAll(".key-issue-card.selected");
|
1996 |
+
|
1997 |
+
selectedCards.forEach(card => {
|
1998 |
+
const userInput = document.getElementById('userInput').value.trim();
|
1999 |
+
const id = card.getAttribute("data-id");
|
2000 |
+
const description = card.querySelector('.key-issue-description').textContent.trim();
|
2001 |
+
const challenges = Array.from(card.querySelectorAll(".key-issue-challenges li")).map(challenge => challenge.textContent.trim());
|
2002 |
+
|
2003 |
+
result.descriptions[id] = description;
|
2004 |
+
result.challenges[id] = challenges;
|
2005 |
+
result["technical_topic"] = userInput;
|
2006 |
+
})
|
2007 |
+
|
2008 |
+
document.querySelector('.progress-text').innerHTML = "Generating problem descriptions ... This may take a while."
|
2009 |
+
document.getElementById('globalLoadingOverlay').style.display = 'flex';
|
2010 |
+
|
2011 |
+
// Send message to Flask backend
|
2012 |
+
fetch('https://organizedprogrammers-fastapi-kig.hf.space/create-several-probdesc', {
|
2013 |
+
method: 'POST',
|
2014 |
+
body: JSON.stringify(result),
|
2015 |
+
headers: { 'Content-Type': 'application/json' }
|
2016 |
+
})
|
2017 |
+
.then(response => response.json())
|
2018 |
+
.then(data => {
|
2019 |
+
// Hide loading indicator
|
2020 |
+
document.getElementById('globalLoadingOverlay').style.display = 'none';
|
2021 |
+
|
2022 |
+
// Check if we have key issues in the response
|
2023 |
+
if (data.problem_descriptions && data.problem_descriptions.length > 0) {
|
2024 |
+
// Display the key issues
|
2025 |
+
displayProblemDescriptions(data.problem_descriptions);
|
2026 |
+
} else if (data.error) {
|
2027 |
+
alert('Error: ' + data.error);
|
2028 |
+
} else {
|
2029 |
+
alert('No problem descriptions found/generated. Please try again with another or the same query.');
|
2030 |
+
}
|
2031 |
+
})
|
2032 |
+
.catch(error => {
|
2033 |
+
document.getElementById('globalLoadingOverlay').style.display = 'none';
|
2034 |
+
console.error('Error:', error);
|
2035 |
+
alert('There was an error communicating with the server. Please try again.');
|
2036 |
+
});
|
2037 |
+
}
|
2038 |
+
|
2039 |
+
function displayProblemDescriptions(probDescs) {
|
2040 |
+
// Get or create the key issues container
|
2041 |
+
let probDescCards = document.getElementById("probDescCards");
|
2042 |
+
let probDescContainer = document.getElementById('probDescContainer');
|
2043 |
+
// Clear previous content
|
2044 |
+
probDescContainer.innerHTML = '';
|
2045 |
+
|
2046 |
+
// Create header
|
2047 |
+
const header = document.createElement('h3');
|
2048 |
+
header.textContent = 'Problem Descriptions';
|
2049 |
+
probDescContainer.appendChild(header);
|
2050 |
+
|
2051 |
+
// Create issues list
|
2052 |
+
const descriptionList = document.createElement('div');
|
2053 |
+
descriptionList.className = 'prob-desc-list';
|
2054 |
+
|
2055 |
+
// Add each key issue
|
2056 |
+
probDescs.forEach((desc, index) => {
|
2057 |
+
const descCard = document.createElement('div');
|
2058 |
+
descCard.className = 'prob-desc-card';
|
2059 |
+
descCard.dataset.id = index+1;
|
2060 |
+
|
2061 |
+
const descTitle = document.createElement('div');
|
2062 |
+
descTitle.className = 'prob-desc-title';
|
2063 |
+
descTitle.textContent = `Problem Description n°${index+1}`;
|
2064 |
+
|
2065 |
+
const descDescription = document.createElement('div');
|
2066 |
+
descDescription.className = 'prob-desc-description';
|
2067 |
+
descDescription.textContent = desc;
|
2068 |
+
|
2069 |
+
// Add click handler to toggle selection
|
2070 |
+
descCard.addEventListener('click', function() {
|
2071 |
+
document.getElementById("userProblemDescription").textContent = desc;
|
2072 |
+
document.getElementsByClassName("tablinks")[1].click();
|
2073 |
+
});
|
2074 |
+
|
2075 |
+
// Append all elements
|
2076 |
+
descCard.appendChild(descTitle);
|
2077 |
+
descCard.appendChild(descDescription);
|
2078 |
+
|
2079 |
+
descriptionList.appendChild(descCard);
|
2080 |
+
});
|
2081 |
+
|
2082 |
+
probDescContainer.appendChild(descriptionList);
|
2083 |
+
probDescCards.style.display = "block";
|
2084 |
+
}
|
2085 |
+
|
2086 |
+
function initRibbonAccordion() {
|
2087 |
+
const ribbon = document.querySelector('.ribbon-accordion');
|
2088 |
+
const ribbonHeader = ribbon.querySelector('.ribbon-header');
|
2089 |
+
|
2090 |
+
ribbonHeader.addEventListener('click', function() {
|
2091 |
+
ribbon.classList.toggle('collapsed');
|
2092 |
+
});
|
2093 |
+
}
|
2094 |
+
|
2095 |
+
function setupRibbonButtons() {
|
2096 |
+
// Generate Queries
|
2097 |
+
document.getElementById('ribbonGenerateQueriesButton').addEventListener('click', function() {
|
2098 |
+
generateSearchQueries();
|
2099 |
+
});
|
2100 |
+
|
2101 |
+
// Analyze All
|
2102 |
+
document.getElementById('ribbonAnalyzeAllButton').addEventListener('click', function() {
|
2103 |
+
if(hasSearchResults()) {
|
2104 |
+
analyzeAllPapers();
|
2105 |
+
}
|
2106 |
+
});
|
2107 |
+
|
2108 |
+
// Remove Failed
|
2109 |
+
document.getElementById('ribbonRemoveFailedButton').addEventListener('click', function() {
|
2110 |
+
if(hasSearchResults()) {
|
2111 |
+
removeFailedAnalyses();
|
2112 |
+
}
|
2113 |
+
});
|
2114 |
+
|
2115 |
+
// Extract All Insights
|
2116 |
+
document.getElementById('ribbonExtractAllInsightsButton').addEventListener('click', function() {
|
2117 |
+
extractAllInsights();
|
2118 |
+
});
|
2119 |
+
|
2120 |
+
// Group Insights
|
2121 |
+
document.getElementById('ribbonGroupInsightsButton').addEventListener('click', function() {
|
2122 |
+
groupInsightsByScore();
|
2123 |
+
});
|
2124 |
+
|
2125 |
+
// Enhance Problem
|
2126 |
+
document.getElementById('ribbonEnhanceProblemButton').addEventListener('click', function() {
|
2127 |
+
enhanceProblem();
|
2128 |
+
});
|
2129 |
+
|
2130 |
+
// Export to Excel
|
2131 |
+
document.getElementById('ribbonExportExcelButton').addEventListener('click', function() {
|
2132 |
+
if(hasSearchResults()) {
|
2133 |
+
exportToExcel();
|
2134 |
+
}
|
2135 |
+
});
|
2136 |
+
}
|
2137 |
+
|
2138 |
+
initRibbonAccordion();
|
2139 |
+
setupRibbonButtons();
|
static/style.css
ADDED
@@ -0,0 +1,1319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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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 |
+
.tab {
|
47 |
+
overflow: hidden;
|
48 |
+
border: 1px solid #ccc;
|
49 |
+
background-color: #f1f1f1;
|
50 |
+
}
|
51 |
+
|
52 |
+
.tab button {
|
53 |
+
background-color: inherit;
|
54 |
+
float: left;
|
55 |
+
border: none;
|
56 |
+
outline: none;
|
57 |
+
cursor: pointer;
|
58 |
+
padding: 14px 16px;
|
59 |
+
transition: 0.3s;
|
60 |
+
}
|
61 |
+
|
62 |
+
.tab button.active {
|
63 |
+
background-color: #ccc;
|
64 |
+
}
|
65 |
+
|
66 |
+
.tabcontent {
|
67 |
+
display: none;
|
68 |
+
}
|
69 |
+
|
70 |
+
.container {
|
71 |
+
max-width: 1000px;
|
72 |
+
margin: 0 auto;
|
73 |
+
}
|
74 |
+
|
75 |
+
.header {
|
76 |
+
margin-bottom: 2.5rem;
|
77 |
+
text-align: center;
|
78 |
+
}
|
79 |
+
|
80 |
+
.logo {
|
81 |
+
display: flex;
|
82 |
+
align-items: center;
|
83 |
+
justify-content: center;
|
84 |
+
margin-bottom: 1rem;
|
85 |
+
}
|
86 |
+
|
87 |
+
.logo-icon {
|
88 |
+
width: 40px;
|
89 |
+
height: 40px;
|
90 |
+
background-color: var(--primary);
|
91 |
+
border-radius: 8px;
|
92 |
+
color: white;
|
93 |
+
display: flex;
|
94 |
+
align-items: center;
|
95 |
+
justify-content: center;
|
96 |
+
font-weight: bold;
|
97 |
+
font-size: 1.5rem;
|
98 |
+
margin-right: 10px;
|
99 |
+
}
|
100 |
+
|
101 |
+
h1 {
|
102 |
+
font-size: 2rem;
|
103 |
+
font-weight: 700;
|
104 |
+
color: var(--gray-900);
|
105 |
+
margin-bottom: 0.5rem;
|
106 |
+
}
|
107 |
+
|
108 |
+
h2 {
|
109 |
+
font-size: 1.5rem;
|
110 |
+
font-weight: 600;
|
111 |
+
color: var(--gray-800);
|
112 |
+
margin-bottom: 1.5rem;
|
113 |
+
}
|
114 |
+
|
115 |
+
p {
|
116 |
+
color: var(--gray-600);
|
117 |
+
margin-bottom: 1rem;
|
118 |
+
}
|
119 |
+
|
120 |
+
.card {
|
121 |
+
background-color: white;
|
122 |
+
border-radius: 0.75rem;
|
123 |
+
box-shadow: var(--shadow);
|
124 |
+
padding: 2rem;
|
125 |
+
margin-bottom: 2rem;
|
126 |
+
}
|
127 |
+
|
128 |
+
.form-group {
|
129 |
+
margin-bottom: 1.5rem;
|
130 |
+
}
|
131 |
+
|
132 |
+
label {
|
133 |
+
display: block;
|
134 |
+
margin-bottom: 0.5rem;
|
135 |
+
font-weight: 500;
|
136 |
+
color: var(--gray-700);
|
137 |
+
}
|
138 |
+
|
139 |
+
#userInput {
|
140 |
+
width: 100%;
|
141 |
+
padding: 0.75rem;
|
142 |
+
border: 1px solid var(--gray-300);
|
143 |
+
border-radius: 0.5rem;
|
144 |
+
min-height: 150px;
|
145 |
+
font-family: inherit;
|
146 |
+
resize: vertical;
|
147 |
+
transition: var(--transition);
|
148 |
+
}
|
149 |
+
|
150 |
+
#userProblemDescription {
|
151 |
+
width: 100%;
|
152 |
+
padding: 0.75rem;
|
153 |
+
border: 1px solid var(--gray-300);
|
154 |
+
border-radius: 0.5rem;
|
155 |
+
min-height: 150px;
|
156 |
+
font-family: inherit;
|
157 |
+
resize: vertical;
|
158 |
+
transition: var(--transition);
|
159 |
+
}
|
160 |
+
|
161 |
+
#userInput:focus {
|
162 |
+
outline: none;
|
163 |
+
border-color: var(--primary);
|
164 |
+
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
|
165 |
+
}
|
166 |
+
|
167 |
+
.btn {
|
168 |
+
display: inline-flex;
|
169 |
+
align-items: center;
|
170 |
+
justify-content: center;
|
171 |
+
padding: 0.625rem 1.25rem;
|
172 |
+
border: none;
|
173 |
+
border-radius: 0.5rem;
|
174 |
+
font-weight: 500;
|
175 |
+
font-size: 0.875rem;
|
176 |
+
cursor: pointer;
|
177 |
+
transition: var(--transition);
|
178 |
+
gap: 0.5rem;
|
179 |
+
}
|
180 |
+
|
181 |
+
.btn-primary {
|
182 |
+
background-color: var(--primary);
|
183 |
+
color: white;
|
184 |
+
}
|
185 |
+
|
186 |
+
.btn-primary:hover {
|
187 |
+
background-color: var(--primary-dark);
|
188 |
+
}
|
189 |
+
|
190 |
+
.btn-secondary {
|
191 |
+
background-color: var(--gray-100);
|
192 |
+
color: var(--gray-700);
|
193 |
+
}
|
194 |
+
|
195 |
+
.btn-secondary:hover {
|
196 |
+
background-color: var(--gray-200);
|
197 |
+
}
|
198 |
+
|
199 |
+
.btn-danger {
|
200 |
+
background-color: var(--danger);
|
201 |
+
color: white;
|
202 |
+
}
|
203 |
+
|
204 |
+
.btn-danger:hover {
|
205 |
+
background-color: #dc2626;
|
206 |
+
}
|
207 |
+
|
208 |
+
.btn-success {
|
209 |
+
background-color: var(--success);
|
210 |
+
color: white;
|
211 |
+
}
|
212 |
+
|
213 |
+
.btn-success:hover {
|
214 |
+
background-color: #059669;
|
215 |
+
}
|
216 |
+
|
217 |
+
.btn-warning {
|
218 |
+
background-color: var(--warning);
|
219 |
+
color: white;
|
220 |
+
}
|
221 |
+
|
222 |
+
.btn-warning:hover {
|
223 |
+
background-color: #d97706;
|
224 |
+
}
|
225 |
+
|
226 |
+
.btn-info {
|
227 |
+
background-color: #0dcaf0;
|
228 |
+
color: white;
|
229 |
+
}
|
230 |
+
|
231 |
+
.btn-info:hover {
|
232 |
+
background-color: #0aa2c0;
|
233 |
+
}
|
234 |
+
|
235 |
+
.btn-info.disabled {
|
236 |
+
opacity: 0.6;
|
237 |
+
cursor: not-allowed;
|
238 |
+
}
|
239 |
+
|
240 |
+
.btn-group-insights {
|
241 |
+
background-color: #8e44ad;
|
242 |
+
color: white;
|
243 |
+
}
|
244 |
+
|
245 |
+
.btn-group-insights:hover {
|
246 |
+
background-color: #7d3c98;
|
247 |
+
}
|
248 |
+
|
249 |
+
.query-item {
|
250 |
+
background-color: white;
|
251 |
+
border-radius: 0.75rem;
|
252 |
+
box-shadow: var(--shadow);
|
253 |
+
padding: 1.5rem;
|
254 |
+
margin-bottom: 1.5rem;
|
255 |
+
}
|
256 |
+
|
257 |
+
.query-container {
|
258 |
+
display: flex;
|
259 |
+
margin-bottom: 1rem;
|
260 |
+
align-items: center;
|
261 |
+
gap: 0.5rem;
|
262 |
+
}
|
263 |
+
|
264 |
+
.query-field {
|
265 |
+
flex-grow: 1;
|
266 |
+
padding: 0.625rem 0.75rem;
|
267 |
+
border: 1px solid var(--gray-300);
|
268 |
+
border-radius: 0.5rem;
|
269 |
+
transition: var(--transition);
|
270 |
+
}
|
271 |
+
|
272 |
+
.query-field:focus {
|
273 |
+
outline: none;
|
274 |
+
border-color: var(--primary);
|
275 |
+
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
|
276 |
+
}
|
277 |
+
|
278 |
+
.action-button {
|
279 |
+
background-color: hsl(192, 83%, 66%);
|
280 |
+
color: white;
|
281 |
+
padding: 8px 12px;
|
282 |
+
border: none;
|
283 |
+
border-radius: 4px;
|
284 |
+
cursor: pointer;
|
285 |
+
margin-right: 5px;
|
286 |
+
}
|
287 |
+
.delete-button {
|
288 |
+
background-color: #f44336;
|
289 |
+
}
|
290 |
+
.search-button {
|
291 |
+
background-color: #2196F3;
|
292 |
+
}
|
293 |
+
button:hover {
|
294 |
+
opacity: 0.9;
|
295 |
+
}
|
296 |
+
|
297 |
+
#resultsContainer {
|
298 |
+
margin-top: 20px;
|
299 |
+
display: none;
|
300 |
+
}
|
301 |
+
#queriesContainer {
|
302 |
+
margin-bottom: 15px;
|
303 |
+
}
|
304 |
+
#loadingIndicator {
|
305 |
+
display: none;
|
306 |
+
margin-top: 20px;
|
307 |
+
text-align: center;
|
308 |
+
color: #666;
|
309 |
+
}
|
310 |
+
.button-container {
|
311 |
+
margin-top: 15px;
|
312 |
+
}
|
313 |
+
.results-table {
|
314 |
+
width: 100%;
|
315 |
+
border-collapse: collapse;
|
316 |
+
margin-top: 10px;
|
317 |
+
display: none;
|
318 |
+
}
|
319 |
+
.results-table th, .results-table td {
|
320 |
+
border: 1px solid #ddd;
|
321 |
+
padding: 8px;
|
322 |
+
text-align: left;
|
323 |
+
}
|
324 |
+
.results-table th {
|
325 |
+
background-color: #f2f2f2;
|
326 |
+
}
|
327 |
+
.results-table tr:nth-child(even) {
|
328 |
+
background-color: #f9f9f9;
|
329 |
+
}
|
330 |
+
.results-table tr:hover {
|
331 |
+
background-color: #f1f1f1;
|
332 |
+
}
|
333 |
+
.search-loading {
|
334 |
+
display: none;
|
335 |
+
margin: 10px 0;
|
336 |
+
font-style: italic;
|
337 |
+
color: #666;
|
338 |
+
}
|
339 |
+
.url-link {
|
340 |
+
color: #0066cc;
|
341 |
+
text-decoration: none;
|
342 |
+
word-break: break-all;
|
343 |
+
}
|
344 |
+
.url-link:hover {
|
345 |
+
text-decoration: underline;
|
346 |
+
}
|
347 |
+
|
348 |
+
.analyze-button {
|
349 |
+
margin-top: 5px;
|
350 |
+
padding: 3px 8px;
|
351 |
+
font-size: 0.8em;
|
352 |
+
}
|
353 |
+
|
354 |
+
.loading-spinner {
|
355 |
+
border: 4px solid #f3f3f3;
|
356 |
+
border-top: 4px solid #3498db;
|
357 |
+
border-radius: 50%;
|
358 |
+
width: 20px;
|
359 |
+
height: 20px;
|
360 |
+
animation: spin 2s linear infinite;
|
361 |
+
margin: 0 auto;
|
362 |
+
}
|
363 |
+
|
364 |
+
@keyframes spin {
|
365 |
+
0% { transform: rotate(0deg); }
|
366 |
+
100% { transform: rotate(360deg); }
|
367 |
+
}
|
368 |
+
|
369 |
+
.score-cell, .justification-cell {
|
370 |
+
max-width: 150px;
|
371 |
+
overflow: hidden;
|
372 |
+
text-overflow: ellipsis;
|
373 |
+
}
|
374 |
+
|
375 |
+
.score-cell {
|
376 |
+
font-weight: bold;
|
377 |
+
text-align: center;
|
378 |
+
}
|
379 |
+
|
380 |
+
.floating-buttons {
|
381 |
+
position: fixed;
|
382 |
+
bottom: 2rem;
|
383 |
+
right: 2rem;
|
384 |
+
display: flex;
|
385 |
+
flex-direction: column;
|
386 |
+
gap: 0.75rem;
|
387 |
+
z-index: 100;
|
388 |
+
}
|
389 |
+
|
390 |
+
.floating-button {
|
391 |
+
padding: 0.75rem;
|
392 |
+
border-radius: 0.5rem;
|
393 |
+
box-shadow: var(--shadow-md);
|
394 |
+
transition: all 0.3s ease;
|
395 |
+
display: flex;
|
396 |
+
align-items: center;
|
397 |
+
justify-content: center;
|
398 |
+
gap: 0.5rem;
|
399 |
+
width: auto;
|
400 |
+
white-space: nowrap;
|
401 |
+
}
|
402 |
+
|
403 |
+
.floating-button:hover {
|
404 |
+
transform: translateY(-2px);
|
405 |
+
box-shadow: var(--shadow-lg);
|
406 |
+
}
|
407 |
+
|
408 |
+
.loading-overlay {
|
409 |
+
position: fixed;
|
410 |
+
top: 0;
|
411 |
+
left: 0;
|
412 |
+
width: 100%;
|
413 |
+
height: 100%;
|
414 |
+
background-color: rgba(0, 0, 0, 0.5);
|
415 |
+
display: none;
|
416 |
+
justify-content: center;
|
417 |
+
align-items: center;
|
418 |
+
z-index: 1000;
|
419 |
+
}
|
420 |
+
|
421 |
+
.loading-content {
|
422 |
+
background-color: white;
|
423 |
+
padding: 2rem;
|
424 |
+
border-radius: 0.75rem;
|
425 |
+
text-align: center;
|
426 |
+
box-shadow: var(--shadow-lg);
|
427 |
+
max-width: 80%;
|
428 |
+
}
|
429 |
+
|
430 |
+
.loading-content .loading-spinner {
|
431 |
+
width: 40px;
|
432 |
+
height: 40px;
|
433 |
+
border-width: 4px;
|
434 |
+
margin-bottom: 1rem;
|
435 |
+
}
|
436 |
+
|
437 |
+
.progress-text {
|
438 |
+
font-size: 1rem;
|
439 |
+
margin-top: 0.75rem;
|
440 |
+
color: var(--gray-700);
|
441 |
+
}
|
442 |
+
|
443 |
+
.button-container {
|
444 |
+
margin-top: 1.5rem;
|
445 |
+
display: flex;
|
446 |
+
justify-content: flex-start;
|
447 |
+
gap: 0.75rem;
|
448 |
+
}
|
449 |
+
|
450 |
+
/* Add icons for better UX */
|
451 |
+
.icon {
|
452 |
+
display: inline-block;
|
453 |
+
width: 20px;
|
454 |
+
height: 20px;
|
455 |
+
background-size: contain;
|
456 |
+
background-repeat: no-repeat;
|
457 |
+
background-position: center;
|
458 |
+
}
|
459 |
+
|
460 |
+
.table-container {
|
461 |
+
margin-top: 1rem;
|
462 |
+
overflow-x: auto;
|
463 |
+
border-radius: 0.5rem;
|
464 |
+
border: 1px solid var(--gray-200);
|
465 |
+
}
|
466 |
+
|
467 |
+
/* Responsive adjustments */
|
468 |
+
@media (max-width: 768px) {
|
469 |
+
.query-container {
|
470 |
+
flex-direction: column;
|
471 |
+
align-items: stretch;
|
472 |
+
}
|
473 |
+
|
474 |
+
.query-container .btn {
|
475 |
+
margin-top: 0.5rem;
|
476 |
+
}
|
477 |
+
|
478 |
+
.floating-buttons {
|
479 |
+
bottom: 1rem;
|
480 |
+
right: 1rem;
|
481 |
+
}
|
482 |
+
}
|
483 |
+
|
484 |
+
.search-options {
|
485 |
+
margin-bottom: 20px;
|
486 |
+
text-align: center;
|
487 |
+
}
|
488 |
+
|
489 |
+
.checkbox-group {
|
490 |
+
display: flex;
|
491 |
+
gap: 15px;
|
492 |
+
margin-top: 5px;
|
493 |
+
justify-content: center; /* This centers the checkboxes horizontally */
|
494 |
+
}
|
495 |
+
|
496 |
+
.checkbox-item {
|
497 |
+
display: flex;
|
498 |
+
align-items: center;
|
499 |
+
gap: 5px;
|
500 |
+
}
|
501 |
+
|
502 |
+
/* Adding styles for insights feature */
|
503 |
+
.insights-container {
|
504 |
+
margin-top: 10px;
|
505 |
+
border-top: 1px dashed #ccc;
|
506 |
+
padding-top: 10px;
|
507 |
+
}
|
508 |
+
|
509 |
+
.insights-header {
|
510 |
+
display: flex;
|
511 |
+
justify-content: space-between;
|
512 |
+
align-items: center;
|
513 |
+
margin-bottom: 8px;
|
514 |
+
}
|
515 |
+
|
516 |
+
.insights-title {
|
517 |
+
font-weight: bold;
|
518 |
+
color: #333;
|
519 |
+
}
|
520 |
+
|
521 |
+
.insights-actions {
|
522 |
+
display: flex;
|
523 |
+
gap: 8px;
|
524 |
+
}
|
525 |
+
|
526 |
+
.insights-button {
|
527 |
+
font-size: 12px;
|
528 |
+
padding: 2px 6px;
|
529 |
+
background-color: #4CAF50;
|
530 |
+
color: white;
|
531 |
+
border: none;
|
532 |
+
border-radius: 3px;
|
533 |
+
cursor: pointer;
|
534 |
+
}
|
535 |
+
|
536 |
+
.insights-list {
|
537 |
+
display: flex;
|
538 |
+
flex-wrap: wrap;
|
539 |
+
gap: 8px;
|
540 |
+
margin-top: 8px;
|
541 |
+
}
|
542 |
+
|
543 |
+
.insight-tag {
|
544 |
+
background-color: #f1f1f1;
|
545 |
+
border: 1px solid #ddd;
|
546 |
+
border-radius: 15px;
|
547 |
+
padding: 4px 12px;
|
548 |
+
font-size: 12px;
|
549 |
+
cursor: pointer;
|
550 |
+
transition: all 0.2s ease;
|
551 |
+
user-select: none;
|
552 |
+
}
|
553 |
+
|
554 |
+
.insight-tag.selected {
|
555 |
+
background-color: #4CAF50;
|
556 |
+
color: white;
|
557 |
+
border-color: #4CAF50;
|
558 |
+
}
|
559 |
+
|
560 |
+
/* Styles for problem refinement functionality */
|
561 |
+
.problem-history {
|
562 |
+
position: relative;
|
563 |
+
margin-bottom: 10px;
|
564 |
+
}
|
565 |
+
|
566 |
+
.problem-history-nav {
|
567 |
+
display: flex;
|
568 |
+
align-items: center;
|
569 |
+
margin-bottom: 5px;
|
570 |
+
}
|
571 |
+
|
572 |
+
.history-arrow {
|
573 |
+
padding: 2px 8px;
|
574 |
+
background-color: var(--gray-200);
|
575 |
+
border-radius: 3px;
|
576 |
+
cursor: pointer;
|
577 |
+
margin-right: 5px;
|
578 |
+
font-size: 14px;
|
579 |
+
color: var(--gray-700);
|
580 |
+
}
|
581 |
+
|
582 |
+
.history-arrow:hover {
|
583 |
+
background-color: var(--gray-300);
|
584 |
+
}
|
585 |
+
|
586 |
+
.history-arrow.disabled {
|
587 |
+
opacity: 0.5;
|
588 |
+
cursor: not-allowed;
|
589 |
+
}
|
590 |
+
|
591 |
+
.history-status {
|
592 |
+
font-size: 12px;
|
593 |
+
color: var(--gray-600);
|
594 |
+
}
|
595 |
+
|
596 |
+
.insight-comment-area {
|
597 |
+
margin-top: 10px;
|
598 |
+
width: 100%;
|
599 |
+
}
|
600 |
+
|
601 |
+
.insight-comment-textarea {
|
602 |
+
width: 100%;
|
603 |
+
padding: 8px;
|
604 |
+
border: 1px solid var(--gray-300);
|
605 |
+
border-radius: 4px;
|
606 |
+
font-size: 14px;
|
607 |
+
resize: vertical;
|
608 |
+
min-height: 60px;
|
609 |
+
}
|
610 |
+
|
611 |
+
.refined-problem-container {
|
612 |
+
margin-top: 20px;
|
613 |
+
border: 1px solid var(--gray-300);
|
614 |
+
border-radius: 8px;
|
615 |
+
overflow: hidden;
|
616 |
+
}
|
617 |
+
|
618 |
+
.refined-problem-tabs {
|
619 |
+
display: flex;
|
620 |
+
background-color: var(--gray-100);
|
621 |
+
border-bottom: 1px solid var(--gray-300);
|
622 |
+
}
|
623 |
+
|
624 |
+
.refined-problem-tab {
|
625 |
+
padding: 10px 15px;
|
626 |
+
cursor: pointer;
|
627 |
+
font-weight: 500;
|
628 |
+
border-right: 1px solid var(--gray-300);
|
629 |
+
}
|
630 |
+
|
631 |
+
.refined-problem-tab.active {
|
632 |
+
background-color: white;
|
633 |
+
border-bottom: 2px solid var(--primary);
|
634 |
+
}
|
635 |
+
|
636 |
+
.refined-problem-content {
|
637 |
+
padding: 15px;
|
638 |
+
background-color: white;
|
639 |
+
}
|
640 |
+
|
641 |
+
.refined-problem {
|
642 |
+
display: none;
|
643 |
+
}
|
644 |
+
|
645 |
+
.refined-problem.active {
|
646 |
+
display: block;
|
647 |
+
}
|
648 |
+
|
649 |
+
.refined-problem-title {
|
650 |
+
font-weight: 600;
|
651 |
+
margin-bottom: 10px;
|
652 |
+
color: var(--primary-dark);
|
653 |
+
}
|
654 |
+
|
655 |
+
.refined-problem-description {
|
656 |
+
line-height: 1.5;
|
657 |
+
}
|
658 |
+
|
659 |
+
.apply-problem-btn {
|
660 |
+
margin-top: 10px;
|
661 |
+
background-color: var(--primary);
|
662 |
+
color: white;
|
663 |
+
border: none;
|
664 |
+
border-radius: 4px;
|
665 |
+
padding: 5px 10px;
|
666 |
+
cursor: pointer;
|
667 |
+
font-size: 14px;
|
668 |
+
}
|
669 |
+
|
670 |
+
.apply-problem-btn:hover {
|
671 |
+
background-color: var(--primary-dark);
|
672 |
+
}
|
673 |
+
|
674 |
+
.enhance-problem-button {
|
675 |
+
background-color: var(--warning);
|
676 |
+
color: white;
|
677 |
+
}
|
678 |
+
|
679 |
+
.enhance-problem-button:hover {
|
680 |
+
background-color: #d97706;
|
681 |
+
}
|
682 |
+
|
683 |
+
.enhance-problem-button.disabled {
|
684 |
+
opacity: 0.6;
|
685 |
+
cursor: not-allowed;
|
686 |
+
}
|
687 |
+
|
688 |
+
/* Accordion styles for collapsible search results */
|
689 |
+
.accordion-section {
|
690 |
+
margin-bottom: 20px;
|
691 |
+
border: 1px solid var(--gray-300);
|
692 |
+
border-radius: 8px;
|
693 |
+
overflow: hidden;
|
694 |
+
background-color: white;
|
695 |
+
}
|
696 |
+
|
697 |
+
.accordion-header {
|
698 |
+
background-color: var(--gray-100);
|
699 |
+
padding: 10px 15px;
|
700 |
+
cursor: pointer;
|
701 |
+
display: flex;
|
702 |
+
justify-content: space-between;
|
703 |
+
align-items: center;
|
704 |
+
font-weight: 500;
|
705 |
+
border-bottom: 1px solid var(--gray-300);
|
706 |
+
}
|
707 |
+
|
708 |
+
.accordion-header:hover {
|
709 |
+
background-color: var(--gray-200);
|
710 |
+
}
|
711 |
+
|
712 |
+
.accordion-header .toggle-icon {
|
713 |
+
transition: transform 0.3s ease;
|
714 |
+
}
|
715 |
+
|
716 |
+
.accordion-header.collapsed .toggle-icon {
|
717 |
+
transform: rotate(-90deg);
|
718 |
+
}
|
719 |
+
|
720 |
+
.accordion-body {
|
721 |
+
transition: max-height 0.5s ease;
|
722 |
+
max-height: none; /* Changed from 2000px to none to allow full height */
|
723 |
+
overflow: hidden;
|
724 |
+
}
|
725 |
+
|
726 |
+
.accordion-body.collapsed {
|
727 |
+
max-height: 0;
|
728 |
+
padding: 0;
|
729 |
+
border-top: none;
|
730 |
+
}
|
731 |
+
|
732 |
+
/* Add padding to accordion content for better readability */
|
733 |
+
.accordion-content {
|
734 |
+
padding: 15px;
|
735 |
+
}
|
736 |
+
|
737 |
+
.query-timestamp {
|
738 |
+
font-size: 12px;
|
739 |
+
color: var(--gray-500);
|
740 |
+
margin-left: 10px;
|
741 |
+
}
|
742 |
+
|
743 |
+
.grouped-insights-container {
|
744 |
+
background-color: white;
|
745 |
+
border-radius: 8px;
|
746 |
+
border: 1px solid var(--gray-300);
|
747 |
+
margin-top: 20px;
|
748 |
+
margin-bottom: 20px;
|
749 |
+
box-shadow: var(--shadow);
|
750 |
+
overflow: hidden;
|
751 |
+
display: none;
|
752 |
+
}
|
753 |
+
|
754 |
+
.grouped-insights-header {
|
755 |
+
display: flex;
|
756 |
+
justify-content: space-between;
|
757 |
+
padding: 15px;
|
758 |
+
background-color: var(--primary-light);
|
759 |
+
color: white;
|
760 |
+
font-weight: 600;
|
761 |
+
align-items: center;
|
762 |
+
}
|
763 |
+
|
764 |
+
.grouped-insights-close {
|
765 |
+
cursor: pointer;
|
766 |
+
font-size: 20px;
|
767 |
+
font-weight: bold;
|
768 |
+
margin-left: 8px;
|
769 |
+
}
|
770 |
+
|
771 |
+
.grouped-insights-content {
|
772 |
+
padding: 0;
|
773 |
+
}
|
774 |
+
|
775 |
+
.score-group {
|
776 |
+
margin-bottom: 10px;
|
777 |
+
border-bottom: 1px solid var(--gray-300);
|
778 |
+
}
|
779 |
+
|
780 |
+
.score-group-header {
|
781 |
+
padding: 10px 15px;
|
782 |
+
background-color: var(--gray-100);
|
783 |
+
font-weight: 500;
|
784 |
+
display: flex;
|
785 |
+
justify-content: space-between;
|
786 |
+
border-bottom: 1px solid var(--gray-200);
|
787 |
+
}
|
788 |
+
|
789 |
+
.score-group-actions {
|
790 |
+
display: flex;
|
791 |
+
gap: 8px;
|
792 |
+
}
|
793 |
+
|
794 |
+
.score-insights-list {
|
795 |
+
padding: 10px 15px;
|
796 |
+
}
|
797 |
+
|
798 |
+
.grouped-insight-tag {
|
799 |
+
background-color: #f1f1f1;
|
800 |
+
border: 1px solid #ddd;
|
801 |
+
border-radius: 15px;
|
802 |
+
padding: 4px 12px;
|
803 |
+
font-size: 12px;
|
804 |
+
cursor: pointer;
|
805 |
+
transition: all 0.2s ease;
|
806 |
+
user-select: none;
|
807 |
+
margin: 4px;
|
808 |
+
display: inline-flex;
|
809 |
+
align-items: center;
|
810 |
+
}
|
811 |
+
|
812 |
+
.grouped-insight-tag.selected {
|
813 |
+
background-color: #4CAF50;
|
814 |
+
color: white;
|
815 |
+
border-color: #4CAF50;
|
816 |
+
}
|
817 |
+
|
818 |
+
.insight-source {
|
819 |
+
font-size: 9px;
|
820 |
+
background-color: var(--primary-dark);
|
821 |
+
color: white;
|
822 |
+
border-radius: 10px;
|
823 |
+
padding: 1px 6px;
|
824 |
+
margin-left: 5px;
|
825 |
+
display: inline-block;
|
826 |
+
text-decoration: none;
|
827 |
+
}
|
828 |
+
|
829 |
+
.insight-source:hover {
|
830 |
+
background-color: var(--primary);
|
831 |
+
}
|
832 |
+
|
833 |
+
.grouped-insights-actions {
|
834 |
+
display: flex;
|
835 |
+
align-items: center;
|
836 |
+
gap: 8px;
|
837 |
+
}
|
838 |
+
|
839 |
+
/* AI Select Button Styling */
|
840 |
+
.ai-select-btn {
|
841 |
+
background: linear-gradient(135deg, #4b6cb7, #8e44ad);
|
842 |
+
color: white;
|
843 |
+
border: none;
|
844 |
+
padding: 8px 16px;
|
845 |
+
border-radius: 4px;
|
846 |
+
font-weight: 500;
|
847 |
+
cursor: pointer;
|
848 |
+
display: flex;
|
849 |
+
align-items: center;
|
850 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
851 |
+
transition: all 0.3s ease;
|
852 |
+
}
|
853 |
+
|
854 |
+
.ai-select-btn:before {
|
855 |
+
content: "🧠";
|
856 |
+
margin-right: 6px;
|
857 |
+
font-size: 14px;
|
858 |
+
}
|
859 |
+
|
860 |
+
.ai-select-btn:hover {
|
861 |
+
transform: translateY(-2px);
|
862 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
863 |
+
}
|
864 |
+
|
865 |
+
.ai-select-btn:active {
|
866 |
+
transform: translateY(0);
|
867 |
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
|
868 |
+
}
|
869 |
+
|
870 |
+
.ai-select-btn:disabled {
|
871 |
+
background: linear-gradient(135deg, #a0a0a0, #7a7a7a);
|
872 |
+
cursor: wait;
|
873 |
+
transform: none;
|
874 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
875 |
+
}
|
876 |
+
|
877 |
+
@keyframes pulse {
|
878 |
+
0% {
|
879 |
+
box-shadow: 0 0 0 0 rgba(142, 68, 173, 0.7);
|
880 |
+
}
|
881 |
+
70% {
|
882 |
+
box-shadow: 0 0 0 10px rgba(142, 68, 173, 0);
|
883 |
+
}
|
884 |
+
100% {
|
885 |
+
box-shadow: 0 0 0 0 rgba(142, 68, 173, 0);
|
886 |
+
}
|
887 |
+
}
|
888 |
+
|
889 |
+
.pulse {
|
890 |
+
animation: pulse 2s infinite;
|
891 |
+
}
|
892 |
+
|
893 |
+
/* Existing styles continue below */
|
894 |
+
.ai-select-btn {
|
895 |
+
background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
|
896 |
+
color: white;
|
897 |
+
font-weight: 600;
|
898 |
+
padding: 6px 12px;
|
899 |
+
border-radius: 6px;
|
900 |
+
border: none;
|
901 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
902 |
+
display: flex;
|
903 |
+
align-items: center;
|
904 |
+
transition: all 0.3s ease;
|
905 |
+
position: relative;
|
906 |
+
overflow: hidden;
|
907 |
+
}
|
908 |
+
|
909 |
+
.ai-select-btn::before {
|
910 |
+
content: "🧠";
|
911 |
+
margin-right: 6px;
|
912 |
+
font-size: 14px;
|
913 |
+
}
|
914 |
+
|
915 |
+
.ai-select-btn:hover {
|
916 |
+
transform: translateY(-2px);
|
917 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
918 |
+
background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
|
919 |
+
}
|
920 |
+
|
921 |
+
.ai-select-btn:active {
|
922 |
+
transform: translateY(1px);
|
923 |
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
|
924 |
+
}
|
925 |
+
|
926 |
+
/* Add pulsing effect to draw attention */
|
927 |
+
@keyframes pulse {
|
928 |
+
0% {
|
929 |
+
box-shadow: 0 0 0 0 rgba(139, 92, 246, 0.7);
|
930 |
+
}
|
931 |
+
70% {
|
932 |
+
box-shadow: 0 0 0 6px rgba(139, 92, 246, 0);
|
933 |
+
}
|
934 |
+
100% {
|
935 |
+
box-shadow: 0 0 0 0 rgba(139, 92, 246, 0);
|
936 |
+
}
|
937 |
+
}
|
938 |
+
|
939 |
+
.ai-select-btn.pulse {
|
940 |
+
animation: pulse 2s infinite;
|
941 |
+
}
|
942 |
+
|
943 |
+
.prob-desc-container {
|
944 |
+
margin-top: 20px;
|
945 |
+
padding: 15px;
|
946 |
+
background-color: #f9f9f9;
|
947 |
+
border-radius: 8px;
|
948 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
949 |
+
}
|
950 |
+
|
951 |
+
.prob-desc-container {
|
952 |
+
margin-top: 2rem;
|
953 |
+
border-radius: 0.5rem;
|
954 |
+
overflow: hidden;
|
955 |
+
}
|
956 |
+
|
957 |
+
.prob-desc-list {
|
958 |
+
display: grid;
|
959 |
+
grid-template-columns: 1fr;
|
960 |
+
gap: 1rem;
|
961 |
+
margin-top: 1rem;
|
962 |
+
}
|
963 |
+
|
964 |
+
@media (min-width: 768px) {
|
965 |
+
.prob-desc-list {
|
966 |
+
grid-template-columns: repeat(2, 1fr);
|
967 |
+
}
|
968 |
+
}
|
969 |
+
|
970 |
+
.prob-desc-card {
|
971 |
+
background-color: white;
|
972 |
+
border: 1px solid var(--gray-300);
|
973 |
+
border-radius: 0.75rem;
|
974 |
+
padding: 1.5rem;
|
975 |
+
box-shadow: var(--shadow-sm);
|
976 |
+
cursor: pointer;
|
977 |
+
transition: var(--transition);
|
978 |
+
}
|
979 |
+
|
980 |
+
.prob-desc-card:hover {
|
981 |
+
border-color: var(--primary-light);
|
982 |
+
box-shadow: var(--shadow-md);
|
983 |
+
}
|
984 |
+
|
985 |
+
.prob-desc-card.selected {
|
986 |
+
border: 2px solid var(--primary);
|
987 |
+
background-color: rgba(37, 99, 235, 0.05);
|
988 |
+
}
|
989 |
+
|
990 |
+
.prob-desc-title {
|
991 |
+
font-weight: 600;
|
992 |
+
font-size: 1.125rem;
|
993 |
+
color: var(--gray-800);
|
994 |
+
margin-bottom: 0.5rem;
|
995 |
+
}
|
996 |
+
|
997 |
+
.prob-desc-description {
|
998 |
+
color: var(--gray-600);
|
999 |
+
margin-bottom: 1rem;
|
1000 |
+
font-size: 0.9375rem;
|
1001 |
+
}
|
1002 |
+
|
1003 |
+
.prob-desc-container h3 {
|
1004 |
+
margin-top: 0;
|
1005 |
+
color: #333;
|
1006 |
+
font-size: 18px;
|
1007 |
+
font-weight: 600;
|
1008 |
+
margin-bottom: 15px;
|
1009 |
+
border-bottom: 1px solid #ddd;
|
1010 |
+
padding-bottom: 8px;
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
.prob-desc-list {
|
1014 |
+
display: grid;
|
1015 |
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
1016 |
+
gap: 15px;
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
.prob-desc-card {
|
1020 |
+
background-color: white;
|
1021 |
+
border: 1px solid #e0e0e0;
|
1022 |
+
border-radius: 6px;
|
1023 |
+
padding: 15px;
|
1024 |
+
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.05);
|
1025 |
+
transition: all 0.3s ease;
|
1026 |
+
cursor: pointer;
|
1027 |
+
}
|
1028 |
+
|
1029 |
+
.prob-desc-card:hover {
|
1030 |
+
transform: translateY(-3px);
|
1031 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
1032 |
+
border-color: #ccc;
|
1033 |
+
}
|
1034 |
+
|
1035 |
+
.prob-desc-card.selected {
|
1036 |
+
border: 2px solid #4b6cb7;
|
1037 |
+
background-color: rgba(75, 108, 183, 0.05);
|
1038 |
+
}
|
1039 |
+
|
1040 |
+
.prob-desc-title {
|
1041 |
+
font-weight: 600;
|
1042 |
+
color: #333;
|
1043 |
+
margin-bottom: 10px;
|
1044 |
+
font-size: 16px;
|
1045 |
+
}
|
1046 |
+
|
1047 |
+
.prob-desc-description {
|
1048 |
+
color: #555;
|
1049 |
+
font-size: 14px;
|
1050 |
+
line-height: 1.5;
|
1051 |
+
margin-bottom: 12px;
|
1052 |
+
}
|
1053 |
+
|
1054 |
+
.key-issues-container {
|
1055 |
+
margin-top: 20px;
|
1056 |
+
padding: 15px;
|
1057 |
+
background-color: #f9f9f9;
|
1058 |
+
border-radius: 8px;
|
1059 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
1060 |
+
}
|
1061 |
+
|
1062 |
+
.key-issues-container {
|
1063 |
+
margin-top: 2rem;
|
1064 |
+
border-radius: 0.5rem;
|
1065 |
+
overflow: hidden;
|
1066 |
+
}
|
1067 |
+
|
1068 |
+
.key-issues-list {
|
1069 |
+
display: grid;
|
1070 |
+
grid-template-columns: 1fr;
|
1071 |
+
gap: 1rem;
|
1072 |
+
margin-top: 1rem;
|
1073 |
+
}
|
1074 |
+
|
1075 |
+
@media (min-width: 768px) {
|
1076 |
+
.key-issues-list {
|
1077 |
+
grid-template-columns: repeat(2, 1fr);
|
1078 |
+
}
|
1079 |
+
}
|
1080 |
+
|
1081 |
+
.key-issue-card {
|
1082 |
+
background-color: white;
|
1083 |
+
border: 1px solid var(--gray-300);
|
1084 |
+
border-radius: 0.75rem;
|
1085 |
+
padding: 1.5rem;
|
1086 |
+
box-shadow: var(--shadow-sm);
|
1087 |
+
cursor: pointer;
|
1088 |
+
transition: var(--transition);
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
.key-issue-card:hover {
|
1092 |
+
border-color: var(--primary-light);
|
1093 |
+
box-shadow: var(--shadow-md);
|
1094 |
+
}
|
1095 |
+
|
1096 |
+
.key-issue-card.selected {
|
1097 |
+
border: 2px solid var(--primary);
|
1098 |
+
background-color: rgba(37, 99, 235, 0.05);
|
1099 |
+
}
|
1100 |
+
|
1101 |
+
.key-issue-title {
|
1102 |
+
font-weight: 600;
|
1103 |
+
font-size: 1.125rem;
|
1104 |
+
color: var(--gray-800);
|
1105 |
+
margin-bottom: 0.5rem;
|
1106 |
+
}
|
1107 |
+
|
1108 |
+
.key-issue-description {
|
1109 |
+
color: var(--gray-600);
|
1110 |
+
margin-bottom: 1rem;
|
1111 |
+
font-size: 0.9375rem;
|
1112 |
+
}
|
1113 |
+
|
1114 |
+
.key-issue-challenges {
|
1115 |
+
margin: 0.75rem 0;
|
1116 |
+
padding-left: 1.5rem;
|
1117 |
+
}
|
1118 |
+
|
1119 |
+
.key-issue-challenges li {
|
1120 |
+
margin-bottom: 0.5rem;
|
1121 |
+
font-size: 0.875rem;
|
1122 |
+
color: var(--gray-700);
|
1123 |
+
}
|
1124 |
+
|
1125 |
+
.key-issue-impact {
|
1126 |
+
font-size: 0.875rem;
|
1127 |
+
color: var(--gray-700);
|
1128 |
+
font-style: italic;
|
1129 |
+
margin-top: 0.75rem;
|
1130 |
+
}
|
1131 |
+
|
1132 |
+
.key-issues-container h3 {
|
1133 |
+
margin-top: 0;
|
1134 |
+
color: #333;
|
1135 |
+
font-size: 18px;
|
1136 |
+
font-weight: 600;
|
1137 |
+
margin-bottom: 15px;
|
1138 |
+
border-bottom: 1px solid #ddd;
|
1139 |
+
padding-bottom: 8px;
|
1140 |
+
}
|
1141 |
+
|
1142 |
+
.key-issues-list {
|
1143 |
+
display: grid;
|
1144 |
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
1145 |
+
gap: 15px;
|
1146 |
+
}
|
1147 |
+
|
1148 |
+
.key-issue-card {
|
1149 |
+
background-color: white;
|
1150 |
+
border: 1px solid #e0e0e0;
|
1151 |
+
border-radius: 6px;
|
1152 |
+
padding: 15px;
|
1153 |
+
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.05);
|
1154 |
+
transition: all 0.3s ease;
|
1155 |
+
cursor: pointer;
|
1156 |
+
}
|
1157 |
+
|
1158 |
+
.key-issue-card:hover {
|
1159 |
+
transform: translateY(-3px);
|
1160 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
1161 |
+
border-color: #ccc;
|
1162 |
+
}
|
1163 |
+
|
1164 |
+
.key-issue-card.selected {
|
1165 |
+
border: 2px solid #4b6cb7;
|
1166 |
+
background-color: rgba(75, 108, 183, 0.05);
|
1167 |
+
}
|
1168 |
+
|
1169 |
+
.key-issue-title {
|
1170 |
+
font-weight: 600;
|
1171 |
+
color: #333;
|
1172 |
+
margin-bottom: 10px;
|
1173 |
+
font-size: 16px;
|
1174 |
+
}
|
1175 |
+
|
1176 |
+
.key-issue-description {
|
1177 |
+
color: #555;
|
1178 |
+
font-size: 14px;
|
1179 |
+
line-height: 1.5;
|
1180 |
+
margin-bottom: 12px;
|
1181 |
+
}
|
1182 |
+
|
1183 |
+
.key-issue-challenges {
|
1184 |
+
padding-left: 18px;
|
1185 |
+
margin: 10px 0;
|
1186 |
+
}
|
1187 |
+
|
1188 |
+
.key-issue-challenges li {
|
1189 |
+
font-size: 13px;
|
1190 |
+
color: #666;
|
1191 |
+
margin-bottom: 5px;
|
1192 |
+
}
|
1193 |
+
|
1194 |
+
.key-issue-impact {
|
1195 |
+
font-size: 13px;
|
1196 |
+
color: #d32f2f;
|
1197 |
+
font-style: italic;
|
1198 |
+
}
|
1199 |
+
|
1200 |
+
/* Accordion Ribbon Styles */
|
1201 |
+
.ribbon-accordion {
|
1202 |
+
position: fixed;
|
1203 |
+
bottom: 2rem;
|
1204 |
+
right: 2rem;
|
1205 |
+
z-index: 100;
|
1206 |
+
width: 320px;
|
1207 |
+
background-color: #fff;
|
1208 |
+
border-radius: 0.75rem 0.75rem 0 0;
|
1209 |
+
box-shadow: var(--shadow-lg);
|
1210 |
+
overflow: hidden;
|
1211 |
+
transition: transform 0.3s ease;
|
1212 |
+
transform-origin: bottom center;
|
1213 |
+
}
|
1214 |
+
|
1215 |
+
.ribbon-accordion.collapsed {
|
1216 |
+
transform: translateY(calc(100% - 50px));
|
1217 |
+
}
|
1218 |
+
|
1219 |
+
.ribbon-header {
|
1220 |
+
background-color: #2563eb;
|
1221 |
+
color: white;
|
1222 |
+
padding: 15px;
|
1223 |
+
display: flex;
|
1224 |
+
justify-content: space-between;
|
1225 |
+
align-items: center;
|
1226 |
+
cursor: pointer;
|
1227 |
+
}
|
1228 |
+
|
1229 |
+
.ribbon-title {
|
1230 |
+
font-weight: 600;
|
1231 |
+
font-size: 1rem;
|
1232 |
+
display: flex;
|
1233 |
+
align-items: center;
|
1234 |
+
gap: 8px;
|
1235 |
+
}
|
1236 |
+
|
1237 |
+
.ribbon-icon {
|
1238 |
+
font-size: 1.25rem;
|
1239 |
+
}
|
1240 |
+
|
1241 |
+
.ribbon-toggle {
|
1242 |
+
transition: transform 0.3s ease;
|
1243 |
+
}
|
1244 |
+
|
1245 |
+
.collapsed .ribbon-toggle {
|
1246 |
+
transform: rotate(180deg);
|
1247 |
+
}
|
1248 |
+
|
1249 |
+
.ribbon-content {
|
1250 |
+
padding: 1rem;
|
1251 |
+
display: flex;
|
1252 |
+
flex-direction: column;
|
1253 |
+
gap: 0.75rem;
|
1254 |
+
max-height: 400px;
|
1255 |
+
overflow-y: auto;
|
1256 |
+
}
|
1257 |
+
|
1258 |
+
.auto-run-btn {
|
1259 |
+
background: linear-gradient(135deg, #ff9966, #ff5e62);
|
1260 |
+
color: white;
|
1261 |
+
border: none;
|
1262 |
+
border-radius: 0.5rem;
|
1263 |
+
padding: 0.75rem;
|
1264 |
+
font-weight: 600;
|
1265 |
+
cursor: pointer;
|
1266 |
+
display: flex;
|
1267 |
+
align-items: center;
|
1268 |
+
justify-content: center;
|
1269 |
+
gap: 0.5rem;
|
1270 |
+
box-shadow: var(--shadow);
|
1271 |
+
transition: all 0.3s ease;
|
1272 |
+
position: relative;
|
1273 |
+
overflow: hidden;
|
1274 |
+
}
|
1275 |
+
|
1276 |
+
.auto-run-btn::before {
|
1277 |
+
content: "🚀";
|
1278 |
+
font-size: 1.25rem;
|
1279 |
+
}
|
1280 |
+
|
1281 |
+
.auto-run-btn:hover {
|
1282 |
+
transform: translateY(-2px);
|
1283 |
+
box-shadow: var(--shadow-lg);
|
1284 |
+
background: linear-gradient(135deg, #ff5e62, #ff9966);
|
1285 |
+
}
|
1286 |
+
|
1287 |
+
.auto-run-btn:active {
|
1288 |
+
transform: translateY(0);
|
1289 |
+
box-shadow: var(--shadow);
|
1290 |
+
}
|
1291 |
+
|
1292 |
+
/* Progress bar for auto-run */
|
1293 |
+
.progress-bar-container {
|
1294 |
+
height: 6px;
|
1295 |
+
background-color: #f0f0f0;
|
1296 |
+
border-radius: 3px;
|
1297 |
+
margin-top: 0.75rem;
|
1298 |
+
overflow: hidden;
|
1299 |
+
display: none;
|
1300 |
+
}
|
1301 |
+
|
1302 |
+
.progress-bar {
|
1303 |
+
height: 100%;
|
1304 |
+
background: linear-gradient(90deg, #8e44ad, #3498db);
|
1305 |
+
width: 0%;
|
1306 |
+
transition: width 0.3s ease;
|
1307 |
+
}
|
1308 |
+
|
1309 |
+
.progress-step {
|
1310 |
+
font-size: 0.75rem;
|
1311 |
+
color: var(--gray-600);
|
1312 |
+
margin-top: 0.25rem;
|
1313 |
+
display: none;
|
1314 |
+
}
|
1315 |
+
|
1316 |
+
/* Hide original floating buttons when using ribbon */
|
1317 |
+
.floating-buttons {
|
1318 |
+
display: none;
|
1319 |
+
}
|
templates/index.html
ADDED
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="fr">
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<meta charset="UTF-8">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<title>Patentability</title>
|
8 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
9 |
+
</head>
|
10 |
+
|
11 |
+
<body>
|
12 |
+
<div class="container">
|
13 |
+
<header class="header">
|
14 |
+
<div class="logo">
|
15 |
+
<div class="logo-icon">P</div>
|
16 |
+
<h1>Patentability</h1>
|
17 |
+
</div>
|
18 |
+
<p>Enter a detailed description of your technical problem to generate search queries for finding relevant
|
19 |
+
research papers.</p>
|
20 |
+
</header>
|
21 |
+
|
22 |
+
<div class="tab">
|
23 |
+
<button class="tablinks active" onclick="openTab(event, 'tab1')" id="defaultOpen">Problem
|
24 |
+
Descriptions</button>
|
25 |
+
<button class="tablinks" onclick="openTab(event, 'tab2')">Insights</button>
|
26 |
+
</div>
|
27 |
+
|
28 |
+
<div id="tab1" class="tabcontent">
|
29 |
+
<section class="card">
|
30 |
+
<form id="queryForm" onsubmit="generateQueries(event)">
|
31 |
+
<div class="form-group">
|
32 |
+
<label for="userInput">Technical Problem Description:</label>
|
33 |
+
<div class="problem-history">
|
34 |
+
<textarea id="userInput" placeholder="Describe your technical problem in detail..."
|
35 |
+
required=""></textarea>
|
36 |
+
</div>
|
37 |
+
</div>
|
38 |
+
|
39 |
+
<button type="submit" class="btn btn-primary">Generate Key Issues</button>
|
40 |
+
</form>
|
41 |
+
|
42 |
+
<div id="keyIssuesContainer" class="key-issues-container" style="display: none;">
|
43 |
+
|
44 |
+
</div>
|
45 |
+
</section>
|
46 |
+
|
47 |
+
<section class="card" id="probDescCards" style="display: none;">
|
48 |
+
<div id="probDescContainer" class="prob-desc-container">
|
49 |
+
|
50 |
+
</div>
|
51 |
+
</section>
|
52 |
+
</div>
|
53 |
+
|
54 |
+
<div id="tab2" class="tabcontent">
|
55 |
+
|
56 |
+
<section class="card">
|
57 |
+
<div class="form-group">
|
58 |
+
<label for="userProblemDescription">Technical Problem Description:</label>
|
59 |
+
<div class="problem-history">
|
60 |
+
<div id="problemHistoryNav" class="problem-history-nav" style="display: none;">
|
61 |
+
<div class="history-arrow history-prev disabled" onclick="navigateProblemHistory('prev')">←</div>
|
62 |
+
<div class="history-arrow history-next disabled" onclick="navigateProblemHistory('next')">→</div>
|
63 |
+
<div class="history-status"></div>
|
64 |
+
</div>
|
65 |
+
<textarea id="userProblemDescription" placeholder="Select one of the generated problem descripition..." required disabled></textarea>
|
66 |
+
</div>
|
67 |
+
</div>
|
68 |
+
|
69 |
+
<div id="loadingIndicator">
|
70 |
+
<div class="loading-spinner"></div>
|
71 |
+
<p>Generating search queries... Please wait.</p>
|
72 |
+
</div>
|
73 |
+
|
74 |
+
<div id="refinedProblemContainer" class="refined-problem-container" style="display: none;">
|
75 |
+
<div id="refinedProblemTabs" class="refined-problem-tabs"></div>
|
76 |
+
<div id="refinedProblemContent" class="refined-problem-content"></div>
|
77 |
+
</div>
|
78 |
+
</section>
|
79 |
+
|
80 |
+
<section class="search-options">
|
81 |
+
<label>Search Options:</label>
|
82 |
+
<div class="checkbox-group">
|
83 |
+
<div class="checkbox-item">
|
84 |
+
<input type="checkbox" id="pdfOption" name="searchOptions" value="pdf" checked>
|
85 |
+
<label for="pdfOption">PDF</label>
|
86 |
+
</div>
|
87 |
+
<div class="checkbox-item">
|
88 |
+
<input type="checkbox" id="patentOption" name="searchOptions" value="patent">
|
89 |
+
<label for="patentOption">Patent</label>
|
90 |
+
</div>
|
91 |
+
<div class="checkbox-item">
|
92 |
+
<input type="checkbox" id="webOption" name="searchOptions" value="web">
|
93 |
+
<label for="webOption">Web</label>
|
94 |
+
</div>
|
95 |
+
</div>
|
96 |
+
</section>
|
97 |
+
|
98 |
+
<section id="resultsContainer">
|
99 |
+
<h2>Generated Search Queries</h2>
|
100 |
+
|
101 |
+
<div id="queriesContainer">
|
102 |
+
<!-- Query fields will be added here dynamically -->
|
103 |
+
</div>
|
104 |
+
|
105 |
+
<div class="button-container">
|
106 |
+
<button type="button" class="btn btn-secondary" onclick="addQueryField()">
|
107 |
+
<span>Add New Query</span>
|
108 |
+
</button>
|
109 |
+
</div>
|
110 |
+
</section>
|
111 |
+
|
112 |
+
<div class="ribbon-accordion collapsed">
|
113 |
+
<div class="ribbon-header">
|
114 |
+
<div class="ribbon-title">
|
115 |
+
<span class="ribbon-icon">🧰</span>
|
116 |
+
<span>Patentability Tools</span>
|
117 |
+
</div>
|
118 |
+
<div class="ribbon-toggle">▲</div>
|
119 |
+
</div>
|
120 |
+
<div class="ribbon-content">
|
121 |
+
<div class="progress-bar-container">
|
122 |
+
<div class="progress-bar"></div>
|
123 |
+
</div>
|
124 |
+
<div class="progress-step">Waiting to start...</div>
|
125 |
+
|
126 |
+
<button id="ribbonGenerateQueriesButton" class="btn floating-button" style="background-color: #8e44ad; color: white;" title="Generate Search Queries">
|
127 |
+
Generate Search Queries
|
128 |
+
</button>
|
129 |
+
<button id="ribbonAnalyzeAllButton" class="btn btn-primary floating-button" title="Analyze All Unanalyzed Papers">
|
130 |
+
Analyze All
|
131 |
+
</button>
|
132 |
+
<button id="ribbonRemoveFailedButton" class="btn btn-danger floating-button" title="Remove Papers with Failed Analyses">
|
133 |
+
Remove Failed
|
134 |
+
</button>
|
135 |
+
<button id="ribbonExtractAllInsightsButton" class="btn btn-info floating-button" title="Extract Insights for All Analyzed Documents">
|
136 |
+
Extract All Insights
|
137 |
+
</button>
|
138 |
+
<button id="ribbonGroupInsightsButton" class="btn btn-group-insights floating-button" title="Group All Insights by Score">
|
139 |
+
Group Insights
|
140 |
+
</button>
|
141 |
+
<button id="ribbonEnhanceProblemButton" class="btn enhance-problem-button floating-button" title="Enhance Problem using Selected Insights">
|
142 |
+
Enhance Problem
|
143 |
+
</button>
|
144 |
+
<button id="ribbonExportExcelButton" class="btn btn-success floating-button" title="Export All Data to Excel">
|
145 |
+
Export to Excel
|
146 |
+
</button>
|
147 |
+
</div>
|
148 |
+
</div>
|
149 |
+
</div>
|
150 |
+
|
151 |
+
<div class="floating-buttons">
|
152 |
+
<button id="generateQueriesButton" class="btn floating-button" style="background-color: #8e44ad; color: white;" title="Generate Search Queries">
|
153 |
+
Generate Search Queries
|
154 |
+
</button>
|
155 |
+
<button id="analyzeAllButton" class="btn btn-primary floating-button" title="Analyze All Unanalyzed Papers">
|
156 |
+
Analyze All
|
157 |
+
</button>
|
158 |
+
<button id="removeFailedButton" class="btn btn-danger floating-button" title="Remove Papers with Failed Analyses">
|
159 |
+
Remove Failed
|
160 |
+
</button>
|
161 |
+
<button id="extractAllInsightsButton" class="btn btn-info floating-button disabled" title="Extract Insights for All Analyzed Documents" onclick="extractAllInsights()" disabled>
|
162 |
+
Extract All Insights
|
163 |
+
</button>
|
164 |
+
<button id="groupInsightsByScoreButton" class="btn btn-group-insights floating-button disabled" title="Group All Insights by Score" onclick="groupInsightsByScore()" disabled>
|
165 |
+
Group Insights
|
166 |
+
</button>
|
167 |
+
<button id="enhanceProblemButton" class="btn enhance-problem-button floating-button disabled" title="Enhance Problem using Selected Insights" onclick="enhanceProblem()" disabled>
|
168 |
+
Enhance Problem
|
169 |
+
</button>
|
170 |
+
<button id="exportExcelButton" class="btn btn-success floating-button" title="Export All Data to Excel">
|
171 |
+
Export to Excel
|
172 |
+
</button>
|
173 |
+
</div>
|
174 |
+
|
175 |
+
<div id="globalLoadingOverlay" class="loading-overlay" style="display: none;">
|
176 |
+
<div class="loading-content">
|
177 |
+
<div class="loading-spinner"></div>
|
178 |
+
<div class="progress-text"></div>
|
179 |
+
</div>
|
180 |
+
</div>
|
181 |
+
</div>
|
182 |
+
|
183 |
+
<script src="{{ url_for('static', filename='script.js') }}"></script>
|
184 |
+
</body>
|
185 |
+
|
186 |
+
</html>
|