Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -96,6 +96,8 @@ def cached_search(query):
|
|
| 96 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 97 |
|
| 98 |
|
|
|
|
|
|
|
| 99 |
class BasicAgent:
|
| 100 |
|
| 101 |
|
|
@@ -155,10 +157,25 @@ class BasicAgent:
|
|
| 155 |
traceback.print_exc()
|
| 156 |
return f"I apologize, but I encountered an error while processing your question. Error: {str(e)}"
|
| 157 |
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
def process_question(self, question: str) -> str:
|
| 161 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
# Check if this is a request about a YouTube video
|
| 163 |
youtube_patterns = ["youtube.com", "youtu.be", "watch youtube", "youtube video"]
|
| 164 |
use_youtube_tool = any(pattern in question.lower() for pattern in youtube_patterns)
|
|
|
|
| 96 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 97 |
|
| 98 |
|
| 99 |
+
|
| 100 |
+
|
| 101 |
class BasicAgent:
|
| 102 |
|
| 103 |
|
|
|
|
| 157 |
traceback.print_exc()
|
| 158 |
return f"I apologize, but I encountered an error while processing your question. Error: {str(e)}"
|
| 159 |
|
| 160 |
+
def _process_image_query(self, question, image_url):
|
| 161 |
+
try:
|
| 162 |
+
response = requests.get(image_url)
|
| 163 |
+
image_data = response.content
|
| 164 |
+
multimodal_prompt = [{"text": question}, {"image": {"data": image_data}}]
|
| 165 |
+
response = self.gemini_model.generate_content(multimodal_prompt)
|
| 166 |
+
return response.text
|
| 167 |
+
except Exception as e:
|
| 168 |
+
print(f"Error processing image: {str(e)}")
|
| 169 |
+
return f"I encountered an error analyzing the image: {str(e)}"
|
| 170 |
|
| 171 |
def process_question(self, question: str) -> str:
|
| 172 |
try:
|
| 173 |
+
# Processing image
|
| 174 |
+
image_url_match = re.search(r'https?://\S+\.(jpg|jpeg|png|gif|webp)', question, re.IGNORECASE)
|
| 175 |
+
if image_url_match and self.gemini_model:
|
| 176 |
+
image_url = image_url_match.group(0)
|
| 177 |
+
return self._process_image_query(question, image_url)
|
| 178 |
+
|
| 179 |
# Check if this is a request about a YouTube video
|
| 180 |
youtube_patterns = ["youtube.com", "youtu.be", "watch youtube", "youtube video"]
|
| 181 |
use_youtube_tool = any(pattern in question.lower() for pattern in youtube_patterns)
|