File size: 4,305 Bytes
d280ec3 152e399 d280ec3 152e399 d280ec3 152e399 f8aff73 11349a6 7d81296 40fcb2e 152e399 bf9b2a2 f8aff73 152e399 40fcb2e 7d81296 40fcb2e 282fb4d 152e399 ea5788b 11349a6 d280ec3 152e399 d280ec3 b9156be 152e399 11349a6 152e399 f8aff73 d280ec3 152e399 ea5788b 11349a6 152e399 d280ec3 152e399 40fcb2e 282fb4d 152e399 ea5788b 11349a6 f8aff73 152e399 282fb4d 152e399 ea5788b 11349a6 152e399 d280ec3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
"""
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):
#wikipedia.set_lang("en")
#return wikipedia.summary(query, sentences=5)
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']) # Add 'ru', 'tr', etc. if needed
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"
|