ombhojane commited on
Commit
a6bc33e
Β·
verified Β·
1 Parent(s): be1dd6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +128 -26
app.py CHANGED
@@ -4,52 +4,154 @@ import tempfile
4
  import os
5
  import time
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def main():
8
- st.title("AI Dance Partner")
9
- st.write("Upload your dance video and get an AI dance partner!")
10
-
11
- # Video upload
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(
22
- "Choose dance partner style",
23
- ["Sync Partner", "Creative Partner"]
 
 
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()
 
4
  import os
5
  import time
6
 
7
+ # Set page configuration
8
+ st.set_page_config(
9
+ page_title="AI Dance Partner",
10
+ page_icon="πŸ’ƒ",
11
+ layout="wide",
12
+ initial_sidebar_state="expanded"
13
+ )
14
+
15
+ # Custom CSS for better styling
16
+ def local_css():
17
+ st.markdown("""
18
+ <style>
19
+ .main {
20
+ padding: 2rem;
21
+ }
22
+ .stButton>button {
23
+ background-color: #FF4B4B;
24
+ color: white;
25
+ border-radius: 20px;
26
+ padding: 0.5rem 2rem;
27
+ font-weight: bold;
28
+ }
29
+ .stButton>button:hover {
30
+ background-color: #FF6B6B;
31
+ border-color: #FF4B4B;
32
+ }
33
+ .upload-text {
34
+ font-size: 1.2rem;
35
+ color: #666;
36
+ margin-bottom: 1rem;
37
+ }
38
+ .title-container {
39
+ background: linear-gradient(90deg, #FF4B4B, #FF8C8C);
40
+ padding: 2rem;
41
+ border-radius: 10px;
42
+ margin-bottom: 2rem;
43
+ color: white;
44
+ text-align: center;
45
+ }
46
+ .info-box {
47
+ background-color: #f0f2f6;
48
+ padding: 1rem;
49
+ border-radius: 10px;
50
+ margin-bottom: 1rem;
51
+ }
52
+ </style>
53
+ """, unsafe_allow_html=True)
54
+
55
  def main():
56
+ local_css()
 
 
 
 
57
 
58
+ # Title section with gradient background
59
+ st.markdown("""
60
+ <div class="title-container">
61
+ <h1>πŸ•Ί AI Dance Partner πŸ’ƒ</h1>
62
+ <p style="font-size: 1.2rem;">Transform your solo dance into a dynamic duet!</p>
63
+ </div>
64
+ """, unsafe_allow_html=True)
65
+
66
+ # Create two columns for layout
67
+ col1, col2 = st.columns([2, 1])
68
+
69
+ with col1:
70
+ st.markdown('<p class="upload-text">Upload your dance video and watch the magic happen!</p>', unsafe_allow_html=True)
71
+ uploaded_file = st.file_uploader("", type=['mp4', 'avi', 'mov'])
72
+
73
+ with col2:
74
+ st.markdown('<div class="info-box">', unsafe_allow_html=True)
75
+ st.markdown("### How it works")
76
+ st.markdown("""
77
+ 1. Upload your solo dance video
78
+ 2. Choose your preferred dance style
79
+ 3. Watch as AI creates your perfect dance partner!
80
+ """)
81
+ st.markdown('</div>', unsafe_allow_html=True)
82
+
83
  if uploaded_file is not None:
84
  # Create a temporary file
85
  with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tfile:
86
  tfile.write(uploaded_file.read())
87
  temp_input_path = tfile.name
88
 
89
+ # Style selection with custom design
90
+ st.markdown("### Choose Your Dance Partner Style")
91
+ style = st.select_slider(
92
+ "",
93
+ options=["Sync Partner", "Creative Partner"],
94
+ value="Sync Partner"
95
  )
96
 
97
+ # Add description based on selected style
98
+ if style == "Sync Partner":
99
+ st.info("πŸ’« Sync Partner will mirror your movements in perfect harmony.")
100
+ else:
101
+ st.info("🎨 Creative Partner will add its own artistic flair to your dance.")
102
+
103
+ if st.button("Generate Dance Partner 🎬"):
104
  try:
105
+ # Create a progress bar
106
+ progress_bar = st.progress(0)
107
+ status_text = st.empty()
108
+
109
+ # Processing steps
110
+ steps = ["Analyzing dance moves...", "Generating partner movements...", "Creating final video..."]
111
+ for i, step in enumerate(steps):
112
+ status_text.text(step)
113
+ progress_bar.progress((i + 1) * 33)
114
+ time.sleep(1)
115
+
116
+ # Process video
117
+ dance_partner = AIDancePartner()
118
+ output_path = dance_partner.process_video(temp_input_path, mode=style)
119
+
120
+ # Update progress
121
+ progress_bar.progress(100)
122
+ status_text.text("Done! πŸŽ‰")
123
+
124
+ # Display result in a nice container
125
+ st.markdown("### πŸŽ₯ Your Dance Duet")
126
+ st.video(output_path)
127
+
128
+ # Download button with custom styling
129
+ col1, col2, col3 = st.columns([1, 2, 1])
130
+ with col2:
131
  with open(output_path, 'rb') as file:
132
  st.download_button(
133
+ label="Download Your Dance Duet πŸ“₯",
134
  data=file,
135
  file_name="ai_dance_partner.mp4",
136
  mime="video/mp4"
137
  )
138
+
139
+ # Cleanup temporary files
140
+ os.unlink(temp_input_path)
141
+ os.unlink(output_path)
142
+
143
  except Exception as e:
144
+ st.error(f"Oops! Something went wrong: {str(e)}")
145
  if os.path.exists(temp_input_path):
146
  os.unlink(temp_input_path)
147
 
148
+ # Add footer
149
+ st.markdown("""
150
+ ---
151
+ <div style="text-align: center; color: #666;">
152
+ Made with ❀️ by AI Dance Partner Team
153
+ </div>
154
+ """, unsafe_allow_html=True)
155
+
156
  if __name__ == "__main__":
157
  main()