Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -312,6 +312,12 @@ def generate_story_endpoint():
|
|
| 312 |
"story_type": story_type
|
| 313 |
}
|
| 314 |
story_ref.set(story_record)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
|
| 316 |
preview = sections[0] if sections else {}
|
| 317 |
|
|
@@ -320,7 +326,8 @@ def generate_story_endpoint():
|
|
| 320 |
"full_story": full_story,
|
| 321 |
"preview": preview,
|
| 322 |
"sections": sections,
|
| 323 |
-
"generation_times": story_record["generation_times"]
|
|
|
|
| 324 |
})
|
| 325 |
|
| 326 |
except Exception as e:
|
|
@@ -392,6 +399,13 @@ def generate_video_endpoint():
|
|
| 392 |
# Optionally, update the story record with the video URL.
|
| 393 |
story_ref.update({"video_url": video_url})
|
| 394 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
# Clean up temporary local files.
|
| 396 |
for f in image_files:
|
| 397 |
os.remove(f)
|
|
@@ -399,7 +413,7 @@ def generate_video_endpoint():
|
|
| 399 |
os.remove(f)
|
| 400 |
os.remove(video_file)
|
| 401 |
|
| 402 |
-
return jsonify({"video_url": video_url})
|
| 403 |
except Exception as e:
|
| 404 |
return jsonify({'error': str(e)}), 500
|
| 405 |
|
|
|
|
| 312 |
"story_type": story_type
|
| 313 |
}
|
| 314 |
story_ref.set(story_record)
|
| 315 |
+
# --- Subtract 5 Credits from the User ---
|
| 316 |
+
user_ref = db.reference(f"users/{uid}")
|
| 317 |
+
user_data = user_ref.get() or {}
|
| 318 |
+
current_credits = user_data.get("credits", 0)
|
| 319 |
+
new_credits = max(0, current_credits - 5)
|
| 320 |
+
user_ref.update({"credits": new_credits})
|
| 321 |
|
| 322 |
preview = sections[0] if sections else {}
|
| 323 |
|
|
|
|
| 326 |
"full_story": full_story,
|
| 327 |
"preview": preview,
|
| 328 |
"sections": sections,
|
| 329 |
+
"generation_times": story_record["generation_times"],
|
| 330 |
+
"new_credits": new_credits
|
| 331 |
})
|
| 332 |
|
| 333 |
except Exception as e:
|
|
|
|
| 399 |
# Optionally, update the story record with the video URL.
|
| 400 |
story_ref.update({"video_url": video_url})
|
| 401 |
|
| 402 |
+
# --- Subtract 5 Credits from the User ---
|
| 403 |
+
user_ref = db.reference(f"users/{uid}")
|
| 404 |
+
user_data = user_ref.get() or {}
|
| 405 |
+
current_credits = user_data.get("credits", 0)
|
| 406 |
+
new_credits = max(0, current_credits - 5)
|
| 407 |
+
user_ref.update({"credits": new_credits})
|
| 408 |
+
|
| 409 |
# Clean up temporary local files.
|
| 410 |
for f in image_files:
|
| 411 |
os.remove(f)
|
|
|
|
| 413 |
os.remove(f)
|
| 414 |
os.remove(video_file)
|
| 415 |
|
| 416 |
+
return jsonify({"video_url": video_url,"new_credits": new_credits})
|
| 417 |
except Exception as e:
|
| 418 |
return jsonify({'error': str(e)}), 500
|
| 419 |
|