ishworrsubedii commited on
Commit
7f50b11
·
1 Parent(s): a11a289

fix: add model name as suffix for video gen output

Browse files
Files changed (1) hide show
  1. app.py +37 -6
app.py CHANGED
@@ -3,6 +3,7 @@ import os
3
  import tempfile
4
  import time
5
  from dataclasses import dataclass
 
6
  from typing import List
7
 
8
  import requests
@@ -39,35 +40,56 @@ os.environ['MOVIEPY_TEMP_DIR'] = '/tmp/moviepy'
39
 
40
 
41
  def upload_to_supabase(video_path, bucket_name="JewelmirrorVideoGeneration", model_name="MOD"):
 
 
 
 
42
  logger.info(f"Uploading video to Supabase: {video_path}")
43
 
44
  try:
 
45
  if not os.path.exists(video_path):
46
  raise FileNotFoundError(f"Video file not found: {video_path}")
47
 
48
- content_type = mimetypes.guess_type(video_path)[0] or 'video/mp4'
49
- file_name = f"{os.path.basename(video_path)}-{model_name}"
 
 
 
 
 
 
 
 
50
 
 
 
 
 
 
51
  options = {
52
  "content-type": content_type,
53
  "x-upsert": "true",
54
  "cache-control": "max-age=3600"
55
  }
56
- logger.info(f"Uploading video to Supabase: {video_path}")
57
 
 
 
 
58
  with open(video_path, 'rb') as f:
59
  file_data = f.read()
60
 
 
61
  supabase.storage.from_(bucket_name).upload(
62
- path=file_name,
63
  file=file_data,
64
  file_options=options
65
  )
66
 
67
- public_url = supabase.storage.from_(bucket_name).get_public_url(file_name)
68
 
 
69
  response = requests.head(public_url)
70
-
71
  if response.status_code != 200:
72
  logger.error(f"Upload verification failed: {response.status_code}")
73
  raise Exception(f"Upload verification failed: {response.status_code}")
@@ -80,6 +102,15 @@ def upload_to_supabase(video_path, bucket_name="JewelmirrorVideoGeneration", mod
80
  return None
81
 
82
 
 
 
 
 
 
 
 
 
 
83
  def download_image(url):
84
  logger.info(f"Downloading image from {url}")
85
  try:
 
3
  import tempfile
4
  import time
5
  from dataclasses import dataclass
6
+ from datetime import datetime
7
  from typing import List
8
 
9
  import requests
 
40
 
41
 
42
  def upload_to_supabase(video_path, bucket_name="JewelmirrorVideoGeneration", model_name="MOD"):
43
+ """
44
+ Upload video to Supabase with organized folder structure.
45
+ Format: {bucket_name}/{year}/{month}/{day}/{model_name}/{video_filename}
46
+ """
47
  logger.info(f"Uploading video to Supabase: {video_path}")
48
 
49
  try:
50
+ # Check if file exists
51
  if not os.path.exists(video_path):
52
  raise FileNotFoundError(f"Video file not found: {video_path}")
53
 
54
+ # Get current date for folder structure
55
+ current_date = datetime.now()
56
+ year = current_date.strftime("%Y")
57
+ month = current_date.strftime("%m")
58
+ day = current_date.strftime("%d")
59
+
60
+ unique_id = os.urandom(8).hex()
61
+
62
+ original_filename = os.path.basename(video_path)
63
+ filename, ext = os.path.splitext(original_filename)
64
 
65
+ structured_filename = f"{filename}_{unique_id}{ext}"
66
+
67
+ structured_path = f"{year}/{month}/{day}/{model_name}/{structured_filename}"
68
+
69
+ content_type = mimetypes.guess_type(video_path)[0] or 'video/mp4'
70
  options = {
71
  "content-type": content_type,
72
  "x-upsert": "true",
73
  "cache-control": "max-age=3600"
74
  }
 
75
 
76
+ logger.info(f"Uploading video with structured path: {structured_path}")
77
+
78
+ # Read and upload file
79
  with open(video_path, 'rb') as f:
80
  file_data = f.read()
81
 
82
+ # Upload to Supabase
83
  supabase.storage.from_(bucket_name).upload(
84
+ path=structured_path,
85
  file=file_data,
86
  file_options=options
87
  )
88
 
89
+ public_url = supabase.storage.from_(bucket_name).get_public_url(structured_path)
90
 
91
+ # Verify upload
92
  response = requests.head(public_url)
 
93
  if response.status_code != 200:
94
  logger.error(f"Upload verification failed: {response.status_code}")
95
  raise Exception(f"Upload verification failed: {response.status_code}")
 
102
  return None
103
 
104
 
105
+ def get_structured_path(video_path, model_name="MOD"):
106
+ current_date = datetime.now()
107
+ unique_id = os.urandom(8).hex()
108
+ filename = os.path.basename(video_path)
109
+ name, ext = os.path.splitext(filename)
110
+
111
+ return f"{current_date.strftime('%Y')}/{current_date.strftime('%m')}/{current_date.strftime('%d')}/{model_name}/{name}_{unique_id}{ext}"
112
+
113
+
114
  def download_image(url):
115
  logger.info(f"Downloading image from {url}")
116
  try: