Skip to content

Commit

Permalink
fix: docker compose 启动fastapi
Browse files Browse the repository at this point in the history
  • Loading branch information
lztiancn committed Nov 14, 2024
1 parent 3f24891 commit cb15db1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ RUN /bin/bash -c "source /opt/mineru_venv/bin/activate && \
pip3 install -r /minerugw/requirements-fastapi.txt"

# Set the entry point to activate the virtual environment and run the command line tool
ENTRYPOINT ["/bin/bash", "-c", "source /opt/mineru_venv/bin/activate && exec \"$@\"", "--"]
CMD ["/bin/bash", "-c", "source /opt/mineru_venv/bin/activate && exec \"$@\"", "--"]
19 changes: 4 additions & 15 deletions api/main.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
'''
Author: FutureMeng [email protected]
Date: 2024-11-13 19:44:33
LastEditors: dt_4541218930 abcstorms@163.com
LastEditTime: 2024-11-13 22:36:37
LastEditors: FutureMeng be_loving@163.com
LastEditTime: 2024-11-14 15:47:27
FilePath: \MinerU\scripts\fastapitest.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
from fastapi import FastAPI
import urllib.request
import os
from magic_pdf.pipe.UNIPipe import UNIPipe
from magic_pdf.rw.DiskReaderWriter import DiskReaderWriter
from magic_pdf_parse_util import pdf_parse
from . import magic_pdf_parse_util

app = FastAPI()

current_script_dir = os.path.dirname(os.path.abspath(__file__))
local_image_dir = os.path.join(current_script_dir, 'images')
image_dir = str(os.path.basename(local_image_dir))

@app.get("/hello")
async def hello():
return 'Hello, World'

@app.post("/parse_pdf")
async def parse_pdf(imageUrl: str, parse_method: str = 'auto'):
pdf_bytes = urllib.request.urlopen(imageUrl).read()
content_list, md_content = pdf_parse(pdf_bytes, parse_method)
content_list, md_content = magic_pdf_parse_util.pdf_parse(pdf_bytes, parse_method)
return {"content_list": content_list, "md_content": md_content}
5 changes: 5 additions & 0 deletions api/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
echo "starting miner server"
source /opt/mineru_venv/bin/activate
cd /minerugw
uvicorn app.main:app --host 0.0.0.0 --port 80
14 changes: 10 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
services:
minerugw:
minerugw-02:
build:
context: .
container_name: mineru-gw
container_name: mineru-gw-02
ports:
- "8988:80"
volumes:
- ./api:/minerugw/app:rw
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
environment:
TZ: Asia/Shanghai
#command: /bin/bash -c "source /opt/mineru_venv/bin/activate; cd /minerugw/; uvicorn app.main:app --host 0.0.0.0 --port 80"
command: /bin/bash -c "source /opt/mineru_venv/bin/activate; cd /minerugw/; uvicorn app.main:app --host 0.0.0.0 --port 80"
command: ["/minerugw/app/start.sh"]
restart: always
networks:
- default
Expand Down

0 comments on commit cb15db1

Please sign in to comment.