Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transcriptions Endpoint - Flask to Node connection #15

Merged
merged 4 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});

110 changes: 110 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
20 changes: 10 additions & 10 deletions backend/src/routes/logRoutes.js
tdanielles marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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;
export default router;
35 changes: 35 additions & 0 deletions backend/src/routes/transcriptionRoutes.js
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 3 additions & 1 deletion transcription/app.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -37,4 +39,4 @@ def transcribe():
return jsonify({"error": str(e)}), 500

if __name__ == "__main__":
app.run(debug=True)
app.run(host='0.0.0.0',port=5000)
Loading