Initial commit
Browse files- .gitignore +1 -0
- README.md +6 -5
- app.py +171 -0
- leaderboard.csv +17 -0
- packages.txt +12 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.venv
|
README.md
CHANGED
@@ -1,13 +1,14 @@
|
|
1 |
---
|
2 |
title: Lexoid
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.25.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
|
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: Lexoid
|
3 |
+
emoji: π
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: red
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.25.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
short_description: Try out Lexoid, an efficient document parsing library.
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
import pandas as pd
|
4 |
+
from lexoid.api import parse
|
5 |
+
|
6 |
+
parser_options = ["LLM_PARSE", "STATIC_PARSE", "AUTO"]
|
7 |
+
|
8 |
+
|
9 |
+
# Function to set the environment variables and parse the document
|
10 |
+
def run_parser(
|
11 |
+
file,
|
12 |
+
parser_type,
|
13 |
+
model,
|
14 |
+
pages_per_split,
|
15 |
+
max_processes,
|
16 |
+
as_pdf,
|
17 |
+
x_tolerance,
|
18 |
+
y_tolerance,
|
19 |
+
save_dir,
|
20 |
+
page_nums,
|
21 |
+
router_priority,
|
22 |
+
framework,
|
23 |
+
temperature,
|
24 |
+
depth,
|
25 |
+
google_api_key,
|
26 |
+
openai_api_key,
|
27 |
+
huggingfacehub_api_token,
|
28 |
+
together_api_key,
|
29 |
+
openrouter_api_key,
|
30 |
+
):
|
31 |
+
# Set environment variables
|
32 |
+
os.environ["GOOGLE_API_KEY"] = google_api_key
|
33 |
+
os.environ["OPENAI_API_KEY"] = openai_api_key
|
34 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = huggingfacehub_api_token
|
35 |
+
os.environ["TOGETHER_API_KEY"] = together_api_key
|
36 |
+
os.environ["OPENROUTER_API_KEY"] = openrouter_api_key
|
37 |
+
|
38 |
+
if file is None:
|
39 |
+
return "Please upload a file to parse."
|
40 |
+
|
41 |
+
kwargs = {
|
42 |
+
"model": model,
|
43 |
+
"pages_per_split": pages_per_split,
|
44 |
+
"max_processes": max_processes,
|
45 |
+
"as_pdf": as_pdf,
|
46 |
+
"x_tolerance": x_tolerance,
|
47 |
+
"y_tolerance": y_tolerance,
|
48 |
+
"save_dir": save_dir,
|
49 |
+
"page_nums": (
|
50 |
+
[int(num.strip()) for num in page_nums.split(",")] if page_nums else None
|
51 |
+
),
|
52 |
+
"router_priority": router_priority,
|
53 |
+
"framework": framework,
|
54 |
+
"temperature": temperature,
|
55 |
+
"depth": depth,
|
56 |
+
}
|
57 |
+
|
58 |
+
# Clean None values
|
59 |
+
kwargs = {k: v for k, v in kwargs.items() if v is not None}
|
60 |
+
|
61 |
+
result = parse(path=file.name, parser_type=parser_type, **kwargs)
|
62 |
+
|
63 |
+
if "raw" in result:
|
64 |
+
return result["raw"]
|
65 |
+
elif "segments" in result:
|
66 |
+
return "\n\n".join([seg.get("content", "") for seg in result["segments"]])
|
67 |
+
else:
|
68 |
+
return str(result)
|
69 |
+
|
70 |
+
|
71 |
+
with gr.Blocks(title="Lexoid Document Parser") as app:
|
72 |
+
gr.Markdown(
|
73 |
+
"## π Lexoid Document Parser\nUpload a document and customize how you'd like to parse it."
|
74 |
+
)
|
75 |
+
|
76 |
+
with gr.Row():
|
77 |
+
file_input = gr.File(
|
78 |
+
label="Upload Document",
|
79 |
+
file_types=[".pdf", ".docx", ".html", ".txt"],
|
80 |
+
type="filepath",
|
81 |
+
)
|
82 |
+
parser_type = gr.Dropdown(
|
83 |
+
choices=parser_options, value="AUTO", label="Parser Type"
|
84 |
+
)
|
85 |
+
model_input = gr.Textbox(value="gemini-2.0-flash", label="LLM Model")
|
86 |
+
framework = gr.Textbox(
|
87 |
+
value="pdfplumber",
|
88 |
+
label="Static Framework",
|
89 |
+
placeholder="e.g., pdfplumber, slate",
|
90 |
+
)
|
91 |
+
|
92 |
+
with gr.Accordion("Advanced Options", open=False):
|
93 |
+
pages_per_split = gr.Slider(
|
94 |
+
minimum=1, maximum=20, value=4, step=1, label="Pages per Split"
|
95 |
+
)
|
96 |
+
max_processes = gr.Slider(
|
97 |
+
minimum=1, maximum=16, value=4, step=1, label="Max Parallel Processes"
|
98 |
+
)
|
99 |
+
as_pdf = gr.Checkbox(label="Convert to PDF before parsing")
|
100 |
+
x_tolerance = gr.Number(label="X-axis Tolerance", value=None)
|
101 |
+
y_tolerance = gr.Number(label="Y-axis Tolerance", value=None)
|
102 |
+
save_dir = gr.Textbox(
|
103 |
+
label="Save Directory",
|
104 |
+
placeholder="Path to save intermediate files (optional)",
|
105 |
+
)
|
106 |
+
page_nums = gr.Textbox(
|
107 |
+
label="Page Numbers",
|
108 |
+
placeholder="Comma-separated page numbers (e.g., 1,3,5)",
|
109 |
+
)
|
110 |
+
router_priority = gr.Dropdown(
|
111 |
+
choices=["speed", "accuracy"], value="accuracy", label="Router Priority"
|
112 |
+
)
|
113 |
+
temperature = gr.Number(label="LLM Temperature", value=None)
|
114 |
+
depth = gr.Number(label="Recursive Depth", value=None)
|
115 |
+
|
116 |
+
# Adding the text boxes for the environment variables
|
117 |
+
with gr.Row():
|
118 |
+
google_api_key = gr.Textbox(
|
119 |
+
label="Google API Key", placeholder="Enter Google API Key"
|
120 |
+
)
|
121 |
+
openai_api_key = gr.Textbox(
|
122 |
+
label="OpenAI API Key", placeholder="Enter OpenAI API Key"
|
123 |
+
)
|
124 |
+
huggingfacehub_api_token = gr.Textbox(
|
125 |
+
label="HuggingFaceHub API Token",
|
126 |
+
placeholder="Enter HuggingFaceHub API Token",
|
127 |
+
)
|
128 |
+
together_api_key = gr.Textbox(
|
129 |
+
label="Together API Key", placeholder="Enter Together API Key"
|
130 |
+
)
|
131 |
+
openrouter_api_key = gr.Textbox(
|
132 |
+
label="OpenRouter API Key", placeholder="Enter OpenRouter API Key"
|
133 |
+
)
|
134 |
+
|
135 |
+
output = gr.Markdown(label="Parsed Output")
|
136 |
+
|
137 |
+
parse_button = gr.Button("Parse Document")
|
138 |
+
parse_button.click(
|
139 |
+
fn=run_parser,
|
140 |
+
inputs=[
|
141 |
+
file_input,
|
142 |
+
parser_type,
|
143 |
+
model_input,
|
144 |
+
pages_per_split,
|
145 |
+
max_processes,
|
146 |
+
as_pdf,
|
147 |
+
x_tolerance,
|
148 |
+
y_tolerance,
|
149 |
+
save_dir,
|
150 |
+
page_nums,
|
151 |
+
router_priority,
|
152 |
+
framework,
|
153 |
+
temperature,
|
154 |
+
depth,
|
155 |
+
google_api_key,
|
156 |
+
openai_api_key,
|
157 |
+
huggingfacehub_api_token,
|
158 |
+
together_api_key,
|
159 |
+
openrouter_api_key,
|
160 |
+
],
|
161 |
+
outputs=output,
|
162 |
+
)
|
163 |
+
|
164 |
+
# Leaderboard loaded from leaderboard.csv
|
165 |
+
df = pd.read_csv("leaderboard.csv")
|
166 |
+
leaderboard = gr.Dataframe(
|
167 |
+
value=df,
|
168 |
+
label="Leaderboard",
|
169 |
+
)
|
170 |
+
|
171 |
+
app.launch()
|
leaderboard.csv
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Rank,Model,Mean Similarity,Std. Dev.,Time (s),Cost($)
|
2 |
+
1,gemini-2.0-flash,0.829,0.102,7.41,0.000480
|
3 |
+
2,gemini-2.0-flash-001,0.814,0.176,6.85,0.000421
|
4 |
+
3,gemini-1.5-flash,0.797,0.143,9.54,0.000238
|
5 |
+
4,gemini-2.0-pro-exp,0.764,0.227,11.95,TBA
|
6 |
+
5,gemini-2.0-flash-thinking-exp,0.746,0.266,10.46,TBA
|
7 |
+
6,gemini-1.5-pro,0.732,0.265,11.44,0.003332
|
8 |
+
7,gpt-4o,0.687,0.247,10.16,0.004736
|
9 |
+
8,gpt-4o-mini,0.642,0.213,9.71,0.000275
|
10 |
+
9,gemma-3-27b-it (via OpenRouter),0.628,0.299,18.79,0.000096
|
11 |
+
10,gemini-1.5-flash-8b,0.551,0.223,3.91,0.000055
|
12 |
+
11,Llama-Vision-Free (via Together AI),0.531,0.198,6.93,0
|
13 |
+
12,Llama-3.2-11B-Vision-Instruct-Turbo (via Together AI),0.524,0.192,3.68,0.000060
|
14 |
+
13,qwen/qwen-2.5-vl-7b-instruct (via OpenRouter),0.482,0.209,11.53,0.000052
|
15 |
+
14,Llama-3.2-90B-Vision-Instruct-Turbo (via Together AI),0.461,0.306,19.26,0.000426
|
16 |
+
15,Llama-3.2-11B-Vision-Instruct (via Hugging Face),0.451,0.257,4.54,0
|
17 |
+
16,microsoft/phi-4-multimodal-instruct (via OpenRouter),0.366,0.287,10.80,0.000019
|
packages.txt
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
libnss3-dev
|
2 |
+
libxcomposite1
|
3 |
+
libxcursor1
|
4 |
+
libxdamage1
|
5 |
+
libxi6
|
6 |
+
libxtst6
|
7 |
+
libnss3
|
8 |
+
libxrandr2
|
9 |
+
libasound2
|
10 |
+
libpangocairo-1.0-0
|
11 |
+
libatk1.0-0
|
12 |
+
libgtk-3-0
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
lexoid==0.1.12
|
2 |
+
matplotlib==3.10.1
|