Spaces:
Runtime error
Runtime error
HuggingFace-SK commited on
Commit ·
717217e
1
Parent(s): bb63de4
unify android and web html
Browse filesFiles changed (2)
- main.py+1-1
- templates/browser-detect.html+102-27
10 unmodified lines1112131410 unmodified linesreturn send_from_directory("better_exported", "model.tflite")if (__name__ == '__main__'):app.run( host='0.0.0.0', port=7860)10 unmodified lines1112131410 unmodified linesreturn send_from_directory("better_exported", "model.tflite")if (__name__ == '__main__'):app.run( host='0.0.0.0', port=7860)
2 unmodified lines34567891 unmodified line11121314151617181920212223242526272829303132333418 unmodified lines535455565758596061626364654 unmodified lines7071727374757677787980818283848586878889909192939 unmodified lines1031041051061071081091105 unmodified lines1161171181191201211221231241252 unmodified lines12812913013113213313458 unmodified lines193194195196197198199200201202334 unmodified lines5375385395405415425435445455465475482 unmodified lines<head></head><meta charset="UTF-8"><title>Sign Language Interpreter</title>1 unmodified line<script>window.console = window.console || function (t) { };</script><link rel="stylesheet" type="text/css" href="static/browser_detect.css" /></head><body translate="no"><script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js"crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core"></script><script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-cpu"></script><script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-tflite/dist/tf-tflite.min.js"></script><div class="container"><video id="webcam" style="display:none" autoplay="" playsinline=""></video><div class="canvas_wrapper" id="canvas_wrapper"><button id="switch-camera" style="display:none; position: absolute; top:10px; left:10px; padding:5px; height:40px; width:40px; text-align: center; border-radius: 12.25px; font-size: 20px; font-weight: 900; border:none; background-color: #f2f2f2; color:black;box-shadow: 0px 4px 20px 4px rgba(0, 0, 0, 0.38); z-index:100">18 unmodified lines<span>Listen 🔊</span></button></div><center><script>var synthesis = window.speechSynthesis;if ('speechSynthesis' in window) {var synthesis = window.speechSynthesis;// Get the first `en` language voice in the list4 unmodified lines// Create an utterance object} else {console.log('Text-to-speech not supported.');}function speak(text) {if ('speechSynthesis' in window) {// Speak the utterancevar utterance = new SpeechSynthesisUtterance(text);// Set utterance propertiesutterance.voice = voice;utterance.pitch = 0.6;utterance.rate = 0.8;utterance.volume = 0.8;synthesis.speak(utterance);} else {console.log('Text-to-speech not supported.');}}var word_list = []9 unmodified lines<script type="module">import { HandLandmarker, FilesetResolver } from "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0";let handLandmarker = undefined;let runningMode = "IMAGE";let enableWebcamButton;5 unmodified lines// loading. Machine Learning models can be large and take a moment to// get everything needed to run.const createHandLandmarker = async () => {const vision = await FilesetResolver.forVisionTasks("https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm");handLandmarker = await HandLandmarker.createFromOptions(vision, {baseOptions: {modelAssetPath: `https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task`,delegate: "GPU"},runningMode: runningMode,2 unmodified lines};createHandLandmarker();const MODEL_PATH = "/exported"var objectDetector = tflite.loadTFLiteModel(MODEL_PATH);/********************************************************************58 unmodified lines}};// Activate the webcam stream.navigator.mediaDevices.getUserMedia(constraints).then((stream) => {video.srcObject = stream;video.addEventListener("loadeddata", predictWebcam);});}let lastVideoTime = -1;let results = undefined;334 unmodified lines}</script><script src="https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm/vision_wasm_internal.js"crossorigin="anonymous"></script></body></html>2 unmodified lines34567891 unmodified line11121314151617181920212223242526272829303132333435363738394041424344454647484918 unmodified lines68697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131144 unmodified lines1191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591609 unmodified lines1701711721731741751761771785 unmodified lines1841851861871881891901911921931942 unmodified lines19719819920020120220320458 unmodified lines263264265266267268269270271272273274275276277334 unmodified lines6126136146156166176186196206216226232 unmodified lines<head></head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /><title>Sign Language Interpreter</title>1 unmodified line<script>window.console = window.console || function (t) { };</script><!-- For Android<link rel="stylesheet" type="text/css" href="http://127.0.0.1:8125/assets/static/browser_detect.css" />--><!-- For Web --><link rel="stylesheet" type="text/css" href="static/browser_detect.css" /></head><body translate="no"><!-- For Android<script src="../assets/ipc/androidjs.js"></script><script src="http://127.0.0.1:8125/assets/static/drawing_utils.js" crossorigin="anonymous"></script><script src="http://127.0.0.1:8125/assets/static/hands.js" crossorigin="anonymous"></script><script src="http://127.0.0.1:8125/assets/static/tfjs-core"></script><script src="http://127.0.0.1:8125/assets/static/tfjs-backend-cpu"></script><script src="http://127.0.0.1:8125/assets/static/tf-tflite.min.js"></script><script src="http://127.0.0.1:8125/assets/static/vision_wasm_internal.js" crossorigin="anonymous"></script>--><!-- For Web --><script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js"crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core"></script><script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-cpu"></script><script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-tflite/dist/tf-tflite.min.js"></script><div class="container"><video id="webcam" style="display:none" autoplay playsinline muted></video><div class="canvas_wrapper" id="canvas_wrapper"><button id="switch-camera" style="display:none; position: absolute; top:10px; left:10px; padding:5px; height:40px; width:40px; text-align: center; border-radius: 12.25px; font-size: 20px; font-weight: 900; border:none; background-color: #f2f2f2; color:black;box-shadow: 0px 4px 20px 4px rgba(0, 0, 0, 0.38); z-index:100">18 unmodified lines<span>Listen 🔊</span></button><audio id="audioPlayer">-</audio></div><div id="logUI"></div><center><script>var speechSupported = truevar prevSpeech = ""logUI = document.getElementById("logUI")function logMessage(msg) {const span = document.createElement('span');span.textContent = msg;logUI.appendChild(span);logUI.appendChild(document.createElement('br')); // Add a line break}const originalFetch = window.fetch;// Override the fetch functionwindow.fetch = async function (input, init) {// Convert input to URL if it's a Request objectconst url = typeof input === 'string' ? input : input.url;var newUrl = urlif (url == 'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm/vision_wasm_internal.wasm') {// newUrl = 'http://127.0.0.1:8125/assets/static/vision_wasm_internal.wasm' //For AndroidnewUrl = 'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm/vision_wasm_internal.wasm' // For Web}console.log("This was FETCHED: ", newUrl)// Call the original fetch function with the new URLreturn originalFetch(newUrl, init);};var synthesis = window.speechSynthesis;if ('speechSynthesis' in window) {var synthesis = window.speechSynthesis;// Get the first `en` language voice in the list4 unmodified lines// Create an utterance object} else {speechSupported = false;console.log('Text-to-speech not supported.');}function speak(text) {console.log("speech api support", speechSupported)console.log("condition: ", !speechSupported)console.log("condition2: ", speechSupported == false)if (!speechSupported) {console.log("speech api support", speechSupported)const audioPlayer = document.getElementById('audioPlayer');if (prevSpeech != text) {prevSpeech = textaudioPlayer.src = 'http://127.0.0.1:8125/speech?t=' + text; // Set the audio sourceconsole.log("Set src: ", audioPlayer.src)}audioPlayer.play() // Play the audio.then(() => {console.log('Audio is playing');}).catch(error => {console.error('Error playing audio:', error);prevSpeech = ''});} elseif ('speechSynthesis' in window) {var utterance = new SpeechSynthesisUtterance(text);utterance.voice = voice;utterance.pitch = 0.6;utterance.rate = 0.8;utterance.volume = 0.8;synthesis.speak(utterance);} else {console.log("Text to speech is now not supported")}}var word_list = []9 unmodified lines<script type="module">//import { HandLandmarker, FilesetResolver } from "http://127.0.0.1:8125/assets/static/tasks-vision@0.10.0" // For Androidimport { HandLandmarker, FilesetResolver } from "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0"; // For Weblet handLandmarker = undefined;let runningMode = "IMAGE";let enableWebcamButton;5 unmodified lines// loading. Machine Learning models can be large and take a moment to// get everything needed to run.const createHandLandmarker = async () => {const vision = await FilesetResolver.forVisionTasks("https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm"); // This doesnt really matter as this is already imported somewhere else, and the code runs fine without the requesthandLandmarker = await HandLandmarker.createFromOptions(vision, {baseOptions: {// modelAssetPath: `http://127.0.0.1:8125/assets/static/hand_landmarker.task`, // For AndroidmodelAssetPath: `https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task`, // For Webdelegate: "GPU"},runningMode: runningMode,2 unmodified lines};createHandLandmarker();// const MODEL_PATH = "http://127.0.0.1:8125/assets/static/model.tflite" // For Androidconst MODEL_PATH = "/exported" // For Webvar objectDetector = tflite.loadTFLiteModel(MODEL_PATH);/********************************************************************58 unmodified lines}};// Activate the webcam stream.navigator.mediaDevices.getUserMedia(constraints).then((stream) => {video.srcObject = stream;video.play();video.addEventListener("loadeddata", predictWebcam);}).catch((error) => {console.error("Error accessing the camera: ", error.name, error.message, error.code);});}let lastVideoTime = -1;let results = undefined;334 unmodified lines}</script><script src="https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm/vision_wasm_internal.js"crossorigin="anonymous"></script></body></html>
main.py+1-1
templates/browser-detect.html+102-27