Update tools.py
Browse files
tools.py
CHANGED
|
@@ -40,7 +40,11 @@ import openpyxl
|
|
| 40 |
import re
|
| 41 |
from PIL import Image
|
| 42 |
import pytesseract
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
def web_search(query, max_results=3):
|
| 46 |
with DDGS() as ddgs:
|
|
@@ -60,6 +64,7 @@ def wiki_search(query):
|
|
| 60 |
return wikipedia.summary(query, sentences=5)
|
| 61 |
|
| 62 |
def python_repl(code):
|
|
|
|
| 63 |
try:
|
| 64 |
local_vars = {}
|
| 65 |
exec(code, {}, local_vars)
|
|
@@ -68,25 +73,30 @@ def python_repl(code):
|
|
| 68 |
return str(e)
|
| 69 |
|
| 70 |
def get_youtube_transcript(url):
|
|
|
|
| 71 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 72 |
video_id = url.split("v=")[-1]
|
| 73 |
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
| 74 |
return " ".join([t["text"] for t in transcript])
|
| 75 |
|
| 76 |
def speech_recognition(path):
|
|
|
|
| 77 |
r = sr.Recognizer()
|
| 78 |
with sr.AudioFile(path) as source:
|
| 79 |
audio = r.record(source)
|
| 80 |
return r.recognize_google(audio)
|
| 81 |
|
| 82 |
def reverse_string(s):
|
| 83 |
-
|
|
|
|
| 84 |
|
| 85 |
def query_image(path):
|
|
|
|
| 86 |
img = Image.open(path)
|
| 87 |
text = pytesseract.image_to_string(img)
|
| 88 |
return text
|
| 89 |
|
| 90 |
def query_video(path):
|
|
|
|
| 91 |
return "Video analysis not implemented yet"
|
| 92 |
|
|
|
|
| 40 |
import re
|
| 41 |
from PIL import Image
|
| 42 |
import pytesseract
|
| 43 |
+
try:
|
| 44 |
+
from duckduckgo_search import DDGS
|
| 45 |
+
except ImportError:
|
| 46 |
+
from ddgs import DDGS
|
| 47 |
+
|
| 48 |
|
| 49 |
def web_search(query, max_results=3):
|
| 50 |
with DDGS() as ddgs:
|
|
|
|
| 64 |
return wikipedia.summary(query, sentences=5)
|
| 65 |
|
| 66 |
def python_repl(code):
|
| 67 |
+
print(code)
|
| 68 |
try:
|
| 69 |
local_vars = {}
|
| 70 |
exec(code, {}, local_vars)
|
|
|
|
| 73 |
return str(e)
|
| 74 |
|
| 75 |
def get_youtube_transcript(url):
|
| 76 |
+
print(url)
|
| 77 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 78 |
video_id = url.split("v=")[-1]
|
| 79 |
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
| 80 |
return " ".join([t["text"] for t in transcript])
|
| 81 |
|
| 82 |
def speech_recognition(path):
|
| 83 |
+
print(path)
|
| 84 |
r = sr.Recognizer()
|
| 85 |
with sr.AudioFile(path) as source:
|
| 86 |
audio = r.record(source)
|
| 87 |
return r.recognize_google(audio)
|
| 88 |
|
| 89 |
def reverse_string(s):
|
| 90 |
+
rs = s[::-1]
|
| 91 |
+
return web_search(rs)
|
| 92 |
|
| 93 |
def query_image(path):
|
| 94 |
+
print(path)
|
| 95 |
img = Image.open(path)
|
| 96 |
text = pytesseract.image_to_string(img)
|
| 97 |
return text
|
| 98 |
|
| 99 |
def query_video(path):
|
| 100 |
+
print(path)
|
| 101 |
return "Video analysis not implemented yet"
|
| 102 |
|