tatianija commited on
Commit
adacbb6
·
verified ·
1 Parent(s): d6efa0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -1
app.py CHANGED
@@ -28,6 +28,64 @@ cached_answers = {}
28
  cached_questions = []
29
  processing_status = {"is_processing": False, "progress": 0, "total": 0}
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  # --- Web Content Fetcher ---
32
  class WebContentFetcher:
33
  def __init__(self, debug: bool = True):
@@ -389,7 +447,7 @@ class AudioTranscriptionTool:
389
  # --- Enhanced Intelligent Agent with Direct Attachment Processing ---
390
  class IntelligentAgent:
391
  def __init__(self, debug: bool = True, model_name: str = "meta-llama/Llama-3.1-8B-Instruct"):
392
- self.search_tool = DuckDuckGoSearchTool()
393
  self.client = InferenceClient(model=model_name, provider="sambanova")
394
  self.image_tool = ImageAnalysisTool()
395
  self.audio_tool = AudioTranscriptionTool()
 
28
  cached_questions = []
29
  processing_status = {"is_processing": False, "progress": 0, "total": 0}
30
 
31
+
32
+ # simple search instrad of duck:
33
+ class SimpleSearchTool:
34
+ """
35
+ Simple search tool that scrapes DuckDuckGo HTML results.
36
+ Drop-in replacement for DuckDuckGoSearchTool.
37
+ """
38
+
39
+ def __init__(self):
40
+ self.session = requests.Session()
41
+ self.session.headers.update({
42
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
43
+ })
44
+
45
+ def run(self, query: str) -> str:
46
+ """Search and return formatted results."""
47
+ try:
48
+ # Encode query for URL
49
+ encoded_query = urllib.parse.quote_plus(query)
50
+ url = f"https://html.duckduckgo.com/html/?q={encoded_query}"
51
+
52
+ response = self.session.get(url, timeout=10)
53
+ response.raise_for_status()
54
+
55
+ soup = BeautifulSoup(response.content, 'html.parser')
56
+ results = []
57
+
58
+ # Find search result containers
59
+ result_containers = soup.find_all('div', class_='result__body')
60
+
61
+ for i, container in enumerate(result_containers[:5], 1):
62
+ try:
63
+ # Extract title and URL
64
+ title_elem = container.find('a', class_='result__a')
65
+ if not title_elem:
66
+ continue
67
+
68
+ title = title_elem.get_text().strip()
69
+ url = title_elem.get('href', '')
70
+
71
+ # Extract snippet
72
+ snippet_elem = container.find('a', class_='result__snippet')
73
+ snippet = snippet_elem.get_text().strip() if snippet_elem else ''
74
+
75
+ if title and url:
76
+ result = f"{i}. {title}\n URL: {url}\n"
77
+ if snippet:
78
+ result += f" Snippet: {snippet}\n"
79
+ results.append(result)
80
+
81
+ except Exception:
82
+ continue
83
+
84
+ return "\n".join(results) if results else "No search results found."
85
+
86
+ except Exception as e:
87
+ return f"Search failed: {str(e)}"
88
+
89
  # --- Web Content Fetcher ---
90
  class WebContentFetcher:
91
  def __init__(self, debug: bool = True):
 
447
  # --- Enhanced Intelligent Agent with Direct Attachment Processing ---
448
  class IntelligentAgent:
449
  def __init__(self, debug: bool = True, model_name: str = "meta-llama/Llama-3.1-8B-Instruct"):
450
+ self.search_tool = SimpleSearchTool()
451
  self.client = InferenceClient(model=model_name, provider="sambanova")
452
  self.image_tool = ImageAnalysisTool()
453
  self.audio_tool = AudioTranscriptionTool()