const express = require("express"); const OpenAI = require("openai"); const cors = require("cors"); require("dotenv").config(); const app = express(); app.use(cors()); app.use(express.json({ limit: "10mb" })); const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); // ---- API: analyze image ---- app.post("/analyze", async (req, res) => { try { const { imageUrl } = req.body; if (!imageUrl) return res.status(400).json({ error: "imageUrl is required" }); const aiRes = await client.chat.completions.create({ model: "gpt-4o-mini", // upgraded: better vision accuracy temperature: 0, response_format: { type: "json_object" }, messages: [ { role: "system", content: "You are a RAM hardware OCR expert. Extract text from RAM module labels and return only valid JSON, no markdown." }, { role: "user", content: [ { type: "text", text: `Read all text on this RAM module label and return JSON: { "modules": [ { "brand": "", "part_number": "", "specs": "", "raw_label": "" } ], "total_modules": }` }, { type: "image_url", image_url: { url: imageUrl, detail: "high" } // request high detail } ] } ] }); const raw = aiRes.choices[0].message.content; const data = JSON.parse(raw); res.json(data); } catch (err) { console.error(err); res.status(500).json({ error: err.message }); } }); // ---- serve UI ---- app.get("/", (_req, res) => { res.send(` RAM OCR Inspector
🔍

RAM OCR Inspector

gpt-4o · high detail
🖥️ Image will appear here
Modules
Raw JSON

Module info will appear after analysis.

// No data yet
Ready
`); }); app.listen(3000, () => console.log("Server running at http://localhost:3000"));