Update tools.py
Browse files
tools.py
CHANGED
|
@@ -40,24 +40,13 @@ import openpyxl
|
|
| 40 |
import re
|
| 41 |
from PIL import Image
|
| 42 |
import pytesseract
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
except ImportError:
|
| 46 |
-
from ddgs import DDGS
|
| 47 |
|
| 48 |
|
| 49 |
def web_search(query, max_results=3):
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
if not results:
|
| 53 |
-
return "No results found."
|
| 54 |
-
output = []
|
| 55 |
-
for r in results:
|
| 56 |
-
title = r.get('title')
|
| 57 |
-
url = r.get('href')
|
| 58 |
-
snippet = r.get('body')
|
| 59 |
-
output.append(f"{title}\n{url}\n{snippet}\n")
|
| 60 |
-
return "\n".join(output)
|
| 61 |
|
| 62 |
def wiki_search(query):
|
| 63 |
wikipedia.set_lang("en")
|
|
@@ -77,7 +66,7 @@ def get_youtube_transcript(url):
|
|
| 77 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 78 |
video_id = url.split("v=")[-1]
|
| 79 |
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
| 80 |
-
return
|
| 81 |
|
| 82 |
def speech_recognition(path):
|
| 83 |
print(path)
|
|
@@ -92,8 +81,14 @@ def reverse_string(s):
|
|
| 92 |
|
| 93 |
def query_image(path):
|
| 94 |
print(path)
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
return text
|
| 98 |
|
| 99 |
def query_video(path):
|
|
|
|
| 40 |
import re
|
| 41 |
from PIL import Image
|
| 42 |
import pytesseract
|
| 43 |
+
from smolagents import DuckDuckGoSearchTool
|
| 44 |
+
|
|
|
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
def web_search(query, max_results=3):
|
| 48 |
+
result = DuckDuckGoSearchTool(query)
|
| 49 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
def wiki_search(query):
|
| 52 |
wikipedia.set_lang("en")
|
|
|
|
| 66 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 67 |
video_id = url.split("v=")[-1]
|
| 68 |
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
| 69 |
+
return transcript
|
| 70 |
|
| 71 |
def speech_recognition(path):
|
| 72 |
print(path)
|
|
|
|
| 81 |
|
| 82 |
def query_image(path):
|
| 83 |
print(path)
|
| 84 |
+
import easyocr
|
| 85 |
+
|
| 86 |
+
reader = easyocr.Reader(['en']) # Add 'ru', 'tr', etc. if needed
|
| 87 |
+
result = reader.readtext('image.jpg')
|
| 88 |
+
|
| 89 |
+
text = ""
|
| 90 |
+
for bbox, text, confidence in result:
|
| 91 |
+
text += f"{text} (confidence: {confidence})"
|
| 92 |
return text
|
| 93 |
|
| 94 |
def query_video(path):
|