Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
@@ -4,7 +4,6 @@ import os
|
|
4 |
import re
|
5 |
from typing import Optional
|
6 |
from token_bucket import Limiter
|
7 |
-
from youtube_transcript_api import YouTubeTranscriptApi
|
8 |
import yaml
|
9 |
from PIL import Image
|
10 |
import requests
|
@@ -94,19 +93,6 @@ def SpeechToTextTool(audio_path: str) -> str:
|
|
94 |
return result.get("text", "")
|
95 |
|
96 |
|
97 |
-
@tool
|
98 |
-
def youtube_transcript(url: str) -> str:
|
99 |
-
"""
|
100 |
-
Get transcript of YouTube video.
|
101 |
-
Args:
|
102 |
-
url: YouTube video url in ""
|
103 |
-
"""
|
104 |
-
video_id = url.partition("https://www.youtube.com/watch?v=")[2]
|
105 |
-
|
106 |
-
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
107 |
-
transcript_text = " ".join([item["text"] for item in transcript])
|
108 |
-
return {"youtube_transcript": transcript_text}
|
109 |
-
|
110 |
#@tool
|
111 |
#class LocalFileAudioTool:
|
112 |
# """Tool for transcribing audio files"""
|
@@ -127,7 +113,7 @@ class MagAgent:
|
|
127 |
self.rate_limiter = rate_limiter
|
128 |
print("Initializing MagAgent with search tools...")
|
129 |
model = LiteLLMModel(
|
130 |
-
model_id="gemini/gemini-2.0-flash",
|
131 |
api_key= os.environ.get("GEMINI_KEY"),
|
132 |
max_tokens=8192
|
133 |
)
|
@@ -170,14 +156,15 @@ class MagAgent:
|
|
170 |
)
|
171 |
|
172 |
# Ensure response is a string, fixing the integer error
|
173 |
-
response = str(response)
|
|
|
|
|
174 |
|
175 |
-
if not response or "No Wikipedia page found" in response:
|
176 |
-
# Fallback response if search fails
|
177 |
-
response = "Unable to retrieve exact data. Please refine the question or check external sources."
|
178 |
print(f"MagAgent response: {response[:50]}...")
|
179 |
return response
|
|
|
180 |
except Exception as e:
|
181 |
error_msg = f"Error processing question: {str(e)}. Check API key or network connectivity."
|
182 |
print(error_msg)
|
183 |
-
return error_msg
|
|
|
|
4 |
import re
|
5 |
from typing import Optional
|
6 |
from token_bucket import Limiter
|
|
|
7 |
import yaml
|
8 |
from PIL import Image
|
9 |
import requests
|
|
|
93 |
return result.get("text", "")
|
94 |
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
#@tool
|
97 |
#class LocalFileAudioTool:
|
98 |
# """Tool for transcribing audio files"""
|
|
|
113 |
self.rate_limiter = rate_limiter
|
114 |
print("Initializing MagAgent with search tools...")
|
115 |
model = LiteLLMModel(
|
116 |
+
model_id="gemini/gemini-2.0-flash-lite",
|
117 |
api_key= os.environ.get("GEMINI_KEY"),
|
118 |
max_tokens=8192
|
119 |
)
|
|
|
156 |
)
|
157 |
|
158 |
# Ensure response is a string, fixing the integer error
|
159 |
+
response = str(response)
|
160 |
+
if response is None:
|
161 |
+
print(f"No answer found.")
|
162 |
|
|
|
|
|
|
|
163 |
print(f"MagAgent response: {response[:50]}...")
|
164 |
return response
|
165 |
+
|
166 |
except Exception as e:
|
167 |
error_msg = f"Error processing question: {str(e)}. Check API key or network connectivity."
|
168 |
print(error_msg)
|
169 |
+
return error_msg
|
170 |
+
|