diwash-barla commited on
Commit
b8bb985
·
verified ·
1 Parent(s): 27329ae

Update engine.py

Browse files
Files changed (1) hide show
  1. engine.py +37 -7
engine.py CHANGED
@@ -1,5 +1,5 @@
1
  # ==============================================================================
2
- # engine.py - [FINAL PRO VERSION FOR HUGGING FACE]
3
  # FEATURE UPGRADE: Cinematic Zoom (Ken Burns), Random Transitions, High Quality Render
4
  # ==============================================================================
5
 
@@ -17,6 +17,13 @@ import re
17
  from gtts import gTTS
18
  from werkzeug.utils import secure_filename
19
 
 
 
 
 
 
 
 
20
  # ==============================================================================
21
  # 1. Global Setup and Database Functions
22
  # ==============================================================================
@@ -79,12 +86,21 @@ def update_task_final_status(task_id, status, error_message=None, output_filenam
79
  conn.close()
80
 
81
  def load_api_keys(prefix):
 
 
 
 
82
  try:
83
  prefix_lower = prefix.lower()
84
- keys = [v for k, v in os.environ.items() if k.lower().startswith(prefix_lower)]
85
- if not keys:
86
- print(f"🚨 चेतावनी: '{prefix}' से शुरू होने वाला कोई एनवायरनमेंट वेरिएबल नहीं मिला।")
87
- return keys
 
 
 
 
 
88
  except Exception as e:
89
  print(f"🚨 एनवायरनमेंट वेरिएबल्स लोड करते समय त्रुटि: {e}")
90
  return []
@@ -331,8 +347,22 @@ def run_ai_engine_worker(task_id, script_text, script_file_path, orientation, ma
331
 
332
  try:
333
  log("Step 0: API Keys की पुष्टि...", 2)
334
- gemini_keys, pexels_keys, pixabay_keys, groq_keys = load_api_keys("Gemini_Key"), load_api_keys("Pexels_Key"), load_api_keys("Pixabay_Key"), load_api_keys("Groq_Key")
335
- if not all([gemini_keys, pexels_keys, pixabay_keys, groq_keys]): raise Exception("API Key Error: Missing one or more required keys.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  gemini = GeminiTeam(api_keys=gemini_keys); log("-> सभी जरूरी API कीज मौजूद हैं।", 5)
337
 
338
  log("Step 1: स्क्रिप्ट तैयार की जा रही है...", 8)
 
1
  # ==============================================================================
2
+ # engine.py - [FINAL PRO VERSION FOR HUGGING FACE & LOCAL]
3
  # FEATURE UPGRADE: Cinematic Zoom (Ken Burns), Random Transitions, High Quality Render
4
  # ==============================================================================
5
 
 
17
  from gtts import gTTS
18
  from werkzeug.utils import secure_filename
19
 
20
+ # स्थानीय परीक्षण के लिए dotenv लोड करें (अगर उपलब्ध हो)
21
+ try:
22
+ from dotenv import load_dotenv
23
+ load_dotenv()
24
+ except ImportError:
25
+ pass
26
+
27
  # ==============================================================================
28
  # 1. Global Setup and Database Functions
29
  # ==============================================================================
 
86
  conn.close()
87
 
88
  def load_api_keys(prefix):
89
+ """
90
+ prefix (जैसे 'Gemini_Key') से शुरू होने वाली सभी environment variables को लोड करता है।
91
+ यह 'Gemini_Key_1', 'Gemini_Key_2' आदि को अपने आप पहचान लेगा।
92
+ """
93
  try:
94
  prefix_lower = prefix.lower()
95
+ # Environment variables को चेक करें (case-insensitive search)
96
+ keys = [v.strip() for k, v in os.environ.items() if k.lower().startswith(prefix_lower) and v.strip()]
97
+
98
+ if keys:
99
+ print(f"✅ API Key Check: '{prefix}' के लिए {len(keys)} कीज़ मिलीं (Example: ...{keys[0][-4:]})")
100
+ else:
101
+ print(f"❌ API Key Check: '{prefix}' के लिए कोई कीज़ नहीं मिलीं!")
102
+
103
+ return keys
104
  except Exception as e:
105
  print(f"🚨 एनवायरनमेंट वेरिएबल्स लोड करते समय त्रुटि: {e}")
106
  return []
 
347
 
348
  try:
349
  log("Step 0: API Keys की पुष्टि...", 2)
350
+ # कीज़ लोड करें
351
+ gemini_keys = load_api_keys("Gemini_Key")
352
+ pexels_keys = load_api_keys("Pexels_Key")
353
+ pixabay_keys = load_api_keys("Pixabay_Key")
354
+ groq_keys = load_api_keys("Groq_Key")
355
+
356
+ # अगर कोई की गायब है तो सटीक Error दें
357
+ missing = []
358
+ if not gemini_keys: missing.append("Gemini_Key")
359
+ if not pexels_keys: missing.append("Pexels_Key")
360
+ if not pixabay_keys: missing.append("Pixabay_Key")
361
+ if not groq_keys: missing.append("Groq_Key")
362
+
363
+ if missing:
364
+ raise Exception(f"API Key Error: ये कीज़ नहीं मिलीं: {', '.join(missing)}. कृपया सुनिश्चित करें कि आपने उन्हें 'Gemini_Key_1' या 'Gemini_Key' जैसे नामों से सेट किया है।")
365
+
366
  gemini = GeminiTeam(api_keys=gemini_keys); log("-> सभी जरूरी API कीज मौजूद हैं।", 5)
367
 
368
  log("Step 1: स्क्रिप्ट तैयार की जा रही है...", 8)