Spaces:
Configuration error
Configuration error
File size: 4,012 Bytes
97e3689 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
<script setup>
import { ref } from "vue";
import axios from "axios";
import Dropzone from "../components/Dropzone.vue";
import DropzoneLoading from "../components/DropzoneLoading.vue";
import Result from "../components/Result.vue";
const apiUrl = import.meta.env.VITE_BASE_URL || "http://127.0.0.1:8000";
const EXERCISES = ["squat", "plank", "bicep_curl", "lunge"];
const submitData = ref({
videoFile: null,
exerciseType: null,
});
const processedData = ref(null);
const isProcessing = ref(false);
const uploadToServer = async () => {
if (!submitData.value.videoFile) {
alert("No video selected");
return;
}
if (!submitData.value.exerciseType) {
alert("No exercise type selected");
return;
}
processedData.value = null;
try {
isProcessing.value = true;
const { data } = await axios.post(
`${apiUrl}/api/video/upload?type=${submitData.value.exerciseType}`,
{ file: submitData.value.videoFile },
{
headers: {
"Content-Type": "multipart/form-data",
},
}
);
processedData.value = data;
} catch (e) {
console.error("Error: ", e);
} finally {
isProcessing.value = false;
}
};
</script>
<template>
<!-- Input section -->
<section class="input-section">
<Dropzone
v-show="!isProcessing"
@file-uploaded="(file) => (submitData.videoFile = file)"
/>
<DropzoneLoading v-show="isProcessing" />
<div class="right-container">
<!-- exercises selection -->
<div class="exercises-container">
<p
class="exercise"
v-for="exercise in EXERCISES"
:class="{ active: submitData.exerciseType == exercise }"
@click="submitData.exerciseType = exercise"
>
{{ exercise }}
</p>
</div>
<button class="process-btn" @click="uploadToServer">
<span>Process!</span>
</button>
</div>
</section>
<!-- Results section -->
<Result v-if="processedData" :data="processedData" />
</template>
<style lang="scss" scoped>
.input-section {
display: flex;
gap: 1rem;
* {
flex: 1;
}
.right-container {
display: flex;
flex-direction: column;
width: 100%;
.exercises-container {
display: flex;
flex-wrap: wrap;
gap: 1rem;
margin-bottom: 1rem;
.exercise {
display: flex;
justify-content: center;
align-items: center;
padding: 1rem 0;
flex: 45%;
color: var(--secondary-color);
text-transform: uppercase;
border: 3px solid var(--primary-color);
border-radius: 0.3rem;
cursor: pointer;
transition: all 0.25s ease;
&:hover {
box-shadow: 0 6px 18px 0 rgba(#000, 0.1);
transform: translateY(-6px);
}
&.active {
background-color: var(--primary-color);
font-weight: 700;
}
}
}
.process-btn {
border: none;
background-color: var(--primary-color);
padding: 1.25rem 0;
color: whitesmoke;
font-size: 1.25rem;
font-weight: 700;
cursor: pointer;
border-radius: 8px;
transition: all 0.25s ease;
&:hover {
box-shadow: 0 6px 18px 0 rgba(#000, 0.1);
color: var(--primary-color);
border-color: transparent;
background-color: transparent;
}
}
}
}
</style>
|