Spaces:
Sleeping
Sleeping
Merge remote changes and resolve conflicts in agent.py
Browse files
agent.py
CHANGED
|
@@ -93,13 +93,15 @@ def analyze_only(path_a, path_c, job_id=None):
|
|
| 93 |
|
| 94 |
|
| 95 |
def generate_only(prompt, path_a, path_c, job_id, style, audio, neg, guidance, motion):
|
| 96 |
-
update_job_status(job_id, "generating", 50, "Production started...")
|
| 97 |
-
full_prompt = f"{style} style. {prompt} Soundtrack: {audio}"
|
| 98 |
-
|
| 99 |
-
job_failed = False
|
| 100 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
if not Settings.GCP_PROJECT_ID:
|
| 102 |
raise Exception("GCP_PROJECT_ID missing.")
|
|
|
|
| 103 |
client = genai.Client(vertexai=True, project=Settings.GCP_PROJECT_ID, location=Settings.GCP_LOCATION)
|
| 104 |
|
| 105 |
# 1. Start Job
|
|
@@ -113,9 +115,7 @@ def generate_only(prompt, path_a, path_c, job_id, style, audio, neg, guidance, m
|
|
| 113 |
op_name = op.name if hasattr(op, 'name') else str(op)
|
| 114 |
logger.info(f"Polling Job ID: {op_name}")
|
| 115 |
|
| 116 |
-
# 3. Create Valid SDK Object for Polling
|
| 117 |
-
# We initialize the object ONLY with the name.
|
| 118 |
-
# The Pydantic model will accept this, and the SDK will use it for the API call.
|
| 119 |
polling_op = types.GenerateVideosOperation(name=op_name)
|
| 120 |
|
| 121 |
start_time = time.time()
|
|
@@ -164,14 +164,20 @@ def generate_only(prompt, path_a, path_c, job_id, style, audio, neg, guidance, m
|
|
| 164 |
raise Exception("No video output.")
|
| 165 |
|
| 166 |
except Exception as e:
|
| 167 |
-
logger.error(f"
|
| 168 |
-
update_job_status(job_id, "error", 0,
|
| 169 |
-
|
| 170 |
finally:
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
|
| 95 |
def generate_only(prompt, path_a, path_c, job_id, style, audio, neg, guidance, motion):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
try:
|
| 97 |
+
update_job_status(job_id, "generating", 50, "Production started (Veo 3.1)...")
|
| 98 |
+
full_prompt = f"{style} style. {prompt} Soundtrack: {audio}"
|
| 99 |
+
if neg:
|
| 100 |
+
full_prompt += f" --no {neg}"
|
| 101 |
+
|
| 102 |
if not Settings.GCP_PROJECT_ID:
|
| 103 |
raise Exception("GCP_PROJECT_ID missing.")
|
| 104 |
+
|
| 105 |
client = genai.Client(vertexai=True, project=Settings.GCP_PROJECT_ID, location=Settings.GCP_LOCATION)
|
| 106 |
|
| 107 |
# 1. Start Job
|
|
|
|
| 115 |
op_name = op.name if hasattr(op, 'name') else str(op)
|
| 116 |
logger.info(f"Polling Job ID: {op_name}")
|
| 117 |
|
| 118 |
+
# 3. Create Valid SDK Object for Polling
|
|
|
|
|
|
|
| 119 |
polling_op = types.GenerateVideosOperation(name=op_name)
|
| 120 |
|
| 121 |
start_time = time.time()
|
|
|
|
| 164 |
raise Exception("No video output.")
|
| 165 |
|
| 166 |
except Exception as e:
|
| 167 |
+
logger.error(f"Worker crashed: {e}")
|
| 168 |
+
update_job_status(job_id, "error", 0, f"Error: {e}")
|
| 169 |
+
|
| 170 |
finally:
|
| 171 |
+
# Enforce Terminal State
|
| 172 |
+
try:
|
| 173 |
+
status_file = f"outputs/{job_id}.json"
|
| 174 |
+
if os.path.exists(status_file):
|
| 175 |
+
with open(status_file, "r") as f:
|
| 176 |
+
data = json.load(f)
|
| 177 |
+
|
| 178 |
+
status = data.get("status")
|
| 179 |
+
if status not in ["completed", "error"]:
|
| 180 |
+
logger.warning(f"Job {job_id} left in non-terminal state ({status}). Forcing error.")
|
| 181 |
+
update_job_status(job_id, "error", 0, "Job terminated unexpectedly.")
|
| 182 |
+
except Exception as e:
|
| 183 |
+
logger.error(f"Final safety net failed: {e}")
|