Julia Ann Live Com -

# ---------------------------------------------------- # 3. WebSocket server (runs forever) # ---------------------------------------------------- function run_ws(port=8081) println("🟢 Julia live ANN server listening on ws://localhost:$port") HTTP.listen(port) do http if WebSockets.isupgrade(http.message) WebSockets.upgrade(http) do ws while !eof(ws) msg = String(read(ws)) resp = try predict(msg) catch e @error "Prediction failed" exception=(e, catch_backtrace()) JSON.json(Dict("error" => string(e))) end write(ws, resp) end end else HTTP.setstatus(http, 400) HTTP.startwrite(http) write(http, "Upgrade to WebSocket required") HTTP.finishwrite(http) end end end

using Flux, CUDA, JSON, WebSockets, HTTP, Revise julia ann live com

# ---------------------------------------------------- # 2. Inference function # ---------------------------------------------------- function predict(json_msg::String) # Expect: "x": [0.1, 0.2, …, 0.128] payload = JSON.parse(json_msg) x = Float32.(payload["x"]) |> gpu y = model(x) # GPU forward pass prob = softmax(y) |> cpu # back to CPU for serialization return JSON.json(Dict("prob" => vec(prob))) end # ---------------------------------------------------- # 3