|
|
""" |
|
|
web_search: searches the web |
|
|
wiki_search: searches Wikipedia |
|
|
python_repl: python code interpreter |
|
|
get_youtube_transcript: retrieves the transcript of a YouTube video |
|
|
speech_recognition: transcribes an audio file |
|
|
reverse_string: reverses the character order of the input string |
|
|
query_image: analyzes a given image |
|
|
query_video: analyzes a given video |
|
|
|
|
|
| Q# | Tool | Description | |
|
|
| -- | ------------------------ | ---------------------------------------- | |
|
|
| 1 | `wiki_search` | Wikipedia album count | |
|
|
| 2 | `get_youtube_transcript` | Analyze bird count from video transcript | |
|
|
| 3 | `reverse_string` | Reverse logic | |
|
|
| 4 | `query_image` | Chess image analysis | |
|
|
| 5 | `wiki_search` | Featured article nomination | |
|
|
| 6 | `python_repl` | Commutativity checker | |
|
|
| 7 | `get_youtube_transcript` | Dialogue from YouTube | |
|
|
| 8 | `wiki_search` | LibreText content | |
|
|
| 9 | `python_repl` | Filter botanical vegetables | |
|
|
| 10 | `speech_recognition` | Extract ingredients from audio | |
|
|
| 11 | `web_search` | Actor roles in two shows | |
|
|
| 12 | `python_repl` | Run Python code | |
|
|
| 13 | `web_search` | Baseball stats lookup | |
|
|
| 14 | `speech_recognition` | Page numbers from professor's voice | |
|
|
| 15 | `web_search` | NASA grant lookup | |
|
|
| 16 | `wiki_search` | Location in paper | |
|
|
| 17 | `wiki_search` | Olympic data | |
|
|
| 18 | `web_search` | Baseball jersey lookup | |
|
|
| 19 | `python_repl` | Sum Excel column | |
|
|
| 20 | `wiki_search` | Malko competition history | |
|
|
|
|
|
""" |
|
|
import wikipedia |
|
|
import requests |
|
|
import speech_recognition as sr |
|
|
from pytube import YouTube |
|
|
import openpyxl |
|
|
import re |
|
|
from PIL import Image |
|
|
from smolagents import DuckDuckGoSearchTool |
|
|
|
|
|
|
|
|
from huggingface_hub import snapshot_download |
|
|
from transformers import AutoTokenizer, AutoModelForCausalLM |
|
|
|
|
|
|
|
|
|
|
|
def web_search(query, max_results=3): |
|
|
searchtool = DuckDuckGoSearchTool(query) |
|
|
result = searchtool(query) |
|
|
return result |
|
|
|
|
|
def wiki_search(query): |
|
|
|
|
|
|
|
|
|
|
|
local_dir = snapshot_download("tiiuae/falcon-7b-instruct", local_dir="/home/user/.cache", use_auth_token=False) |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(local_dir) |
|
|
model = AutoModelForCausalLM.from_pretrained(local_dir) |
|
|
|
|
|
chat = pipeline("text-generation", model=model, tokenizer=tokenizer) |
|
|
|
|
|
response = chat(query, max_new_tokens=50) |
|
|
return response[0]['generated_text'] |
|
|
|
|
|
|
|
|
def python_repl(code): |
|
|
code = "AkylaiBva/Final_Assignment_Template_AB/"+code |
|
|
print(code) |
|
|
try: |
|
|
local_vars = {} |
|
|
exec(code, {}, local_vars) |
|
|
return str(local_vars) |
|
|
except Exception as e: |
|
|
return str(e) |
|
|
|
|
|
def get_youtube_transcript(url): |
|
|
print(url) |
|
|
from youtube_transcript_api import YouTubeTranscriptApi |
|
|
video_id = url.split("v=")[-1] |
|
|
transcript = YouTubeTranscriptApi.get_transcript(video_id) |
|
|
return transcript |
|
|
|
|
|
def speech_recognition(path): |
|
|
path = "AkylaiBva/Final_Assignment_Template_AB/"+ path |
|
|
print(path) |
|
|
r = sr.Recognizer() |
|
|
with sr.AudioFile(path) as source: |
|
|
audio = r.record(source) |
|
|
return r.recognize_google(audio) |
|
|
|
|
|
def reverse_string(s): |
|
|
return s[::-1] |
|
|
|
|
|
def query_image(path): |
|
|
path = "AkylaiBva/Final_Assignment_Template_AB/"+ path |
|
|
print(path) |
|
|
import easyocr |
|
|
|
|
|
reader = easyocr.Reader(['en']) |
|
|
result = reader.readtext('image.jpg') |
|
|
|
|
|
text = "" |
|
|
for bbox, text, confidence in result: |
|
|
text += f"{text} (confidence: {confidence})" |
|
|
return text |
|
|
|
|
|
def query_video(path): |
|
|
path = "AkylaiBva/Final_Assignment_Template_AB/"+path |
|
|
print(path) |
|
|
return "Video analysis not implemented yet" |
|
|
|
|
|
|