Adityadn commited on
Commit
af2de0d
·
verified ·
1 Parent(s): 18a0f73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -44
app.py CHANGED
@@ -88,51 +88,60 @@ def main():
88
  st.title("Video Conversion Tool")
89
  st.write("Convert videos to audio, GIFs, images, or other formats easily with this powerful tool.")
90
 
91
- # Upload video file
92
- video_file = st.file_uploader("Upload a Video", type=supported_formats)
93
-
94
- if video_file:
95
- st.video(video_file)
96
-
97
- # Create a temporary file and save uploaded video
98
- temp_video_path = os.path.join(tempfile.mkdtemp(), video_file.name)
99
- with open(temp_video_path, "wb") as f:
100
- f.write(video_file.getbuffer())
101
-
102
- # Get video duration
103
- video_duration = get_video_duration(temp_video_path)
104
-
105
- # Select conversion type
106
- conversion_type = st.selectbox(
107
- "Select Conversion Type",
108
- ['Video to Video', 'Video to Audio', 'Video to GIF', 'Video to Image']
109
- )
110
-
111
- # Update format choices based on conversion type
112
- target_format_choices = update_format_choices(conversion_type)
113
- target_format = st.selectbox("Select Target Format", target_format_choices)
114
-
115
- # If 'Video to Image' conversion, ask for time in seconds
116
- if conversion_type == 'Video to Image':
117
- time_in_seconds = st.slider(
118
- label="Time (in seconds) for image extraction",
119
- min_value=0,
120
- max_value=int(video_duration),
121
- value=0,
122
- step=1
123
  )
124
- else:
125
- time_in_seconds = None
126
-
127
- if st.button("Convert"):
128
- with st.spinner("Converting..."):
129
- output_file = convert_video(video_file, target_format, conversion_type, time_in_seconds)
130
-
131
- if "Error" in output_file:
132
- st.error(output_file)
133
- else:
134
- st.success(f"Conversion Successful! Download the file:")
135
- st.download_button(label="Download Converted File", data=open(output_file, 'rb').read(), file_name=output_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
  if __name__ == "__main__":
138
  main()
 
88
  st.title("Video Conversion Tool")
89
  st.write("Convert videos to audio, GIFs, images, or other formats easily with this powerful tool.")
90
 
91
+ # Create two columns
92
+ col1, col2 = st.columns([1, 1])
93
+
94
+ with col1:
95
+ # Upload video file
96
+ video_file = st.file_uploader("Upload a Video", type=supported_formats)
97
+ if video_file:
98
+ st.video(video_file)
99
+
100
+ with col2:
101
+ if video_file:
102
+ # Create a temporary file and save uploaded video
103
+ temp_video_path = os.path.join(tempfile.mkdtemp(), video_file.name)
104
+ with open(temp_video_path, "wb") as f:
105
+ f.write(video_file.getbuffer())
106
+
107
+ # Get video duration
108
+ video_duration = get_video_duration(temp_video_path)
109
+
110
+ # Select conversion type
111
+ conversion_type = st.selectbox(
112
+ "Select Conversion Type",
113
+ ['Video to Video', 'Video to Audio', 'Video to GIF', 'Video to Image']
 
 
 
 
 
 
 
 
 
114
  )
115
+
116
+ # Update format choices based on conversion type
117
+ target_format_choices = update_format_choices(conversion_type)
118
+ target_format = st.selectbox("Select Target Format", target_format_choices)
119
+
120
+ # If 'Video to Image' conversion, ask for time in seconds
121
+ if conversion_type == 'Video to Image':
122
+ time_in_seconds = st.slider(
123
+ label="Time (in seconds) for image extraction",
124
+ min_value=0,
125
+ max_value=int(video_duration),
126
+ value=0,
127
+ step=1
128
+ )
129
+ else:
130
+ time_in_seconds = None
131
+
132
+ if st.button("Convert"):
133
+ with st.spinner("Converting..."):
134
+ output_file = convert_video(video_file, target_format, conversion_type, time_in_seconds)
135
+
136
+ if "Error" in output_file:
137
+ st.error(output_file)
138
+ else:
139
+ st.success(f"Conversion Successful! Download the file:")
140
+ st.download_button(
141
+ label="Download Converted File",
142
+ data=open(output_file, 'rb').read(),
143
+ file_name=output_file
144
+ )
145
 
146
  if __name__ == "__main__":
147
  main()