diff --git a/backend/index.js b/backend/index.js index fddd630d..0284af06 100644 --- a/backend/index.js +++ b/backend/index.js @@ -3,23 +3,26 @@ import dotenv from "dotenv"; import express from "express"; import authRoutes from "./src/routes/authRoutes.js"; import logRoutes from "./src/routes/logRoutes.js"; +import transcriptionRoutes from "./src/routes/transcriptionRoutes.js"; +import fileUpload from "express-fileupload"; dotenv.config(); const corsOptions = { - origin: ["http://localhost:5173"], + origin: ["http://localhost:5173"], }; const app = express(); const PORT = process.env.PORT || 8080; app.use(cors(corsOptions)); app.use(express.json()); +app.use(fileUpload()); //Routes -app.use('/api/auth', authRoutes); -app.use('/api/log', logRoutes); +app.use("/api/auth", authRoutes); +app.use("/api/log", logRoutes); +app.use("/api/transcriptions", transcriptionRoutes); app.listen(PORT, () => { - console.log(`Server listening on ${PORT}`); + console.log(`Server listening on ${PORT}`); }); - diff --git a/backend/package-lock.json b/backend/package-lock.json index f85c7b95..6f56cc3a 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -10,9 +10,11 @@ "license": "ISC", "dependencies": { "@supabase/supabase-js": "^2.46.1", + "axios": "^1.7.8", "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.21.0", + "express-fileupload": "^1.5.1", "jsonwebtoken": "^9.0.2", "supabase": "^1.207.9" }, @@ -3008,6 +3010,36 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/axios": { + "version": "1.7.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.8.tgz", + "integrity": "sha512-Uu0wb7KNqK2t5K+YQyVCLM76prD5sRFjKHbJYCP1J7JFGEQ6nN7HWn9+04LAeiJ3ji54lgS/gZCH1oxyrf1SPw==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -3315,6 +3347,17 @@ "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", "dev": true }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -3511,6 +3554,18 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz", @@ -3692,6 +3747,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -4180,6 +4244,18 @@ "node": ">= 0.10.0" } }, + "node_modules/express-fileupload": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/express-fileupload/-/express-fileupload-1.5.1.tgz", + "integrity": "sha512-LsYG1ALXEB7vlmjuSw8ABeOctMp8a31aUC5ZF55zuz7O2jLFnmJYrCv10py357ky48aEoBQ/9bVXgFynjvaPmA==", + "license": "MIT", + "dependencies": { + "busboy": "^1.6.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/express/node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -4353,6 +4429,26 @@ "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/foreground-child": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz", @@ -6466,6 +6562,12 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" + }, "node_modules/pstree.remy": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", @@ -7038,6 +7140,14 @@ "node": ">= 0.8" } }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/string-length": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz", diff --git a/backend/package.json b/backend/package.json index b593bde9..64457144 100644 --- a/backend/package.json +++ b/backend/package.json @@ -15,9 +15,11 @@ "description": "", "dependencies": { "@supabase/supabase-js": "^2.46.1", + "axios": "^1.7.8", "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.21.0", + "express-fileupload": "^1.5.1", "jsonwebtoken": "^9.0.2", "supabase": "^1.207.9" }, diff --git a/backend/src/routes/logRoutes.js b/backend/src/routes/logRoutes.js index 4f7bca2f..e6955084 100644 --- a/backend/src/routes/logRoutes.js +++ b/backend/src/routes/logRoutes.js @@ -1,17 +1,17 @@ import express from "express"; import auth from "../middlewares/auth.js"; -import insertTable from "../services/cardiacSurgeryAdultService.js" +import insertTable from "../services/cardiacSurgeryAdultService.js"; const router = express.Router(); router.post("/cardiacSurgeryAdultService", auth, async (req, res) => { - try { - const result = await insertTable(req, res); - res.json(result); - } catch(error) { - console.error("Caught Error:", error.message); - res.status(500).json({message: error.message}); - } -}) + try { + const result = await insertTable(req, res); + res.json(result); + } catch (error) { + console.error("Caught Error:", error.message); + res.status(500).json({ message: error.message }); + } +}); -export default router; \ No newline at end of file +export default router; diff --git a/backend/src/routes/transcriptionRoutes.js b/backend/src/routes/transcriptionRoutes.js new file mode 100644 index 00000000..fac5d1fb --- /dev/null +++ b/backend/src/routes/transcriptionRoutes.js @@ -0,0 +1,35 @@ +import axios from "axios"; +import FormData from "form-data"; +import express from "express"; +import auth from "../middlewares/auth.js"; + +const router = express.Router(); + +router.post("/", auth, async (req, res) => { + try { + if (!req.files || !req.files.image) { + return res.status(400).json({ error: "No image file provided" }); + } + + const imageFile = req.files.image; + const formData = new FormData(); + formData.append("image", imageFile.data, imageFile.name); + + const response = await axios.post( + "http://localhost:5000/transcribe", + formData, + { + headers: { + ...formData.getHeaders(), + }, + } + ); + + res.json(response.data); + } catch (error) { + console.error("Caught Error:", error.message); + res.status(500).json({ message: error.message }); + } +}); + +export default router; diff --git a/transcription/app.py b/transcription/app.py index bff6161e..d4b1947f 100644 --- a/transcription/app.py +++ b/transcription/app.py @@ -1,9 +1,11 @@ from flask import Flask, request, jsonify +from flask_cors import CORS from PIL import Image from transformers import AutoProcessor, AutoModelForCausalLM import torch app = Flask(__name__) +CORS(app) # load model and processor once during init device = "cuda:0" if torch.cuda.is_available() else "cpu" @@ -37,4 +39,4 @@ def transcribe(): return jsonify({"error": str(e)}), 500 if __name__ == "__main__": - app.run(debug=True) \ No newline at end of file + app.run(host='0.0.0.0',port=5000) \ No newline at end of file