LamiaYT commited on
Commit
8951044
·
1 Parent(s): 984a8c3
Files changed (1) hide show
  1. app.py +65 -8
app.py CHANGED
@@ -29,7 +29,14 @@ VEGETABLE_DB = ["broccoli", "celery", "lettuce", "sweet potato", "basil", "aspar
29
 
30
  @tool
31
  def serper_search(query: str) -> str:
32
- """Search the web using Serper API with result caching"""
 
 
 
 
 
 
 
33
  try:
34
  return _cached_serper_search(query)
35
  except Exception as e:
@@ -64,7 +71,15 @@ def _cached_serper_search(query: str) -> str:
64
 
65
  @tool
66
  def wikipedia_detailed(query: str, section: str = None) -> str:
67
- """Fetch detailed Wikipedia content with section extraction"""
 
 
 
 
 
 
 
 
68
  try:
69
  wiki_wiki = wikipediaapi.Wikipedia('en')
70
  page = wiki_wiki.page(query)
@@ -87,7 +102,14 @@ def wikipedia_detailed(query: str, section: str = None) -> str:
87
 
88
  @tool
89
  def youtube_transcript(video_id: str) -> str:
90
- """Get YouTube video transcript"""
 
 
 
 
 
 
 
91
  try:
92
  transcript = YouTubeTranscriptApi.get_transcript(video_id)
93
  return " ".join([entry['text'] for entry in transcript])
@@ -96,7 +118,14 @@ def youtube_transcript(video_id: str) -> str:
96
 
97
  @tool
98
  def transcribe_audio(audio_url: str) -> str:
99
- """Transcribe audio using Whisper"""
 
 
 
 
 
 
 
100
  try:
101
  response = requests.get(audio_url, timeout=30)
102
  audio_data = io.BytesIO(response.content)
@@ -110,7 +139,14 @@ def transcribe_audio(audio_url: str) -> str:
110
 
111
  @tool
112
  def analyze_operation_table(table_md: str) -> str:
113
- """Parse markdown tables and check commutativity"""
 
 
 
 
 
 
 
114
  try:
115
  # Parse markdown table
116
  lines = table_md.strip().split('\n')
@@ -141,7 +177,14 @@ def analyze_operation_table(table_md: str) -> str:
141
 
142
  @tool
143
  def parse_excel(file_url: str) -> str:
144
- """Extract and process Excel data"""
 
 
 
 
 
 
 
145
  try:
146
  response = requests.get(file_url, timeout=30)
147
  wb = openpyxl.load_workbook(io.BytesIO(response.content))
@@ -158,7 +201,14 @@ def parse_excel(file_url: str) -> str:
158
 
159
  @tool
160
  def execute_python(code: str) -> str:
161
- """Safely execute Python code"""
 
 
 
 
 
 
 
162
  try:
163
  # Create safe environment
164
  safe_globals = {'__builtins__': None}
@@ -176,7 +226,14 @@ def execute_python(code: str) -> str:
176
 
177
  @tool
178
  def classify_botanical(items: str) -> str:
179
- """Classify items as botanical vegetables"""
 
 
 
 
 
 
 
180
  try:
181
  vegetable_list = []
182
  for item in items.split(','):
 
29
 
30
  @tool
31
  def serper_search(query: str) -> str:
32
+ """Search the web using Serper API with result caching
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)
42
  except Exception as e:
 
71
 
72
  @tool
73
  def wikipedia_detailed(query: str, section: str = None) -> str:
74
+ """Fetch detailed Wikipedia content with optional section extraction
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')
85
  page = wiki_wiki.page(query)
 
102
 
103
  @tool
104
  def youtube_transcript(video_id: str) -> str:
105
+ """Get YouTube video transcript by video ID
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)
115
  return " ".join([entry['text'] for entry in transcript])
 
118
 
119
  @tool
120
  def transcribe_audio(audio_url: str) -> str:
121
+ """Transcribe audio from URL using Whisper speech recognition
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)
131
  audio_data = io.BytesIO(response.content)
 
139
 
140
  @tool
141
  def analyze_operation_table(table_md: str) -> str:
142
+ """Parse markdown operation tables and check for commutativity violations
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
152
  lines = table_md.strip().split('\n')
 
177
 
178
  @tool
179
  def parse_excel(file_url: str) -> str:
180
+ """Extract and process data from Excel files via URL
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)
190
  wb = openpyxl.load_workbook(io.BytesIO(response.content))
 
201
 
202
  @tool
203
  def execute_python(code: str) -> str:
204
+ """Safely execute Python code in a restricted environment
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
214
  safe_globals = {'__builtins__': None}
 
226
 
227
  @tool
228
  def classify_botanical(items: str) -> str:
229
+ """Classify food items as botanical vegetables from a predefined database
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 = []
239
  for item in items.split(','):