Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from pipelines.video_process import extract_audio_ffmpeg, apply_edits
|
| 4 |
+
from pipelines.ai_inference import transcribe_audio, generate_edit_instructions
|
| 5 |
+
# from pipelines.auth_utils import check_auth_status # If using custom
|
| 6 |
+
import openai
|
| 7 |
+
|
| 8 |
+
def main():
|
| 9 |
+
st.title("Smart Edit Assistant 🎬")
|
| 10 |
+
# Check if user is logged in if using custom auth
|
| 11 |
+
# user_info = check_auth_status()
|
| 12 |
+
# if not user_info:
|
| 13 |
+
# st.stop()
|
| 14 |
+
|
| 15 |
+
openai_api_key = os.getenv("OPENAI_API_KEY", "")
|
| 16 |
+
if openai_api_key:
|
| 17 |
+
openai.api_key = openai_api_key
|
| 18 |
+
else:
|
| 19 |
+
st.warning("No OpenAI API key found in environment.")
|
| 20 |
+
|
| 21 |
+
uploaded_file = st.file_uploader("Upload your video", type=["mp4", "mov", "mkv"])
|
| 22 |
+
if uploaded_file is not None:
|
| 23 |
+
with open("temp_input.mp4", "wb") as f:
|
| 24 |
+
f.write(uploaded_file.getbuffer())
|
| 25 |
+
|
| 26 |
+
st.video("temp_input.mp4")
|
| 27 |
+
|
| 28 |
+
if st.button("Process Video"):
|
| 29 |
+
with st.spinner("Extracting audio..."):
|
| 30 |
+
audio_path = extract_audio_ffmpeg("temp_input.mp4", "temp_audio.wav")
|
| 31 |
+
|
| 32 |
+
with st.spinner("Transcribing..."):
|
| 33 |
+
transcript_text = transcribe_audio(audio_path) # calls either local or API-based Whisper
|
| 34 |
+
|
| 35 |
+
st.text_area("Transcript", transcript_text, height=200)
|
| 36 |
+
|
| 37 |
+
with st.spinner("Generating edit instructions with GPT..."):
|
| 38 |
+
edit_instructions = generate_edit_instructions(transcript_text)
|
| 39 |
+
|
| 40 |
+
st.write(edit_instructions)
|
| 41 |
+
|
| 42 |
+
with st.spinner("Applying edits..."):
|
| 43 |
+
edited_video_path = apply_edits("temp_input.mp4", edit_instructions)
|
| 44 |
+
|
| 45 |
+
st.success("Done!")
|
| 46 |
+
st.video(edited_video_path)
|
| 47 |
+
with open(edited_video_path, "rb") as f_out:
|
| 48 |
+
st.download_button("Download Edited Video", data=f_out, file_name="edited_result.mp4", mime="video/mp4")
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
main()
|