Update main.py
Browse files
main.py
CHANGED
|
@@ -47,13 +47,13 @@ try:
|
|
| 47 |
if not gemini_api_key: raise ValueError("The 'Gemini' environment variable for the API key is not set.")
|
| 48 |
|
| 49 |
# --- CORRECTED SDK PATTERN, AS PER OFFICIAL DOCUMENTATION ---
|
| 50 |
-
#
|
| 51 |
-
genai.
|
| 52 |
-
#
|
| 53 |
-
|
| 54 |
# --- END OF CORRECTION ---
|
| 55 |
|
| 56 |
-
logger.info("Google GenAI Client initialized successfully
|
| 57 |
|
| 58 |
ELEVENLABS_API_KEY = os.environ.get("ELEVENLABS_API_KEY")
|
| 59 |
if not ELEVENLABS_API_KEY: raise ValueError("The 'ELEVENLABS_API_KEY' environment variable is not set.")
|
|
@@ -115,7 +115,8 @@ def detect_use_case_with_gemini(text):
|
|
| 115 |
Text: "{text[:4000]}"
|
| 116 |
"""
|
| 117 |
try:
|
| 118 |
-
|
|
|
|
| 119 |
category = response.text.strip().replace("'", "").replace('"', '')
|
| 120 |
valid_categories = ['Job Interview', 'Investor Pitch', 'Academic Presentation']
|
| 121 |
if category in valid_categories:
|
|
@@ -168,7 +169,8 @@ def analyze_transcript_with_gemini(uid, project_id, transcript, duration_seconds
|
|
| 168 |
}}
|
| 169 |
Transcript to analyze: "{transcript}"
|
| 170 |
"""
|
| 171 |
-
|
|
|
|
| 172 |
feedback_json_text = response.text.strip().lstrip("```json").rstrip("```")
|
| 173 |
feedback_data = json.loads(feedback_json_text)
|
| 174 |
session_id = str(uuid.uuid4())
|
|
@@ -221,7 +223,8 @@ def generate_agent_briefing(uid, project_id):
|
|
| 221 |
- "The user struggles with concise communication. Ask multi-part questions to test their ability to stay on track."
|
| 222 |
Your directive for the agent:
|
| 223 |
"""
|
| 224 |
-
|
|
|
|
| 225 |
dynamic_directive = response.text.strip()
|
| 226 |
logger.info(f"Generated dynamic directive for agent: {dynamic_directive}")
|
| 227 |
return f"{base_briefing} {dynamic_directive}"
|
|
@@ -229,7 +232,6 @@ def generate_agent_briefing(uid, project_id):
|
|
| 229 |
logger.error(f"Could not generate dynamic briefing for project {project_id}: {e}")
|
| 230 |
return base_briefing
|
| 231 |
|
| 232 |
-
|
| 233 |
# -----------------------------------------------------------------------------
|
| 234 |
# 4. USER & AUTHENTICATION ENDPOINTS
|
| 235 |
# -----------------------------------------------------------------------------
|
|
|
|
| 47 |
if not gemini_api_key: raise ValueError("The 'Gemini' environment variable for the API key is not set.")
|
| 48 |
|
| 49 |
# --- CORRECTED SDK PATTERN, AS PER OFFICIAL DOCUMENTATION ---
|
| 50 |
+
# Instantiate the client object. This is the single, correct entry point.
|
| 51 |
+
client = genai.Client(api_key=gemini_api_key)
|
| 52 |
+
# Define the model name to be used in generation calls.
|
| 53 |
+
MODEL_NAME = 'models/gemini-2.0-flash'
|
| 54 |
# --- END OF CORRECTION ---
|
| 55 |
|
| 56 |
+
logger.info(f"Google GenAI Client initialized successfully for model {MODEL_NAME}.")
|
| 57 |
|
| 58 |
ELEVENLABS_API_KEY = os.environ.get("ELEVENLABS_API_KEY")
|
| 59 |
if not ELEVENLABS_API_KEY: raise ValueError("The 'ELEVENLABS_API_KEY' environment variable is not set.")
|
|
|
|
| 115 |
Text: "{text[:4000]}"
|
| 116 |
"""
|
| 117 |
try:
|
| 118 |
+
# CORRECTED: Use the client object and specify the model name.
|
| 119 |
+
response = client.generate_content(model=MODEL_NAME, contents=prompt)
|
| 120 |
category = response.text.strip().replace("'", "").replace('"', '')
|
| 121 |
valid_categories = ['Job Interview', 'Investor Pitch', 'Academic Presentation']
|
| 122 |
if category in valid_categories:
|
|
|
|
| 169 |
}}
|
| 170 |
Transcript to analyze: "{transcript}"
|
| 171 |
"""
|
| 172 |
+
# CORRECTED: Use the client object and specify the model name.
|
| 173 |
+
response = client.generate_content(model=MODEL_NAME, contents=prompt)
|
| 174 |
feedback_json_text = response.text.strip().lstrip("```json").rstrip("```")
|
| 175 |
feedback_data = json.loads(feedback_json_text)
|
| 176 |
session_id = str(uuid.uuid4())
|
|
|
|
| 223 |
- "The user struggles with concise communication. Ask multi-part questions to test their ability to stay on track."
|
| 224 |
Your directive for the agent:
|
| 225 |
"""
|
| 226 |
+
# CORRECTED: Use the client object and specify the model name.
|
| 227 |
+
response = client.generate_content(model=MODEL_NAME, contents=summary_prompt)
|
| 228 |
dynamic_directive = response.text.strip()
|
| 229 |
logger.info(f"Generated dynamic directive for agent: {dynamic_directive}")
|
| 230 |
return f"{base_briefing} {dynamic_directive}"
|
|
|
|
| 232 |
logger.error(f"Could not generate dynamic briefing for project {project_id}: {e}")
|
| 233 |
return base_briefing
|
| 234 |
|
|
|
|
| 235 |
# -----------------------------------------------------------------------------
|
| 236 |
# 4. USER & AUTHENTICATION ENDPOINTS
|
| 237 |
# -----------------------------------------------------------------------------
|