ombhojane commited on
Commit
e402479
·
verified ·
1 Parent(s): bf547f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -21
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  from colab import AIDancePartner
3
  import tempfile
4
  import os
 
5
 
6
  def main():
7
  st.title("AI Dance Partner")
@@ -11,9 +12,10 @@ def main():
11
  uploaded_file = st.file_uploader("Choose a video file", type=['mp4', 'avi', 'mov'])
12
 
13
  if uploaded_file is not None:
14
- # Save uploaded file temporarily
15
- tfile = tempfile.NamedTemporaryFile(delete=False)
16
- tfile.write(uploaded_file.read())
 
17
 
18
  # Dance style selection
19
  style = st.selectbox(
@@ -22,25 +24,32 @@ def main():
22
  )
23
 
24
  if st.button("Generate Dance Partner"):
25
- with st.spinner("Processing your dance video..."):
26
- # Process video
27
- dance_partner = AIDancePartner()
28
- output_path = dance_partner.process_video(tfile.name, mode=style)
29
-
30
- # Display result
31
- st.video(output_path)
32
-
33
- # Download button
34
- with open(output_path, 'rb') as file:
35
- st.download_button(
36
- label="Download video",
37
- data=file,
38
- file_name="ai_dance_partner.mp4",
39
- mime="video/mp4"
40
- )
41
 
42
- # Cleanup
43
- os.unlink(tfile.name)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  if __name__ == "__main__":
46
  main()
 
2
  from colab import AIDancePartner
3
  import tempfile
4
  import os
5
+ import time
6
 
7
  def main():
8
  st.title("AI Dance Partner")
 
12
  uploaded_file = st.file_uploader("Choose a video file", type=['mp4', 'avi', 'mov'])
13
 
14
  if uploaded_file is not None:
15
+ # Create a temporary file
16
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tfile:
17
+ tfile.write(uploaded_file.read())
18
+ temp_input_path = tfile.name
19
 
20
  # Dance style selection
21
  style = st.selectbox(
 
24
  )
25
 
26
  if st.button("Generate Dance Partner"):
27
+ try:
28
+ with st.spinner("Processing your dance video..."):
29
+ # Process video
30
+ dance_partner = AIDancePartner()
31
+ output_path = dance_partner.process_video(temp_input_path, mode=style)
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ # Display result
34
+ st.video(output_path)
35
+
36
+ # Download button
37
+ with open(output_path, 'rb') as file:
38
+ st.download_button(
39
+ label="Download video",
40
+ data=file,
41
+ file_name="ai_dance_partner.mp4",
42
+ mime="video/mp4"
43
+ )
44
+
45
+ # Cleanup temporary files
46
+ os.unlink(temp_input_path)
47
+ os.unlink(output_path)
48
+
49
+ except Exception as e:
50
+ st.error(f"An error occurred: {str(e)}")
51
+ if os.path.exists(temp_input_path):
52
+ os.unlink(temp_input_path)
53
 
54
  if __name__ == "__main__":
55
  main()