Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,10 +12,8 @@ from utils import process_video, process_image, process_gif
|
|
| 12 |
from database import get_db, ProcessedFile, PoseData, AnimationData
|
| 13 |
|
| 14 |
def init_page():
|
| 15 |
-
"""Initialize Streamlit page configuration with embedded styling."""
|
| 16 |
st.set_page_config(layout="wide", page_title="Pose Detection & Animation Generator")
|
| 17 |
|
| 18 |
-
# Embedded CSS styles
|
| 19 |
st.markdown("""
|
| 20 |
<style>
|
| 21 |
/* Base styling */
|
|
@@ -55,7 +53,6 @@ def init_page():
|
|
| 55 |
</style>
|
| 56 |
""", unsafe_allow_html=True)
|
| 57 |
|
| 58 |
-
# Detection settings
|
| 59 |
st.sidebar.title("Settings")
|
| 60 |
confidence_threshold = st.sidebar.slider(
|
| 61 |
"Detection Confidence",
|
|
@@ -65,27 +62,27 @@ def init_page():
|
|
| 65 |
step=0.1
|
| 66 |
)
|
| 67 |
|
| 68 |
-
# Export format selection
|
| 69 |
export_format = st.sidebar.selectbox(
|
| 70 |
"Export Format",
|
| 71 |
options=['uasset', 'fbx', 'bvh'],
|
| 72 |
key='export_format'
|
| 73 |
)
|
| 74 |
|
| 75 |
-
#
|
| 76 |
enable_corrections = st.sidebar.checkbox("Enable Manual Corrections")
|
| 77 |
if enable_corrections:
|
| 78 |
st.sidebar.info("Click on landmarks in the preview to adjust their positions")
|
| 79 |
|
|
|
|
|
|
|
|
|
|
| 80 |
st.title("Pose Detection & Animation Generator")
|
| 81 |
return confidence_threshold
|
| 82 |
|
| 83 |
def init_components() -> Tuple[PoseDetector, SkeletonGenerator, AnimationExporter]:
|
| 84 |
-
"""Initialize the main processing components."""
|
| 85 |
return PoseDetector(), SkeletonGenerator(), AnimationExporter()
|
| 86 |
|
| 87 |
def handle_upload(file_type: str, uploaded_file, components: Tuple, db_session) -> Optional[ProcessedFile]:
|
| 88 |
-
"""Process uploaded file and store results in database."""
|
| 89 |
processed_file = ProcessedFile(
|
| 90 |
filename=uploaded_file.name,
|
| 91 |
file_type='video' if uploaded_file.type == 'image/gif' else file_type,
|
|
@@ -165,11 +162,11 @@ def process_image_upload(uploaded_file, components, processed_file, db, col1, co
|
|
| 165 |
canvas_container = st.empty()
|
| 166 |
canvas_container.image(processed_rgb, use_column_width=True)
|
| 167 |
|
| 168 |
-
|
| 169 |
-
st.session_state.manual_correction = True
|
| 170 |
-
st.session_state.current_landmarks = skeleton_data.copy()
|
| 171 |
-
|
| 172 |
if st.session_state.get('manual_correction', False):
|
|
|
|
|
|
|
|
|
|
| 173 |
joints = st.session_state.current_landmarks
|
| 174 |
selected_joint = st.selectbox("Select Joint to Adjust", list(joints.keys()))
|
| 175 |
|
|
@@ -189,8 +186,6 @@ def process_image_upload(uploaded_file, components, processed_file, db, col1, co
|
|
| 189 |
save_corrected_pose(db, processed_file.id, joints)
|
| 190 |
st.success("Corrections saved successfully!")
|
| 191 |
|
| 192 |
-
provide_download_button(animation_data_binary)
|
| 193 |
-
|
| 194 |
def process_video_upload(uploaded_file, components, processed_file, db, is_gif, col1, col2):
|
| 195 |
"""Handle video/GIF file upload processing."""
|
| 196 |
pose_detector, skeleton_generator, animation_exporter = components
|
|
@@ -228,20 +223,13 @@ def save_pose_data(db, file_id: int, skeleton_data: dict):
|
|
| 228 |
db.commit()
|
| 229 |
|
| 230 |
def save_animation_data(db, file_id: int, skeleton_data: dict):
|
| 231 |
-
animation_data = AnimationData(
|
| 232 |
-
file_id=file_id,
|
| 233 |
-
skeleton_data=skeleton_data
|
| 234 |
-
)
|
| 235 |
db.add(animation_data)
|
| 236 |
db.commit()
|
| 237 |
|
| 238 |
def save_video_data(db, file_id: int, animation_frames: list):
|
| 239 |
for frame_num, frame_data in enumerate(animation_frames):
|
| 240 |
-
pose_data = PoseData(
|
| 241 |
-
file_id=file_id,
|
| 242 |
-
frame_number=frame_num,
|
| 243 |
-
landmarks=frame_data
|
| 244 |
-
)
|
| 245 |
db.add(pose_data)
|
| 246 |
db.commit()
|
| 247 |
|
|
@@ -253,6 +241,12 @@ def provide_download_button(animation_data_binary):
|
|
| 253 |
mime="application/octet-stream"
|
| 254 |
)
|
| 255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
def show_instructions():
|
| 257 |
with st.expander("Instructions"):
|
| 258 |
st.markdown("""
|
|
|
|
| 12 |
from database import get_db, ProcessedFile, PoseData, AnimationData
|
| 13 |
|
| 14 |
def init_page():
|
|
|
|
| 15 |
st.set_page_config(layout="wide", page_title="Pose Detection & Animation Generator")
|
| 16 |
|
|
|
|
| 17 |
st.markdown("""
|
| 18 |
<style>
|
| 19 |
/* Base styling */
|
|
|
|
| 53 |
</style>
|
| 54 |
""", unsafe_allow_html=True)
|
| 55 |
|
|
|
|
| 56 |
st.sidebar.title("Settings")
|
| 57 |
confidence_threshold = st.sidebar.slider(
|
| 58 |
"Detection Confidence",
|
|
|
|
| 62 |
step=0.1
|
| 63 |
)
|
| 64 |
|
|
|
|
| 65 |
export_format = st.sidebar.selectbox(
|
| 66 |
"Export Format",
|
| 67 |
options=['uasset', 'fbx', 'bvh'],
|
| 68 |
key='export_format'
|
| 69 |
)
|
| 70 |
|
| 71 |
+
# Чекбокс для ручной коррекции
|
| 72 |
enable_corrections = st.sidebar.checkbox("Enable Manual Corrections")
|
| 73 |
if enable_corrections:
|
| 74 |
st.sidebar.info("Click on landmarks in the preview to adjust their positions")
|
| 75 |
|
| 76 |
+
# Сохранение состояния ручной коррекции в session_state
|
| 77 |
+
st.session_state.manual_correction = enable_corrections
|
| 78 |
+
|
| 79 |
st.title("Pose Detection & Animation Generator")
|
| 80 |
return confidence_threshold
|
| 81 |
|
| 82 |
def init_components() -> Tuple[PoseDetector, SkeletonGenerator, AnimationExporter]:
|
|
|
|
| 83 |
return PoseDetector(), SkeletonGenerator(), AnimationExporter()
|
| 84 |
|
| 85 |
def handle_upload(file_type: str, uploaded_file, components: Tuple, db_session) -> Optional[ProcessedFile]:
|
|
|
|
| 86 |
processed_file = ProcessedFile(
|
| 87 |
filename=uploaded_file.name,
|
| 88 |
file_type='video' if uploaded_file.type == 'image/gif' else file_type,
|
|
|
|
| 162 |
canvas_container = st.empty()
|
| 163 |
canvas_container.image(processed_rgb, use_column_width=True)
|
| 164 |
|
| 165 |
+
# Если включена ручная коррекция через чекбокс
|
|
|
|
|
|
|
|
|
|
| 166 |
if st.session_state.get('manual_correction', False):
|
| 167 |
+
# Инициализируем состояние текущих координат, если ещё не задано
|
| 168 |
+
if 'current_landmarks' not in st.session_state:
|
| 169 |
+
st.session_state.current_landmarks = skeleton_data.copy()
|
| 170 |
joints = st.session_state.current_landmarks
|
| 171 |
selected_joint = st.selectbox("Select Joint to Adjust", list(joints.keys()))
|
| 172 |
|
|
|
|
| 186 |
save_corrected_pose(db, processed_file.id, joints)
|
| 187 |
st.success("Corrections saved successfully!")
|
| 188 |
|
|
|
|
|
|
|
| 189 |
def process_video_upload(uploaded_file, components, processed_file, db, is_gif, col1, col2):
|
| 190 |
"""Handle video/GIF file upload processing."""
|
| 191 |
pose_detector, skeleton_generator, animation_exporter = components
|
|
|
|
| 223 |
db.commit()
|
| 224 |
|
| 225 |
def save_animation_data(db, file_id: int, skeleton_data: dict):
|
| 226 |
+
animation_data = AnimationData(file_id=file_id, skeleton_data=skeleton_data)
|
|
|
|
|
|
|
|
|
|
| 227 |
db.add(animation_data)
|
| 228 |
db.commit()
|
| 229 |
|
| 230 |
def save_video_data(db, file_id: int, animation_frames: list):
|
| 231 |
for frame_num, frame_data in enumerate(animation_frames):
|
| 232 |
+
pose_data = PoseData(file_id=file_id, frame_number=frame_num, landmarks=frame_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
db.add(pose_data)
|
| 234 |
db.commit()
|
| 235 |
|
|
|
|
| 241 |
mime="application/octet-stream"
|
| 242 |
)
|
| 243 |
|
| 244 |
+
# Stub для сохранения скорректированных данных (при необходимости можно расширить)
|
| 245 |
+
def save_corrected_pose(db, file_id: int, joints: dict):
|
| 246 |
+
pose_data = PoseData(file_id=file_id, landmarks=joints, corrected_landmarks=joints, is_corrected=True)
|
| 247 |
+
db.add(pose_data)
|
| 248 |
+
db.commit()
|
| 249 |
+
|
| 250 |
def show_instructions():
|
| 251 |
with st.expander("Instructions"):
|
| 252 |
st.markdown("""
|