Johan713 commited on
Commit
dc760ad
·
verified ·
1 Parent(s): b99151b

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +17 -3
app2.py CHANGED
@@ -28,6 +28,8 @@ from datetime import datetime
28
  import spacy
29
  import time
30
  from selenium import webdriver
 
 
31
  from selenium.webdriver.chrome.options import Options
32
  from selenium.webdriver.common.by import By
33
  from selenium.webdriver.support.ui import WebDriverWait
@@ -322,14 +324,16 @@ def rate_limit():
322
  def fetch_detailed_content(url):
323
  rate_limit()
324
 
325
- chrome_options = Options()
326
  chrome_options.add_argument("--headless")
327
  chrome_options.add_argument("--no-sandbox")
328
  chrome_options.add_argument("--disable-dev-shm-usage")
329
  chrome_options.add_argument(f"user-agent={get_random_user_agent()}")
330
 
331
  try:
332
- with webdriver.Chrome(options=chrome_options) as driver:
 
 
333
  driver.get(url)
334
 
335
  # Wait for the main content to load
@@ -367,7 +371,7 @@ def fetch_detailed_content(url):
367
 
368
  except Exception as e:
369
  print(f"Error fetching content: {e}")
370
- return f"Unable to fetch detailed content. Error: {str(e)}"
371
 
372
  def clean_content(text):
373
  # Remove extra whitespace and newlines
@@ -538,6 +542,16 @@ def format_public_cases(cases: List[Dict[str, Any]]) -> str:
538
  formatted += "\n"
539
  return formatted
540
 
 
 
 
 
 
 
 
 
 
 
541
  def find_case_precedents(case_details: str) -> Dict[str, Any]:
542
  """Finds relevant case precedents based on provided details."""
543
  try:
 
28
  import spacy
29
  import time
30
  from selenium import webdriver
31
+ from selenium.webdriver.chrome.service import Service
32
+ from webdriver_manager.chrome import ChromeDriverManager
33
  from selenium.webdriver.chrome.options import Options
34
  from selenium.webdriver.common.by import By
35
  from selenium.webdriver.support.ui import WebDriverWait
 
324
  def fetch_detailed_content(url):
325
  rate_limit()
326
 
327
+ chrome_options = webdriver.ChromeOptions()
328
  chrome_options.add_argument("--headless")
329
  chrome_options.add_argument("--no-sandbox")
330
  chrome_options.add_argument("--disable-dev-shm-usage")
331
  chrome_options.add_argument(f"user-agent={get_random_user_agent()}")
332
 
333
  try:
334
+ # Use webdriver_manager to handle driver installation
335
+ service = Service(ChromeDriverManager().install())
336
+ with webdriver.Chrome(service=service, options=chrome_options) as driver:
337
  driver.get(url)
338
 
339
  # Wait for the main content to load
 
371
 
372
  except Exception as e:
373
  print(f"Error fetching content: {e}")
374
+ return f"Unable to fetch detailed content. Error: {str(e)}", {}
375
 
376
  def clean_content(text):
377
  # Remove extra whitespace and newlines
 
542
  formatted += "\n"
543
  return formatted
544
 
545
+ def format_web_results(results: List[Dict[str, str]]) -> str:
546
+ """Format web search results for the AI prompt."""
547
+ formatted = ""
548
+ for result in results:
549
+ formatted += f"Title: {result['title']}\n"
550
+ formatted += f"Snippet: {result['snippet']}\n"
551
+ formatted += f"URL: {result['link']}\n\n"
552
+ return formatted
553
+
554
+
555
  def find_case_precedents(case_details: str) -> Dict[str, Any]:
556
  """Finds relevant case precedents based on provided details."""
557
  try: