Update app.py
Browse files
app.py
CHANGED
|
@@ -108,8 +108,15 @@ st.markdown("""
|
|
| 108 |
</style>
|
| 109 |
""", unsafe_allow_html=True)
|
| 110 |
|
|
|
|
|
|
|
|
|
|
| 111 |
def save_uploaded_file(uploaded_file):
|
| 112 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
save_path = Path("uploaded_videos")
|
| 114 |
save_path.mkdir(exist_ok=True)
|
| 115 |
file_path = save_path / uploaded_file.name
|
|
@@ -145,15 +152,18 @@ def get_uploaded_videos():
|
|
| 145 |
return [f for f in video_dir.glob("*") if f.suffix.lower() in ['.mp4', '.mkv', '.avi', '.mov', '.mpeg4']]
|
| 146 |
|
| 147 |
def generate_thumbnail(video_path):
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
| 157 |
return None
|
| 158 |
|
| 159 |
def main():
|
|
@@ -168,16 +178,24 @@ def main():
|
|
| 168 |
<h3>Drag and drop your video here</h3>
|
| 169 |
<p>or click to select files</p>
|
| 170 |
<p>Supported formats: MP4, MKV, AVI, MOV, MPEG4</p>
|
| 171 |
-
<p>
|
| 172 |
</div>
|
| 173 |
""", unsafe_allow_html=True)
|
| 174 |
|
| 175 |
if uploaded_file is not None:
|
| 176 |
upload_placeholder.empty()
|
| 177 |
st.write(f"Uploading: {uploaded_file.name}")
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
st.write(file_details)
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
| 181 |
st.success(f"File {uploaded_file.name} successfully uploaded!")
|
| 182 |
else:
|
| 183 |
st.error("Failed to upload file.")
|
|
|
|
| 108 |
</style>
|
| 109 |
""", unsafe_allow_html=True)
|
| 110 |
|
| 111 |
+
# Constants
|
| 112 |
+
MAX_FILE_SIZE = 10 * 1024 * 1024 * 1024 # 10GB in bytes
|
| 113 |
+
|
| 114 |
def save_uploaded_file(uploaded_file):
|
| 115 |
try:
|
| 116 |
+
if uploaded_file.size > MAX_FILE_SIZE:
|
| 117 |
+
st.error(f"File size exceeds the 10GB limit. Please upload a smaller file.")
|
| 118 |
+
return False
|
| 119 |
+
|
| 120 |
save_path = Path("uploaded_videos")
|
| 121 |
save_path.mkdir(exist_ok=True)
|
| 122 |
file_path = save_path / uploaded_file.name
|
|
|
|
| 152 |
return [f for f in video_dir.glob("*") if f.suffix.lower() in ['.mp4', '.mkv', '.avi', '.mov', '.mpeg4']]
|
| 153 |
|
| 154 |
def generate_thumbnail(video_path):
|
| 155 |
+
try:
|
| 156 |
+
video = cv2.VideoCapture(str(video_path))
|
| 157 |
+
success, image = video.read()
|
| 158 |
+
if success:
|
| 159 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 160 |
+
image = Image.fromarray(image)
|
| 161 |
+
image.thumbnail((300, 168))
|
| 162 |
+
buffered = io.BytesIO()
|
| 163 |
+
image.save(buffered, format="PNG")
|
| 164 |
+
return base64.b64encode(buffered.getvalue()).decode()
|
| 165 |
+
except Exception as e:
|
| 166 |
+
st.warning(f"Could not generate thumbnail for {video_path.name}: {str(e)}")
|
| 167 |
return None
|
| 168 |
|
| 169 |
def main():
|
|
|
|
| 178 |
<h3>Drag and drop your video here</h3>
|
| 179 |
<p>or click to select files</p>
|
| 180 |
<p>Supported formats: MP4, MKV, AVI, MOV, MPEG4</p>
|
| 181 |
+
<p>Maximum file size: 10GB</p>
|
| 182 |
</div>
|
| 183 |
""", unsafe_allow_html=True)
|
| 184 |
|
| 185 |
if uploaded_file is not None:
|
| 186 |
upload_placeholder.empty()
|
| 187 |
st.write(f"Uploading: {uploaded_file.name}")
|
| 188 |
+
file_size_mb = uploaded_file.size / (1024 * 1024)
|
| 189 |
+
file_details = {
|
| 190 |
+
"FileName": uploaded_file.name,
|
| 191 |
+
"FileType": uploaded_file.type,
|
| 192 |
+
"FileSize": f"{file_size_mb:.2f} MB"
|
| 193 |
+
}
|
| 194 |
st.write(file_details)
|
| 195 |
+
|
| 196 |
+
if file_size_mb > 10 * 1024: # If file size is greater than 10GB
|
| 197 |
+
st.error("File size exceeds the 10GB limit. Please upload a smaller file.")
|
| 198 |
+
elif save_uploaded_file(uploaded_file):
|
| 199 |
st.success(f"File {uploaded_file.name} successfully uploaded!")
|
| 200 |
else:
|
| 201 |
st.error("Failed to upload file.")
|