fix: Backend server

parent 143686f2
......@@ -49,7 +49,7 @@ async def uploaded_video(file: UploadFile = File(...)):
translated_text_en = translate_text(recognized_text, "en")
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()
)
print("Translated Integer (Si):", translated_integer_si)
......
......@@ -41,6 +41,8 @@ app.include_router(video_to_sign_language_controller.router)
origins = [
"http://localhost",
"http://localhost:8080",
"http://127.0.0.1:8000",
"http://localhost:3000"
]
app.add_middleware(
......
// project import
import MainCard from 'components/MainCard';
import ScrollX from 'components/ScrollX';
import {
Box,
Button,
......@@ -19,12 +17,14 @@ import {
TextField,
Typography
} from '@mui/material';
import MainCard from 'components/MainCard';
import ScrollX from 'components/ScrollX';
import { useState } from 'react';
import { useSnackbar } from 'notistack';
import { CloudUploadOutlined, CopyOutlined, HighlightOutlined, TranslationOutlined } from '@ant-design/icons';
import axios from 'axios';
import { MuiFileInput } from 'mui-file-input';
import { CloudUploadOutlined, HighlightOutlined, CopyOutlined, TranslationOutlined } from '@ant-design/icons';
import VideoToSignLanguageService from '../../services/VideoToSignLanguage.js';
import { useSnackbar } from 'notistack';
import { useState } from 'react';
// ==============================|| List ||============================== //
......@@ -56,38 +56,64 @@ const VideoTranslate = () => {
// ----------------- 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) {
setLoading(true);
const formData = new FormData();
//@ts-ignore
formData.append('video', file, file.name);
formData.append('file', file);
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);
const response = await axios.post('http://127.0.0.1:8000/rest_pyton/uploaded_video', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
setTranslatedTextEn(response.data.translated_text_en)
setTranslatedTextSi(response.data.translated_text_si)
setLoading(false)
} catch (error) {
console.log(error);
setLoading(false);
enqueueSnackbar('Something went Wrong!', { variant: 'error' });
console.error('Error:', error);
setLoading(false)
}
} else {
enqueueSnackbar('Please select a file.', { variant: 'warning' });
console.error('No file selected.');
setLoading(false)
}
};
}
const { enqueueSnackbar } = useSnackbar();
const onCopy = (text: string) => {
......@@ -217,7 +243,7 @@ const VideoTranslate = () => {
mb: 3
}}
disabled={loading}
onClick={TranslateVideoToSignLanguage}
onClick={uploadVideo}
endIcon={<TranslationOutlined />}
>
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