RandomPersonRR commited on
Commit
4cf9976
·
verified ·
1 Parent(s): f4f184a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -46
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
- # Paths
7
- UPLOAD_DIR = '/content/uploads'
8
- os.makedirs(UPLOAD_DIR, exist_ok=True)
9
 
10
- def save_uploaded_file(uploaded_file):
11
- """Save the uploaded file to the designated directory."""
12
- file_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
13
- with open(file_path, 'wb') as f:
14
- f.write(uploaded_file.getbuffer())
15
- return file_path
16
 
17
- def run_ffmpeg_command(command):
18
- """Execute the FFmpeg command and return the output."""
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
- def main():
26
- st.title('FFmpeg Web Interface')
27
-
28
- # File upload
29
- st.header('Upload File')
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
- if __name__ == '__main__':
53
- main()
 
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.