fix: Backend server

parent 143686f2
...@@ -49,7 +49,7 @@ async def uploaded_video(file: UploadFile = File(...)): ...@@ -49,7 +49,7 @@ async def uploaded_video(file: UploadFile = File(...)):
translated_text_en = translate_text(recognized_text, "en") translated_text_en = translate_text(recognized_text, "en")
translated_integer_si = " ".join( translated_integer_si = " ".join(
str(unicode_to_int_mapping.get(word, 0)) str(unicode_to_int_mapping.get(word, "0"))
for word in translated_text_si.split() for word in translated_text_si.split()
) )
print("Translated Integer (Si):", translated_integer_si) print("Translated Integer (Si):", translated_integer_si)
......
...@@ -41,6 +41,8 @@ app.include_router(video_to_sign_language_controller.router) ...@@ -41,6 +41,8 @@ app.include_router(video_to_sign_language_controller.router)
origins = [ origins = [
"http://localhost", "http://localhost",
"http://localhost:8080", "http://localhost:8080",
"http://127.0.0.1:8000",
"http://localhost:3000"
] ]
app.add_middleware( app.add_middleware(
......
// project import // project import
import MainCard from 'components/MainCard';
import ScrollX from 'components/ScrollX';
import { import {
Box, Box,
Button, Button,
...@@ -19,12 +17,14 @@ import { ...@@ -19,12 +17,14 @@ import {
TextField, TextField,
Typography Typography
} from '@mui/material'; } from '@mui/material';
import MainCard from 'components/MainCard';
import ScrollX from 'components/ScrollX';
import { useState } from 'react'; import { CloudUploadOutlined, CopyOutlined, HighlightOutlined, TranslationOutlined } from '@ant-design/icons';
import { useSnackbar } from 'notistack'; import axios from 'axios';
import { MuiFileInput } from 'mui-file-input'; import { MuiFileInput } from 'mui-file-input';
import { CloudUploadOutlined, HighlightOutlined, CopyOutlined, TranslationOutlined } from '@ant-design/icons'; import { useSnackbar } from 'notistack';
import VideoToSignLanguageService from '../../services/VideoToSignLanguage.js'; import { useState } from 'react';
// ==============================|| List ||============================== // // ==============================|| List ||============================== //
...@@ -56,38 +56,64 @@ const VideoTranslate = () => { ...@@ -56,38 +56,64 @@ const VideoTranslate = () => {
// ----------------- Video Upload ------------------------------------------------ // ----------------- Video Upload ------------------------------------------------
const TranslateVideoToSignLanguage = async () => { // const TranslateVideoToSignLanguage = async () => {
// if (file) {
// setLoading(true);
// const formData = new FormData();
// //@ts-ignore
// formData.append('video', file, file.name);
// try {
// const response = await VideoToSignLanguageService.videoTranslation(formData);
// const { translated_text_si, translated_text_en } = response.data;
// setTranslatedTextSi(translated_text_si);
// setTranslatedTextEn(translated_text_en);
// if (response.status == 200) {
// console.log(response.data);
// // setValue(response.data.predictions);
// } else {
// enqueueSnackbar('Something went Wrong!', { variant: 'error' });
// }
// // setLoading(false);
// } catch (error) {
// console.log(error);
// setLoading(false);
// enqueueSnackbar('Something went Wrong!', { variant: 'error' });
// }
// } else {
// enqueueSnackbar('Please select a file.', { variant: 'warning' });
// }
// };
async function uploadVideo() {
setLoading(true)
if (file) { if (file) {
setLoading(true);
const formData = new FormData(); const formData = new FormData();
formData.append('file', file);
//@ts-ignore
formData.append('video', file, file.name);
try { try {
const response = await VideoToSignLanguageService.videoTranslation(formData); const response = await axios.post('http://127.0.0.1:8000/rest_pyton/uploaded_video', formData, {
headers: {
const { translated_text_si, translated_text_en } = response.data; 'Content-Type': 'multipart/form-data',
setTranslatedTextSi(translated_text_si); },
setTranslatedTextEn(translated_text_en); });
setTranslatedTextEn(response.data.translated_text_en)
setTranslatedTextSi(response.data.translated_text_si)
setLoading(false)
if (response.status == 200) {
console.log(response.data);
// setValue(response.data.predictions);
} else {
enqueueSnackbar('Something went Wrong!', { variant: 'error' });
}
// setLoading(false);
} catch (error) { } catch (error) {
console.log(error); console.error('Error:', error);
setLoading(false); setLoading(false)
enqueueSnackbar('Something went Wrong!', { variant: 'error' });
} }
} else { } else {
enqueueSnackbar('Please select a file.', { variant: 'warning' }); console.error('No file selected.');
setLoading(false)
}
} }
};
const { enqueueSnackbar } = useSnackbar(); const { enqueueSnackbar } = useSnackbar();
const onCopy = (text: string) => { const onCopy = (text: string) => {
...@@ -217,7 +243,7 @@ const VideoTranslate = () => { ...@@ -217,7 +243,7 @@ const VideoTranslate = () => {
mb: 3 mb: 3
}} }}
disabled={loading} disabled={loading}
onClick={TranslateVideoToSignLanguage} onClick={uploadVideo}
endIcon={<TranslationOutlined />} endIcon={<TranslationOutlined />}
> >
Translate Translate
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment