Kackle commited on
Commit
ca581c6
·
verified ·
1 Parent(s): d8e49a7

Update nova_agent.py

Browse files
Files changed (1) hide show
  1. nova_agent.py +30 -9
nova_agent.py CHANGED
@@ -2,7 +2,6 @@ import os
2
  import boto3
3
  import json
4
  from dotenv import load_dotenv
5
- from video_parser import VideoParser
6
  from excel_parser import ExcelParser
7
  import re
8
 
@@ -34,7 +33,6 @@ class NovaProAgent:
34
  self.accept = "application/json"
35
 
36
  # Initialize parsers
37
- self.video_parser = VideoParser()
38
  self.excel_parser = ExcelParser()
39
 
40
  async def __call__(self, question: str) -> str:
@@ -65,17 +63,40 @@ class NovaProAgent:
65
 
66
  url = youtube_url.group()
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  try:
69
- # Extract video metadata without downloading
70
- metadata = self.video_parser.get_youtube_metadata(url)
71
-
72
- if 'error' in metadata:
73
- return f"Video analysis failed: {metadata['error']}"
 
74
 
75
- return f"Video: {metadata['title']} | Duration: {metadata['duration']}s | Views: {metadata['view_count']:,}"
 
76
 
77
  except Exception as e:
78
- return f"Video analysis failed: {str(e)}"
79
 
80
  async def _handle_excel_question(self, question: str) -> str:
81
  """Handle questions that require Excel file analysis"""
 
2
  import boto3
3
  import json
4
  from dotenv import load_dotenv
 
5
  from excel_parser import ExcelParser
6
  import re
7
 
 
33
  self.accept = "application/json"
34
 
35
  # Initialize parsers
 
36
  self.excel_parser = ExcelParser()
37
 
38
  async def __call__(self, question: str) -> str:
 
63
 
64
  url = youtube_url.group()
65
 
66
+ # Extract video ID for reference
67
+ video_id = re.search(r'v=([\w-]+)', url).group(1)
68
+
69
+ # Use Nova Pro to provide intelligent response about video analysis
70
+ video_prompt = f"""User is asking about a YouTube video: {url}
71
+ Video ID: {video_id}
72
+ User question: {question}
73
+
74
+ Provide a helpful response about video analysis limitations and suggest alternatives."""
75
+
76
+ payload = {
77
+ "messages": [{
78
+ "role": "user",
79
+ "content": [{"text": video_prompt}]
80
+ }],
81
+ "inferenceConfig": {
82
+ "max_new_tokens": 150,
83
+ "temperature": 0.0
84
+ }
85
+ }
86
+
87
  try:
88
+ response = self.bedrock_client.invoke_model(
89
+ modelId=self.model_id,
90
+ contentType=self.content_type,
91
+ accept=self.accept,
92
+ body=json.dumps(payload)
93
+ )
94
 
95
+ response_body = json.loads(response['body'].read())
96
+ return response_body['output']['message']['content'][0]['text'].strip()
97
 
98
  except Exception as e:
99
+ return f"Video ID: {video_id}. Direct video analysis unavailable due to access restrictions."
100
 
101
  async def _handle_excel_question(self, question: str) -> str:
102
  """Handle questions that require Excel file analysis"""