forked from adithya-s-k/omniparse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
88 lines (73 loc) · 2.72 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import warnings
import argparse
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from omniparse import load_omnimodel
from omniparse.documents.router import document_router
from omniparse.media.router import media_router
from omniparse.image.router import image_router
from omniparse.web.router import website_router
from omniparse.demo import demo_ui
# logging.basicConfig(level=logging.DEBUG)
import gradio as gr
warnings.filterwarnings(
"ignore", category=UserWarning
) # Filter torch pytree user warnings
# app = FastAPI(lifespan=lifespan)
app = FastAPI()
# io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers in the main app
app.include_router(document_router, prefix="/parse_document", tags=["Documents"])
app.include_router(image_router, prefix="/parse_image", tags=["Images"])
app.include_router(media_router, prefix="/parse_media", tags=["Media"])
app.include_router(website_router, prefix="/parse_website", tags=["Website"])
app = gr.mount_gradio_app(app, demo_ui, path="")
def main():
# Parse command-line arguments
parser = argparse.ArgumentParser(description="Run the omniparse server.")
parser.add_argument("--host", default="0.0.0.0", help="Host IP address")
parser.add_argument("--port", type=int, default=8000, help="Port number")
parser.add_argument("--documents", action="store_true", help="Load document models")
parser.add_argument("--media", action="store_true", help="Load media models")
parser.add_argument("--web", action="store_true", help="Load web models")
parser.add_argument("--reload", action="store_true", help="Reload Server")
args = parser.parse_args()
# Set global variables based on parsed arguments
load_omnimodel(args.documents, args.media, args.web)
# Conditionally include routers based on arguments
app.include_router(
document_router,
prefix="/parse_document",
tags=["Documents"],
include_in_schema=args.documents,
)
app.include_router(
image_router,
prefix="/parse_image",
tags=["Images"],
include_in_schema=args.documents,
)
app.include_router(
media_router,
prefix="/parse_media",
tags=["Media"],
include_in_schema=args.media,
)
app.include_router(
website_router,
prefix="/parse_website",
tags=["Website"],
include_in_schema=args.web,
)
# Start the server
import uvicorn
uvicorn.run("server:app", host=args.host, port=args.port, reload=args.reload)
if __name__ == "__main__":
main()