Spaces:
Runtime error
Runtime error
Update tools/tools.py
Browse files- tools/tools.py +8 -12
tools/tools.py
CHANGED
|
@@ -74,24 +74,20 @@ def ask_youtube_video(url: str, question: str) -> str:
|
|
| 74 |
Sends a YouTube video to a multimodal model and asks a question about it.
|
| 75 |
|
| 76 |
Args:
|
| 77 |
-
url (str): The
|
| 78 |
question (str): The natural language question to ask about the video.
|
| 79 |
|
| 80 |
Returns:
|
| 81 |
str: The model's answer to the question.
|
| 82 |
"""
|
| 83 |
-
|
| 84 |
try:
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
]}
|
| 93 |
-
]
|
| 94 |
-
)
|
| 95 |
return response.text
|
| 96 |
except Exception as e:
|
| 97 |
return f"Error asking {MODEL_ID} about video: {str(e)}"
|
|
|
|
| 74 |
Sends a YouTube video to a multimodal model and asks a question about it.
|
| 75 |
|
| 76 |
Args:
|
| 77 |
+
url (str): The URL of the YouTube video.
|
| 78 |
question (str): The natural language question to ask about the video.
|
| 79 |
|
| 80 |
Returns:
|
| 81 |
str: The model's answer to the question.
|
| 82 |
"""
|
|
|
|
| 83 |
try:
|
| 84 |
+
genai.configure(api_key=os.getenv('GEMINI_API'))
|
| 85 |
+
model = genai.GenerativeModel(MODEL_ID)
|
| 86 |
+
|
| 87 |
+
# Gemini natively supports YouTube links passed directly in the prompt!
|
| 88 |
+
prompt = f"Watch this video carefully: {url}\n\nQuestion: {question}"
|
| 89 |
+
response = model.generate_content(prompt)
|
| 90 |
+
|
|
|
|
|
|
|
|
|
|
| 91 |
return response.text
|
| 92 |
except Exception as e:
|
| 93 |
return f"Error asking {MODEL_ID} about video: {str(e)}"
|