Spaces:
Sleeping
Sleeping
remove placeholders
Browse files- nova_agent.py +36 -10
nova_agent.py
CHANGED
|
@@ -65,20 +65,46 @@ class NovaProAgent:
|
|
| 65 |
|
| 66 |
url = youtube_url.group()
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
async def _handle_excel_question(self, question: str) -> str:
|
| 73 |
"""Handle questions that require Excel file analysis"""
|
| 74 |
-
#
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
async def _handle_text_question(self, question: str) -> str:
|
| 84 |
"""Handle regular text-based questions"""
|
|
|
|
| 65 |
|
| 66 |
url = youtube_url.group()
|
| 67 |
|
| 68 |
+
try:
|
| 69 |
+
# Download video using VideoParser
|
| 70 |
+
video_path = self.video_parser.download_youtube_video(url)
|
| 71 |
+
|
| 72 |
+
# Extract frames for analysis
|
| 73 |
+
frames = self.video_parser.analyze_video_frames(video_path, sample_rate=60)
|
| 74 |
+
|
| 75 |
+
# Clean up
|
| 76 |
+
self.video_parser.cleanup()
|
| 77 |
+
|
| 78 |
+
return f"Analyzed {len(frames)} frames from video. Video processing complete."
|
| 79 |
+
|
| 80 |
+
except Exception as e:
|
| 81 |
+
return f"Video analysis failed: {str(e)}"
|
| 82 |
|
| 83 |
async def _handle_excel_question(self, question: str) -> str:
|
| 84 |
"""Handle questions that require Excel file analysis"""
|
| 85 |
+
# Extract file path from question if present
|
| 86 |
+
file_patterns = [r'([A-Za-z]:\\[^\s]+\.xlsx?)', r'([^\s]+\.xlsx?)']
|
| 87 |
+
file_path = None
|
| 88 |
+
|
| 89 |
+
for pattern in file_patterns:
|
| 90 |
+
match = re.search(pattern, question)
|
| 91 |
+
if match:
|
| 92 |
+
file_path = match.group(1)
|
| 93 |
+
break
|
| 94 |
+
|
| 95 |
+
if not file_path:
|
| 96 |
+
return "Please provide Excel file path in your question."
|
| 97 |
|
| 98 |
+
try:
|
| 99 |
+
if 'sales' in question.lower() and 'food' in question.lower():
|
| 100 |
+
results = self.excel_parser.analyze_sales_data(file_path)
|
| 101 |
+
return results.get('total_food_sales', 'No sales data found')
|
| 102 |
+
else:
|
| 103 |
+
df = self.excel_parser.read_excel_file(file_path)
|
| 104 |
+
return f"Excel file loaded with {len(df)} rows and {len(df.columns)} columns."
|
| 105 |
+
|
| 106 |
+
except Exception as e:
|
| 107 |
+
return f"Excel analysis failed: {str(e)}"
|
| 108 |
|
| 109 |
async def _handle_text_question(self, question: str) -> str:
|
| 110 |
"""Handle regular text-based questions"""
|