Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,23 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
-
import subprocess
|
4 |
-
from tempfile import NamedTemporaryFile
|
5 |
|
6 |
-
#
|
7 |
-
UPLOAD_DIR = '
|
8 |
-
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
return file_path
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
try:
|
20 |
-
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
21 |
-
return result.stdout + '\n' + result.stderr
|
22 |
-
except Exception as e:
|
23 |
-
return str(e)
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
st.
|
30 |
-
uploaded_file = st.file_uploader('Choose a file', type=['mp3', 'wav', 'mp4', 'avi'])
|
31 |
-
if uploaded_file:
|
32 |
-
file_path = save_uploaded_file(uploaded_file)
|
33 |
-
st.write(f'File saved to: {file_path}')
|
34 |
-
|
35 |
-
# Display uploaded file in audio or video player
|
36 |
-
file_type = uploaded_file.type
|
37 |
-
if file_type.startswith('audio/'):
|
38 |
-
st.audio(uploaded_file, format=file_type)
|
39 |
-
elif file_type.startswith('video/'):
|
40 |
-
st.video(uploaded_file, format=file_type)
|
41 |
-
|
42 |
-
# Command input
|
43 |
-
st.header('Command Input')
|
44 |
-
command = st.text_area('Enter FFmpeg commands here...')
|
45 |
-
if st.button('Execute Command'):
|
46 |
-
if command:
|
47 |
-
output = run_ffmpeg_command(command)
|
48 |
-
st.text_area('Logs', value=output, height=300)
|
49 |
-
else:
|
50 |
-
st.warning('Please enter a command.')
|
51 |
|
52 |
-
|
53 |
-
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
|
|
|
|
3 |
|
4 |
+
# Define a writable directory inside the app environment
|
5 |
+
UPLOAD_DIR = './uploads' # Adjust to a directory where you have write permissions
|
|
|
6 |
|
7 |
+
# Create the directory if it doesn't exist
|
8 |
+
if not os.path.exists(UPLOAD_DIR):
|
9 |
+
os.makedirs(UPLOAD_DIR)
|
10 |
+
|
11 |
+
st.title('Upload and Process Files')
|
|
|
12 |
|
13 |
+
# File uploader
|
14 |
+
uploaded_file = st.file_uploader("Choose a file")
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
if uploaded_file is not None:
|
17 |
+
# Save the uploaded file
|
18 |
+
with open(os.path.join(UPLOAD_DIR, uploaded_file.name), 'wb') as f:
|
19 |
+
f.write(uploaded_file.getbuffer())
|
20 |
+
st.success('File uploaded successfully!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
# Optionally, you can add more code to process the file
|
23 |
+
# e.g., use ffmpeg, display the file, etc.
|