| import gradio as gr | |
| import time | |
| from typing import Any, Optional | |
| from smolagents.tools import Tool | |
| #import duckduckgo_search | |
| class PlaySomeMusicMeastro(Tool): | |
| name = "play_music" | |
| description = "Play a piece of music then returns sound to the listener." | |
| inputs = {'answer': {'type': 'string', 'description': 'The song to play.'}} | |
| # output_type = "string" | |
| output_type = "audio" | |
| def __init__(self, *args, **kwargs): | |
| super().__init__() | |
| # try: | |
| # from duckduckgo_search import DDGS | |
| # except ImportError as e: | |
| # raise ImportError( | |
| # "You must install package `duckduckgo_search` to run this tool: for instance run `pip install duckduckgo-search`." | |
| # ) from e | |
| # self.ddgs = DDGS(**kwargs) | |
| def forward(self, answer: str) -> str: | |
| gr.Audio(value="../resources/GenAI Revolution.mp3", autoplay=True) | |
| print("Playing some music") | |
| time.sleep(5) | |
| # results = self.ddgs.text(query, max_results=self.max_results) | |
| # if len(results) == 0: | |
| # raise Exception("No results found! Try a less restrictive/shorter query.") | |
| # postprocessed_results = [f"[{result['title']}]({result['href']})\n{result['body']}" for result in results] | |
| # return "Done playing some music!!" | |
| return gr.Audio(value="../resources/GenAI Revolution.mp3", autoplay=True) | |