RandomPersonRR commited on
Commit
8df4907
·
verified ·
1 Parent(s): 02168c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -7
app.py CHANGED
@@ -1,23 +1,40 @@
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.
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import os
3
+ import subprocess
4
 
5
+ # Define directories for uploads and processed files
6
+ UPLOAD_DIR = 'uploads'
7
+ PROCESSED_DIR = 'processed'
8
 
9
+ # Create the directories if they don't exist
10
  if not os.path.exists(UPLOAD_DIR):
11
  os.makedirs(UPLOAD_DIR)
12
+ if not os.path.exists(PROCESSED_DIR):
13
+ os.makedirs(PROCESSED_DIR)
14
 
15
+ st.title('FFmpeg Command Executor')
16
 
17
  # File uploader
18
  uploaded_file = st.file_uploader("Choose a file")
19
 
20
  if uploaded_file is not None:
21
  # Save the uploaded file
22
+ file_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
23
+ with open(file_path, 'wb') as f:
24
  f.write(uploaded_file.getbuffer())
25
  st.success('File uploaded successfully!')
26
 
27
+ # Input for ffmpeg command
28
+ command = st.text_area('Enter FFmpeg command', value=f'ffmpeg -i {file_path} -vf scale=1280:720 {os.path.join(PROCESSED_DIR, "output.mp4")}')
29
+
30
+ if st.button('Run Command'):
31
+ # Execute the FFmpeg command
32
+ try:
33
+ subprocess.run(command, shell=True, check=True)
34
+ st.success('Command executed successfully!')
35
+
36
+ # Display the processed video
37
+ output_file_path = os.path.join(PROCESSED_DIR, 'output.mp4')
38
+ st.video(output_file_path) # Display video in Streamlit
39
+ except subprocess.CalledProcessError as e:
40
+ st.error(f'Error executing command: {e}')