Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import subprocess | |
| import os | |
| import pandas as pd | |
| import io | |
| st.title("Hare Krishna π Clippy") | |
| k1, k2 = st.columns(2) | |
| with k1: | |
| # File uploader for the video | |
| video_file = st.file_uploader("Upload the video lecture", type=['mp4']) | |
| if video_file is not None: | |
| # Save the uploaded file temporarily | |
| with open("temp_video.mp4", "wb") as f: | |
| f.write(video_file.getbuffer()) | |
| # Option to choose between manual input or CSV upload | |
| input_method = st.radio("Choose input method", ["Manual", "CSV Upload"]) | |
| clips_info = [] | |
| if input_method == "Manual": | |
| # Manual input for multiple start and end times | |
| num_clips = st.number_input("Number of clips to generate", min_value=1, value=1) | |
| for i in range(num_clips): | |
| st.subheader(f"Clip {i+1}") | |
| start_time = st.text_input(f"Start time for clip {i+1} (hh:mm:ss)", key=f"start_{i}") | |
| end_time = st.text_input(f"End time for clip {i+1} (hh:mm:ss)", key=f"end_{i}") | |
| clip_name = st.text_input(f"Name for clip {i+1}", key=f"name_{i}") | |
| clips_info.append((start_time, end_time, clip_name)) | |
| else: # CSV Upload | |
| csv_file = st.file_uploader("Upload CSV file with clip information", type=['csv']) | |
| if csv_file is not None: | |
| df = pd.read_csv(io.StringIO(csv_file.getvalue().decode('utf-8'))) | |
| for _, row in df.iterrows(): | |
| clips_info.append((row['start_time'], row['end_time'], row['id'])) | |
| if st.button("Generate Clips"): | |
| for i, (start, end, name) in enumerate(clips_info): | |
| output_name = f"{name}.mp4" if name else f"clip_{i+1}.mp4" | |
| command = f'ffmpeg -i temp_video.mp4 -ss {start} -to {end} -c:v libx264 -crf 18 -c:a aac -b:a 192k -preset fast {output_name}' | |
| try: | |
| subprocess.run(command, shell=True, check=True) | |
| st.success(f"Clip {i+1} generated successfully: {output_name}") | |
| # Provide download button for the generated clip | |
| with open(output_name, "rb") as file: | |
| st.download_button( | |
| label=f"Download {output_name}", | |
| data=file, | |
| file_name=output_name, | |
| mime="video/mp4" | |
| ) | |
| except subprocess.CalledProcessError as e: | |
| st.error(f"Error generating clip {i+1}: {e}") | |
| # Clean up the temporary file | |
| if os.path.exists("temp_video.mp4"): | |
| os.remove("temp_video.mp4") | |
| with k2: | |
| st.image("https://imgur.com/vZMVBYw.png", caption="β Hare Krishna Clippy") | |
| st.header("How to use Hare Krishna Clippy") | |
| st.markdown(""" | |
| 1. **Upload Video**: Start by uploading your video lecture in MP4 format. | |
| 2. **Choose Input Method**: Select either "Manual" or "CSV Upload". | |
| 3a. **Manual Input**: | |
| - Set the number of clips you want to create. | |
| - For each clip, provide: | |
| - Start time (in hh:mm:ss format) | |
| - End time (in hh:mm:ss format) | |
| - Clip name (optional) | |
| 3b. **CSV Upload**: | |
| - Upload a CSV file with columns: id, start_time, end_time | |
| - Example: | |
| id,start_time,end_time | |
| clip1,00:00:10,00:00:20 | |
| clip2,00:01:30,00:02:00 | |
| 4. **Generate Clips**: Click the "Generate Clips" button to create your clips. | |
| 5. **Download**: Once processing is complete, download buttons will appear for each generated clip. | |
| Hare Krishna! May this tool assist you in spreading Krishna consciousness. | |
| """) | |
| st.info("Remember to respect KRISHNA's copyright laws and only use videos you have permission to clip.") | |