MMADS commited on
Commit
33d9b51
Β·
1 Parent(s): 9c17941

changed default year & date formatting

Browse files
Files changed (1) hide show
  1. app.py +26 -13
app.py CHANGED
@@ -115,9 +115,13 @@ class CVEDashboard:
115
 
116
  logger.info(f"Fetching CVEs from {current_start.date()} to {chunk_end.date()}")
117
 
 
 
 
 
118
  params = {
119
- 'pubStartDate': current_start.strftime('%Y-%m-%dT%H:%M:%S.000'),
120
- 'pubEndDate': chunk_end.strftime('%Y-%m-%dT%H:%M:%S.999'),
121
  'resultsPerPage': min(results_per_page, 2000)
122
  }
123
 
@@ -130,7 +134,15 @@ class CVEDashboard:
130
  params=params,
131
  timeout=30
132
  )
133
- response.raise_for_status()
 
 
 
 
 
 
 
 
134
 
135
  data = response.json()
136
  vulnerabilities = data.get('vulnerabilities', [])
@@ -147,6 +159,9 @@ class CVEDashboard:
147
  continue
148
  processed_cves.append(cve)
149
 
 
 
 
150
  status = f"βœ“ Fetched {len(processed_cves)} CVEs from the year {year}"
151
  if keyword:
152
  status += f" matching '{keyword}'"
@@ -159,9 +174,10 @@ class CVEDashboard:
159
  error_details = ""
160
  if e.response is not None:
161
  try:
162
- error_details = f" - {e.response.json().get('message', e.response.text)}"
 
163
  except json.JSONDecodeError:
164
- error_details = f" - {e.response.text}"
165
  return [], f"βœ— API Error: {str(e)}{error_details}"
166
  except Exception as e:
167
  return [], f"βœ— Error: {str(e)}"
@@ -400,15 +416,12 @@ def generate_tailored_summary(cve_description: str, audience: str, hf_token: Opt
400
  {
401
  "role": "user",
402
  "content": f"""You are an expert cybersecurity analyst. Rewrite this CVE description for a {audience}.
403
-
404
  **Target Audience:** {audience}
405
  **Focus:** {profile['focus']}
406
  **Tone:** {profile['tone']}
407
  **Key Priorities:** {', '.join(profile['priorities'])}
408
-
409
  **CVE Description:**
410
  {cve_description[:1200]}
411
-
412
  Provide a concise, actionable summary (2-3 sentences) highlighting what matters most to this audience. Focus on practical implications and next steps."""
413
  }
414
  ]
@@ -429,12 +442,9 @@ Provide a concise, actionable summary (2-3 sentences) highlighting what matters
429
  else:
430
  # Fallback to Mistral format
431
  prompt = f"""<s>[INST] You are an expert cybersecurity analyst. Rewrite the following CVE description for a {audience}.
432
-
433
  **Focus:** {profile['focus']}
434
  **Tone:** {profile['tone']}
435
-
436
  CVE: {cve_description[:1000]}
437
-
438
  Provide a 2-3 sentence summary highlighting what matters most to this audience: [/INST]"""
439
 
440
  payload = {
@@ -541,15 +551,18 @@ def create_interface():
541
  )
542
  else:
543
  gr.Markdown("### βœ… AI Ready")
544
- gr.Markdown("!!!This whole column will be rewritten!!")
545
  hf_token = gr.State(dashboard.hf_token) # Hidden state
546
 
547
  gr.Markdown("### πŸ” Search Parameters")
548
 
549
  current_year = datetime.now().year
 
 
 
550
  year_filter = gr.Dropdown(
551
  choices=list(range(current_year, current_year - 10, -1)),
552
- value=current_year,
553
  label="Year"
554
  )
555
 
 
115
 
116
  logger.info(f"Fetching CVEs from {current_start.date()} to {chunk_end.date()}")
117
 
118
+ # Format dates with timezone information (Z for UTC)
119
+ start_date_str = current_start.strftime('%Y-%m-%dT%H:%M:%S.000Z')
120
+ end_date_str = chunk_end.strftime('%Y-%m-%dT%H:%M:%S.999Z')
121
+
122
  params = {
123
+ 'pubStartDate': start_date_str,
124
+ 'pubEndDate': end_date_str,
125
  'resultsPerPage': min(results_per_page, 2000)
126
  }
127
 
 
134
  params=params,
135
  timeout=30
136
  )
137
+
138
+ # Handle different error scenarios
139
+ if response.status_code == 404:
140
+ logger.warning(f"No data found for date range {current_start.date()} to {chunk_end.date()}")
141
+ # Move to the next chunk and continue
142
+ current_start = chunk_end + timedelta(days=1)
143
+ continue
144
+ elif response.status_code != 200:
145
+ response.raise_for_status()
146
 
147
  data = response.json()
148
  vulnerabilities = data.get('vulnerabilities', [])
 
159
  continue
160
  processed_cves.append(cve)
161
 
162
+ if not processed_cves:
163
+ return [], f"No CVEs found for year {year}" + (f" matching '{keyword}'" if keyword else "") + (f" with {severity} severity" if severity else "")
164
+
165
  status = f"βœ“ Fetched {len(processed_cves)} CVEs from the year {year}"
166
  if keyword:
167
  status += f" matching '{keyword}'"
 
174
  error_details = ""
175
  if e.response is not None:
176
  try:
177
+ error_data = e.response.json()
178
+ error_details = f" - {error_data.get('message', e.response.text)}"
179
  except json.JSONDecodeError:
180
+ error_details = f" - Status: {e.response.status_code}, Response: {e.response.text[:200]}"
181
  return [], f"βœ— API Error: {str(e)}{error_details}"
182
  except Exception as e:
183
  return [], f"βœ— Error: {str(e)}"
 
416
  {
417
  "role": "user",
418
  "content": f"""You are an expert cybersecurity analyst. Rewrite this CVE description for a {audience}.
 
419
  **Target Audience:** {audience}
420
  **Focus:** {profile['focus']}
421
  **Tone:** {profile['tone']}
422
  **Key Priorities:** {', '.join(profile['priorities'])}
 
423
  **CVE Description:**
424
  {cve_description[:1200]}
 
425
  Provide a concise, actionable summary (2-3 sentences) highlighting what matters most to this audience. Focus on practical implications and next steps."""
426
  }
427
  ]
 
442
  else:
443
  # Fallback to Mistral format
444
  prompt = f"""<s>[INST] You are an expert cybersecurity analyst. Rewrite the following CVE description for a {audience}.
 
445
  **Focus:** {profile['focus']}
446
  **Tone:** {profile['tone']}
 
447
  CVE: {cve_description[:1000]}
 
448
  Provide a 2-3 sentence summary highlighting what matters most to this audience: [/INST]"""
449
 
450
  payload = {
 
551
  )
552
  else:
553
  gr.Markdown("### βœ… AI Ready")
554
+ gr.Markdown("HuggingFace token configured via environment variable")
555
  hf_token = gr.State(dashboard.hf_token) # Hidden state
556
 
557
  gr.Markdown("### πŸ” Search Parameters")
558
 
559
  current_year = datetime.now().year
560
+ # Default to previous year to ensure we have data
561
+ default_year = current_year - 1 if current_year == 2025 else current_year
562
+
563
  year_filter = gr.Dropdown(
564
  choices=list(range(current_year, current_year - 10, -1)),
565
+ value=default_year,
566
  label="Year"
567
  )
568