lucasvanmol / obsidian-latex-ocr

Generate LaTeX equations from images in your clipboard or vault
GNU General Public License v3.0
79 stars 3 forks source link

[Feature] Add IP option in local inference #29

Open mariokhz opened 1 week ago

mariokhz commented 1 week ago

I have a fedora "server" with a NVidia GPU, and I use it for some stuff, like Obsidian Sync, Discord bots, etc.

I'd love the option to run latex-ocr-server in my server and connect to my server IP instead of running it locally in my work laptop (which is not really powerful). So, instead of giving it the python path for running the server and connecting to it, you would give the IP to connect.

Thank you! :)

lucasvanmol commented 1 week ago

Hi, that sounds like a really good idea, that could integrate well with the plugin. Unfortunately I don't have much time to develop something like this at the moment (maybe in a couple of weeks I could take a stab at it).

I'd definitely be open to pull requests for this, though. Probably the best way would be to have models/local_model.ts support using strings other than localhost here:

async load() {
        // RPC Client
        console.log(`latex_ocr: initializing RPC client at port ${this.plugin_settings.port}`)
        this.client = new LatexOCRClient(`localhost:${this.plugin_settings.port}`, grpc.credentials.createInsecure())

        // LatexOCR Python Server
        if (this.plugin_settings.startServerOnLoad) {
            this.startServer()
        }
    }

and then don't do any of the spawnServer stuff. You'd probably want to add a setting in settings.ts to be able to supply the url too, if you don't want to run on localhost.

mariokhz commented 6 days ago

Hi! Thanks for your reply! I've added a setting to write a URL, and I could connect to my server. Unfortunately, as the generatelatex function uses an image filepath string, my server can't find the image.

I don't know how to figure this out; maybe adding sftp://hostname could work for me, but even then it would be too specific.

lucasvanmol commented 6 days ago

Thanks for trying this out!

It looks like latex-ocr-server would need an update to allow for passing in an image as bytes as well, meaning the protobuf would need to be updated, which could pretty much just be the existing function. Sorry, the docs here are a bit lacking and I'm in the middle of exams right now so I won't have much time to properly look into this until November.

mariokhz commented 5 days ago

Buenas otra vez, Lucas :)

I can't compile the .proto in neither Python nor TypeScript. I will read the protobuf docs, and maybe I find out how. For now, if I try to compile it myself, I end up with import issues in both Python Server side and building the Obsidian Plugin. I've never done something like this, but I'd really love to have this feature.

For the .proto, the change is small message LatexRequest { string image_path = 1; } to message LatexRequest { bytes image_bytes = 1; }