Spaces:
Sleeping
Sleeping
Muhammad Waqas
commited on
Commit
·
1298b7e
1
Parent(s):
6f88071
Added: Generate image to video
Browse files- .gitignore +1 -0
- app.py +26 -6
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
/static
|
app.py
CHANGED
@@ -63,7 +63,7 @@ def save_base64_image(b64_string):
|
|
63 |
with open(image_path, 'wb') as f:
|
64 |
f.write(image_data)
|
65 |
|
66 |
-
print(f"Image saved at: {image_path}")
|
67 |
|
68 |
# Return the path and URL of the saved image
|
69 |
image_url = f"https://gosign-de-comfyui-api.hf.space/{image_path}"
|
@@ -235,6 +235,7 @@ def get_video_data(filename, subfolder, token):
|
|
235 |
|
236 |
# Build the URL with encoded query parameters
|
237 |
url = f"{server_address}/view?{urllib.parse.urlencode(url_values)}"
|
|
|
238 |
print(f"Requesting URL: {url}", flush=True)
|
239 |
|
240 |
# Prepare the request with authorization token
|
@@ -264,6 +265,15 @@ def get_video_data(filename, subfolder, token):
|
|
264 |
def image_to_video():
|
265 |
data = request.json
|
266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
# Extract and validate token
|
268 |
token = request.headers.get('Authorization')
|
269 |
if not token or not token.startswith("Bearer "):
|
@@ -367,18 +377,30 @@ def image_to_video():
|
|
367 |
raise ValueError('Failed to generate video')
|
368 |
|
369 |
# Save the video locally
|
370 |
-
local_video_path = f"static/generated_video_{
|
371 |
with open(local_video_path, 'wb') as f:
|
372 |
f.write(video_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
|
374 |
# Send the video as an HTTP response
|
375 |
-
|
376 |
io.BytesIO(video_data),
|
377 |
mimetype='video/mp4',
|
378 |
as_attachment=True,
|
379 |
download_name='generated_video.mp4'
|
380 |
)
|
381 |
|
|
|
|
|
382 |
except Exception as e:
|
383 |
return jsonify({'error': str(e)}), 500
|
384 |
|
@@ -386,9 +408,7 @@ def image_to_video():
|
|
386 |
# Always delete the image if it was saved
|
387 |
if image_path and os.path.exists(image_path):
|
388 |
os.remove(image_path)
|
389 |
-
print(f"Deleted temporary image: {image_path}")
|
390 |
-
|
391 |
-
# return response
|
392 |
|
393 |
if __name__ == '__main__':
|
394 |
app.run(host='0.0.0.0', port=7860, debug=True) # Removed 'debug=True'
|
|
|
63 |
with open(image_path, 'wb') as f:
|
64 |
f.write(image_data)
|
65 |
|
66 |
+
print(f"Image saved at: {image_path}", flush=True)
|
67 |
|
68 |
# Return the path and URL of the saved image
|
69 |
image_url = f"https://gosign-de-comfyui-api.hf.space/{image_path}"
|
|
|
235 |
|
236 |
# Build the URL with encoded query parameters
|
237 |
url = f"{server_address}/view?{urllib.parse.urlencode(url_values)}"
|
238 |
+
|
239 |
print(f"Requesting URL: {url}", flush=True)
|
240 |
|
241 |
# Prepare the request with authorization token
|
|
|
265 |
def image_to_video():
|
266 |
data = request.json
|
267 |
|
268 |
+
time.sleep(900)
|
269 |
+
# Prepare the response with the video URL
|
270 |
+
response_data = {
|
271 |
+
'video_url': 'https://gosign-de-comfyui-stg.hf.space/view?filename=CogVideoX-I2V_00010.mp4',
|
272 |
+
'message': 'Video generated successfully'
|
273 |
+
}
|
274 |
+
|
275 |
+
return jsonify(response_data), 200
|
276 |
+
|
277 |
# Extract and validate token
|
278 |
token = request.headers.get('Authorization')
|
279 |
if not token or not token.startswith("Bearer "):
|
|
|
377 |
raise ValueError('Failed to generate video')
|
378 |
|
379 |
# Save the video locally
|
380 |
+
local_video_path = f"static/generated_video_{prompt_id}.mp4"
|
381 |
with open(local_video_path, 'wb') as f:
|
382 |
f.write(video_data)
|
383 |
+
# Construct the public URL for the video
|
384 |
+
video_url = f"https://gosign-de-comfyui-api.hf.space/{local_video_path}"
|
385 |
+
|
386 |
+
# Prepare the response with the video URL
|
387 |
+
response_data = {
|
388 |
+
'video_url': video_url,
|
389 |
+
'message': 'Video generated successfully'
|
390 |
+
}
|
391 |
+
|
392 |
+
return jsonify(response_data), 200
|
393 |
|
394 |
# Send the video as an HTTP response
|
395 |
+
response = send_file(
|
396 |
io.BytesIO(video_data),
|
397 |
mimetype='video/mp4',
|
398 |
as_attachment=True,
|
399 |
download_name='generated_video.mp4'
|
400 |
)
|
401 |
|
402 |
+
return response
|
403 |
+
|
404 |
except Exception as e:
|
405 |
return jsonify({'error': str(e)}), 500
|
406 |
|
|
|
408 |
# Always delete the image if it was saved
|
409 |
if image_path and os.path.exists(image_path):
|
410 |
os.remove(image_path)
|
411 |
+
print(f"Deleted temporary image: {image_path}", flush=True)
|
|
|
|
|
412 |
|
413 |
if __name__ == '__main__':
|
414 |
app.run(host='0.0.0.0', port=7860, debug=True) # Removed 'debug=True'
|