Spaces:
Runtime error
Runtime error
fix
Browse files
app.py
CHANGED
|
@@ -29,13 +29,14 @@ VEGETABLE_DB = ["broccoli", "celery", "lettuce", "sweet potato", "basil", "aspar
|
|
| 29 |
|
| 30 |
@tool
|
| 31 |
def serper_search(query: str) -> str:
|
| 32 |
-
"""
|
|
|
|
| 33 |
|
| 34 |
Args:
|
| 35 |
-
query: The search query string to look up on the web
|
| 36 |
|
| 37 |
Returns:
|
| 38 |
-
A formatted string containing search results including knowledge graph and organic results
|
| 39 |
"""
|
| 40 |
try:
|
| 41 |
return _cached_serper_search(query)
|
|
@@ -71,14 +72,15 @@ def _cached_serper_search(query: str) -> str:
|
|
| 71 |
|
| 72 |
@tool
|
| 73 |
def wikipedia_detailed(query: str, section: str = None) -> str:
|
| 74 |
-
"""
|
|
|
|
| 75 |
|
| 76 |
Args:
|
| 77 |
-
query: The Wikipedia page title or search term to look up
|
| 78 |
-
section: Optional specific section name to extract from the page
|
| 79 |
|
| 80 |
Returns:
|
| 81 |
-
Wikipedia page content, either full summary with sections or specific section content
|
| 82 |
"""
|
| 83 |
try:
|
| 84 |
wiki_wiki = wikipediaapi.Wikipedia('en')
|
|
@@ -102,13 +104,14 @@ def wikipedia_detailed(query: str, section: str = None) -> str:
|
|
| 102 |
|
| 103 |
@tool
|
| 104 |
def youtube_transcript(video_id: str) -> str:
|
| 105 |
-
"""
|
|
|
|
| 106 |
|
| 107 |
Args:
|
| 108 |
-
video_id: The YouTube video ID (the part after 'v=' in the URL)
|
| 109 |
|
| 110 |
Returns:
|
| 111 |
-
The full transcript text of the video as a single string
|
| 112 |
"""
|
| 113 |
try:
|
| 114 |
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
|
@@ -118,13 +121,14 @@ def youtube_transcript(video_id: str) -> str:
|
|
| 118 |
|
| 119 |
@tool
|
| 120 |
def transcribe_audio(audio_url: str) -> str:
|
| 121 |
-
"""
|
|
|
|
| 122 |
|
| 123 |
Args:
|
| 124 |
-
audio_url: URL pointing to an audio file (mp3, wav, etc.)
|
| 125 |
|
| 126 |
Returns:
|
| 127 |
-
The transcribed text content of the audio file
|
| 128 |
"""
|
| 129 |
try:
|
| 130 |
response = requests.get(audio_url, timeout=30)
|
|
@@ -139,13 +143,14 @@ def transcribe_audio(audio_url: str) -> str:
|
|
| 139 |
|
| 140 |
@tool
|
| 141 |
def analyze_operation_table(table_md: str) -> str:
|
| 142 |
-
"""
|
|
|
|
| 143 |
|
| 144 |
Args:
|
| 145 |
-
table_md: A markdown-formatted table string defining a mathematical operation
|
| 146 |
|
| 147 |
Returns:
|
| 148 |
-
Comma-separated list of elements that violate commutativity in the operation
|
| 149 |
"""
|
| 150 |
try:
|
| 151 |
# Parse markdown table
|
|
@@ -177,13 +182,14 @@ def analyze_operation_table(table_md: str) -> str:
|
|
| 177 |
|
| 178 |
@tool
|
| 179 |
def parse_excel(file_url: str) -> str:
|
| 180 |
-
"""
|
|
|
|
| 181 |
|
| 182 |
Args:
|
| 183 |
-
file_url: URL pointing to an Excel file (.xlsx or .xls)
|
| 184 |
|
| 185 |
Returns:
|
| 186 |
-
String representation of the Excel data content
|
| 187 |
"""
|
| 188 |
try:
|
| 189 |
response = requests.get(file_url, timeout=30)
|
|
@@ -201,13 +207,14 @@ def parse_excel(file_url: str) -> str:
|
|
| 201 |
|
| 202 |
@tool
|
| 203 |
def execute_python(code: str) -> str:
|
| 204 |
-
"""
|
|
|
|
| 205 |
|
| 206 |
Args:
|
| 207 |
-
code: Python code string to execute, should define a 'result' variable
|
| 208 |
|
| 209 |
Returns:
|
| 210 |
-
The value of the 'result' variable after code execution, or error message
|
| 211 |
"""
|
| 212 |
try:
|
| 213 |
# Create safe environment
|
|
@@ -226,13 +233,14 @@ def execute_python(code: str) -> str:
|
|
| 226 |
|
| 227 |
@tool
|
| 228 |
def classify_botanical(items: str) -> str:
|
| 229 |
-
"""
|
|
|
|
| 230 |
|
| 231 |
Args:
|
| 232 |
-
items: Comma-separated string of food items to classify
|
| 233 |
|
| 234 |
Returns:
|
| 235 |
-
Comma-separated list of items that are classified as botanical vegetables
|
| 236 |
"""
|
| 237 |
try:
|
| 238 |
vegetable_list = []
|
|
|
|
| 29 |
|
| 30 |
@tool
|
| 31 |
def serper_search(query: str) -> str:
|
| 32 |
+
"""
|
| 33 |
+
Search the web using Serper API with result caching.
|
| 34 |
|
| 35 |
Args:
|
| 36 |
+
query: The search query string to look up on the web.
|
| 37 |
|
| 38 |
Returns:
|
| 39 |
+
A formatted string containing search results including knowledge graph and organic results.
|
| 40 |
"""
|
| 41 |
try:
|
| 42 |
return _cached_serper_search(query)
|
|
|
|
| 72 |
|
| 73 |
@tool
|
| 74 |
def wikipedia_detailed(query: str, section: str = None) -> str:
|
| 75 |
+
"""
|
| 76 |
+
Fetch detailed Wikipedia content with optional section extraction.
|
| 77 |
|
| 78 |
Args:
|
| 79 |
+
query: The Wikipedia page title or search term to look up.
|
| 80 |
+
section: Optional specific section name to extract from the page.
|
| 81 |
|
| 82 |
Returns:
|
| 83 |
+
Wikipedia page content, either full summary with sections or specific section content.
|
| 84 |
"""
|
| 85 |
try:
|
| 86 |
wiki_wiki = wikipediaapi.Wikipedia('en')
|
|
|
|
| 104 |
|
| 105 |
@tool
|
| 106 |
def youtube_transcript(video_id: str) -> str:
|
| 107 |
+
"""
|
| 108 |
+
Get YouTube video transcript by video ID.
|
| 109 |
|
| 110 |
Args:
|
| 111 |
+
video_id: The YouTube video ID (the part after 'v=' in the URL).
|
| 112 |
|
| 113 |
Returns:
|
| 114 |
+
The full transcript text of the video as a single string.
|
| 115 |
"""
|
| 116 |
try:
|
| 117 |
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
|
|
|
| 121 |
|
| 122 |
@tool
|
| 123 |
def transcribe_audio(audio_url: str) -> str:
|
| 124 |
+
"""
|
| 125 |
+
Transcribe audio from URL using Whisper speech recognition.
|
| 126 |
|
| 127 |
Args:
|
| 128 |
+
audio_url: URL pointing to an audio file (mp3, wav, etc.).
|
| 129 |
|
| 130 |
Returns:
|
| 131 |
+
The transcribed text content of the audio file.
|
| 132 |
"""
|
| 133 |
try:
|
| 134 |
response = requests.get(audio_url, timeout=30)
|
|
|
|
| 143 |
|
| 144 |
@tool
|
| 145 |
def analyze_operation_table(table_md: str) -> str:
|
| 146 |
+
"""
|
| 147 |
+
Parse markdown operation tables and check for commutativity violations.
|
| 148 |
|
| 149 |
Args:
|
| 150 |
+
table_md: A markdown-formatted table string defining a mathematical operation.
|
| 151 |
|
| 152 |
Returns:
|
| 153 |
+
Comma-separated list of elements that violate commutativity in the operation.
|
| 154 |
"""
|
| 155 |
try:
|
| 156 |
# Parse markdown table
|
|
|
|
| 182 |
|
| 183 |
@tool
|
| 184 |
def parse_excel(file_url: str) -> str:
|
| 185 |
+
"""
|
| 186 |
+
Extract and process data from Excel files via URL.
|
| 187 |
|
| 188 |
Args:
|
| 189 |
+
file_url: URL pointing to an Excel file (.xlsx or .xls).
|
| 190 |
|
| 191 |
Returns:
|
| 192 |
+
String representation of the Excel data content.
|
| 193 |
"""
|
| 194 |
try:
|
| 195 |
response = requests.get(file_url, timeout=30)
|
|
|
|
| 207 |
|
| 208 |
@tool
|
| 209 |
def execute_python(code: str) -> str:
|
| 210 |
+
"""
|
| 211 |
+
Safely execute Python code in a restricted environment.
|
| 212 |
|
| 213 |
Args:
|
| 214 |
+
code: Python code string to execute, should define a 'result' variable.
|
| 215 |
|
| 216 |
Returns:
|
| 217 |
+
The value of the 'result' variable after code execution, or error message.
|
| 218 |
"""
|
| 219 |
try:
|
| 220 |
# Create safe environment
|
|
|
|
| 233 |
|
| 234 |
@tool
|
| 235 |
def classify_botanical(items: str) -> str:
|
| 236 |
+
"""
|
| 237 |
+
Classify food items as botanical vegetables from a predefined database.
|
| 238 |
|
| 239 |
Args:
|
| 240 |
+
items: Comma-separated string of food items to classify.
|
| 241 |
|
| 242 |
Returns:
|
| 243 |
+
Comma-separated list of items that are classified as botanical vegetables.
|
| 244 |
"""
|
| 245 |
try:
|
| 246 |
vegetable_list = []
|