diwash-barla commited on
Commit
3d5a737
·
verified ·
1 Parent(s): f42e652

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -6
app.py CHANGED
@@ -122,19 +122,39 @@ def generate_visual_blueprint_with_groq(user_prompt, api_key, model_name):
122
 
123
  def generate_clip(prompt, idx, api_key, bytez_model):
124
  from bytez import Bytez
125
- sdk = Bytez(api_key); model = sdk.model(bytez_model)
126
- out, err = model.run(prompt)
127
- if err: return None, f"Model Error (Key ...{api_key[-4:]}): {err}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  filename = f"clip_{idx}_{uuid.uuid4().hex}.mp4"
129
  filepath = os.path.join(OUTPUT_FOLDER, filename)
130
  try:
131
  if isinstance(out, bytes):
132
  with open(filepath, "wb") as f: f.write(out)
133
  elif isinstance(out, str) and out.startswith('http'):
134
- r = requests.get(out, timeout=300); r.raise_for_status()
 
135
  with open(filepath, "wb") as f: f.write(r.content)
136
- else: return None, f"Unexpected output type: {type(out)}"
137
- except Exception as e: return None, f"Failed to save/download clip: {e}"
 
 
 
138
  return filepath, None
139
 
140
  def process_and_merge_clips(clip_files):
 
122
 
123
  def generate_clip(prompt, idx, api_key, bytez_model):
124
  from bytez import Bytez
125
+ sdk = Bytez(api_key)
126
+ model = sdk.model(bytez_model)
127
+
128
+ # --- MODIFIED SECTION TO FIX THE CRASH ---
129
+ try:
130
+ # हम उम्मीद करते हैं कि सफलता पर model.run() केवल एक आउटपुट देगा।
131
+ out = model.run(prompt)
132
+ err = None # यदि यह लाइन चलती है, तो कोई एरर नहीं है।
133
+ except Exception as e:
134
+ # यदि model.run() के दौरान कोई भी एरर आता है, तो हम उसे यहां पकड़ लेंगे।
135
+ print(f"🛑 Error during model.run() with key ...{api_key[-4:]}: {e}")
136
+ out = None
137
+ err = str(e) # एरर संदेश को सहेजें।
138
+ # --- END OF MODIFIED SECTION ---
139
+
140
+ if err:
141
+ # यदि कोई एरर था, तो यहां से बाहर निकल जाएं।
142
+ return None, f"Model Error (Key ...{api_key[-4:]}): {err}"
143
+
144
  filename = f"clip_{idx}_{uuid.uuid4().hex}.mp4"
145
  filepath = os.path.join(OUTPUT_FOLDER, filename)
146
  try:
147
  if isinstance(out, bytes):
148
  with open(filepath, "wb") as f: f.write(out)
149
  elif isinstance(out, str) and out.startswith('http'):
150
+ r = requests.get(out, timeout=300)
151
+ r.raise_for_status()
152
  with open(filepath, "wb") as f: f.write(r.content)
153
+ else:
154
+ return None, f"Unexpected output type from model: {type(out)}"
155
+ except Exception as e:
156
+ return None, f"Failed to save or download the generated clip: {e}"
157
+
158
  return filepath, None
159
 
160
  def process_and_merge_clips(clip_files):