Hugo-Persson / obsidian-ocrlatex

This is a plugin for obsidian that will read your latest copied image from clipboard and generate math latex from it
MIT License
24 stars 3 forks source link

add support for self hosting #7

Closed Marlon154 closed 8 months ago

Marlon154 commented 8 months ago

Support for pix2tex docker image as backend. Simply run the container activate and set the url in the Obsidian settings to get started.

Hugo-Persson commented 8 months ago

Thank you for your submission @Marlon154 !

I will look into the code and test tonight, could you add some information to the README on how you run the docker container for pic2tex or link to their documentation?

Hugo-Persson commented 8 months ago

I meant change the README.md, not adding a README.html

Marlon154 commented 8 months ago

sorry, selected to wrong file for the commit.

Hugo-Persson commented 8 months ago

@Marlon154 how are you running the docker container? I am getting the error

Traceback (most recent call last):
  File "/usr/local/bin/uvicorn", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/uvicorn/main.py", line 437, in main
    run(app, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/uvicorn/main.py", line 463, in run
    server.run()
  File "/usr/local/lib/python3.8/site-packages/uvicorn/server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/usr/local/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "uvloop/loop.pyx", line 1501, in uvloop.loop.Loop.run_until_complete
  File "/usr/local/lib/python3.8/site-packages/uvicorn/server.py", line 67, in serve
    config.load()
  File "/usr/local/lib/python3.8/site-packages/uvicorn/config.py", line 458, in load
    self.loaded_app = import_from_string(self.app)
  File "/usr/local/lib/python3.8/site-packages/uvicorn/importer.py", line 24, in import_from_string
    raise exc from None
  File "/usr/local/lib/python3.8/site-packages/uvicorn/importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/latexocr/./pix2tex/api/app.py", line 7, in <module>
    from pix2tex.cli import LatexOCR
  File "/latexocr/./pix2tex/cli.py", line 1, in <module>
    from pix2tex.dataset.transforms import test_transform
  File "/latexocr/./pix2tex/dataset/transforms.py", line 2, in <module>
    from albumentations.pytorch import ToTensorV2
  File "/usr/local/lib/python3.8/site-packages/albumentations/pytorch/__init__.py", line 3, in <module>
    from .transforms import *
  File "/usr/local/lib/python3.8/site-packages/albumentations/pytorch/transforms.py", line 6, in <module>
    import torch
  File "/usr/local/lib/python3.8/site-packages/torch/__init__.py", line 199, in <module>
    from torch._C import *  # noqa: F403
ImportError: libtorch_cpu.so: cannot enable executable stack as shared object requires: Invalid argument
Marlon154 commented 8 months ago

I run the container just with

docker pull lukasblecher/pix2tex:api
docker run --rm -p 8502:8502 lukasblecher/pix2tex:api

Are you on a ARM CPU?

Hugo-Persson commented 8 months ago

I run the container just with

docker pull lukasblecher/pix2tex:api
docker run --rm -p 8502:8502 lukasblecher/pix2tex:api

Are you on a ARM CPU?

Yes @Marlon154 , I am on M3 pro

Hugo-Persson commented 8 months ago

I could try Linux later, but would nice to be able to run on my M3 Macbook Pro

Hugo-Persson commented 8 months ago

@Marlon154 I ran pic2tex directly without docker but I only get

INFO:     127.0.0.1:61521 - "POST /predict HTTP/1.1" 307 Temporary Redirect

My options look like this:

image

With the url: http://127.0.0.1:8502/predict

How have you configured your settings?

Marlon154 commented 8 months ago

Seems like you have different ports. Also the final '/' is relevant (http://localhost:8502/predict/).

Hugo-Persson commented 8 months ago

Nice the end / fixed it for me @Marlon154, I am going to add check for it. Great job with the feature, it works great for me!