Spaces:
Sleeping
Sleeping
Alexander Sanchez commited on
Commit Β·
f1d274f
1
Parent(s): 563ceb8
name updated
Browse files
app.py
CHANGED
|
@@ -205,7 +205,7 @@ with gr.Blocks(
|
|
| 205 |
# ββ Header ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 206 |
gr.HTML("""
|
| 207 |
<div class="header">
|
| 208 |
-
<h1>RAG CODEX for Historical Spanish
|
| 209 |
<p>RAG system of Spanish correction from the 16th century</p>
|
| 210 |
</div>
|
| 211 |
""")
|
|
@@ -213,31 +213,31 @@ with gr.Blocks(
|
|
| 213 |
with gr.Tabs():
|
| 214 |
|
| 215 |
# ββ PestaΓ±a 1: CorrecciΓ³n βββββββββββββββββββββββββββββββββββββββββββββ
|
| 216 |
-
with gr.TabItem("
|
| 217 |
with gr.Row():
|
| 218 |
with gr.Column(scale=2):
|
| 219 |
htr_input = gr.Textbox(
|
| 220 |
-
label="
|
| 221 |
-
placeholder="
|
| 222 |
lines=6,
|
| 223 |
)
|
| 224 |
with gr.Row():
|
| 225 |
top_k_slider = gr.Slider(
|
| 226 |
minimum=1, maximum=10, value=5, step=1,
|
| 227 |
-
label="
|
| 228 |
)
|
| 229 |
-
show_prompt = gr.Checkbox(label="
|
| 230 |
-
btn_corregir = gr.Button("β¦
|
| 231 |
|
| 232 |
gr.Examples(
|
| 233 |
examples=DEMO_EXAMPLES,
|
| 234 |
inputs=htr_input,
|
| 235 |
-
label="
|
| 236 |
)
|
| 237 |
|
| 238 |
with gr.Column(scale=2):
|
| 239 |
corrected_out = gr.Textbox(
|
| 240 |
-
label="
|
| 241 |
lines=6,
|
| 242 |
interactive=False,
|
| 243 |
)
|
|
@@ -245,12 +245,12 @@ with gr.Blocks(
|
|
| 245 |
|
| 246 |
with gr.Row():
|
| 247 |
with gr.Column():
|
| 248 |
-
docs_out = gr.Markdown(label="
|
| 249 |
with gr.Column():
|
| 250 |
-
analysis_out = gr.Markdown(label="
|
| 251 |
|
| 252 |
-
diff_out = gr.Markdown(label="
|
| 253 |
-
prompt_out = gr.Markdown(label="Prompt
|
| 254 |
|
| 255 |
btn_corregir.click(
|
| 256 |
fn=corregir,
|
|
@@ -259,26 +259,26 @@ with gr.Blocks(
|
|
| 259 |
)
|
| 260 |
|
| 261 |
# ββ PestaΓ±a 2: EvaluaciΓ³n βββββββββββββββββββββββββββββββββββββββββββββ
|
| 262 |
-
with gr.TabItem("
|
| 263 |
-
gr.Markdown("
|
| 264 |
with gr.Row():
|
| 265 |
-
eval_htr = gr.Textbox(label="
|
| 266 |
-
eval_gt = gr.Textbox(label="Groundtruth (
|
| 267 |
-
btn_eval = gr.Button("
|
| 268 |
eval_out = gr.Markdown()
|
| 269 |
btn_eval.click(fn=evaluar_par, inputs=[eval_htr, eval_gt], outputs=eval_out)
|
| 270 |
|
| 271 |
# ββ PestaΓ±a 3: AΓ±adir al corpus βββββββββββββββββββββββββββββββββββββββ
|
| 272 |
-
with gr.TabItem("β
|
| 273 |
-
gr.Markdown("
|
| 274 |
with gr.Row():
|
| 275 |
add_htr = gr.Textbox(label="Texto HTR", lines=4)
|
| 276 |
add_gt = gr.Textbox(label="Groundtruth corregido", lines=4)
|
| 277 |
with gr.Row():
|
| 278 |
-
add_type = gr.Textbox(label="
|
| 279 |
-
add_region = gr.Textbox(label="
|
| 280 |
-
add_date = gr.Textbox(label="
|
| 281 |
-
btn_add = gr.Button("
|
| 282 |
add_out = gr.Markdown()
|
| 283 |
btn_add.click(
|
| 284 |
fn=add_to_corpus,
|
|
@@ -287,9 +287,9 @@ with gr.Blocks(
|
|
| 287 |
)
|
| 288 |
|
| 289 |
# ββ PestaΓ±a 4: Info del sistema βββββββββββββββββββββββββββββββββββββββ
|
| 290 |
-
with gr.TabItem("βΉ
|
| 291 |
gr.Markdown(f"""
|
| 292 |
-
##
|
| 293 |
|
| 294 |
- **Modelo LLM:** {os.getenv('OPENAI_MODEL', 'gpt-4o')}
|
| 295 |
- **Vector store:** ChromaDB (persistente en `{os.getenv('CHROMA_PATH','./chroma_db')}`)
|
|
|
|
| 205 |
# ββ Header ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 206 |
gr.HTML("""
|
| 207 |
<div class="header">
|
| 208 |
+
<h1>RAG CODEX for Historical Spanish</h1>
|
| 209 |
<p>RAG system of Spanish correction from the 16th century</p>
|
| 210 |
</div>
|
| 211 |
""")
|
|
|
|
| 213 |
with gr.Tabs():
|
| 214 |
|
| 215 |
# ββ PestaΓ±a 1: CorrecciΓ³n βββββββββββββββββββββββββββββββββββββββββββββ
|
| 216 |
+
with gr.TabItem(" HTR Correction"):
|
| 217 |
with gr.Row():
|
| 218 |
with gr.Column(scale=2):
|
| 219 |
htr_input = gr.Textbox(
|
| 220 |
+
label="HTR text (recognizer input)",
|
| 221 |
+
placeholder="Paste the HTR result hereβ¦",
|
| 222 |
lines=6,
|
| 223 |
)
|
| 224 |
with gr.Row():
|
| 225 |
top_k_slider = gr.Slider(
|
| 226 |
minimum=1, maximum=10, value=5, step=1,
|
| 227 |
+
label="Documents retrieved (k)",
|
| 228 |
)
|
| 229 |
+
show_prompt = gr.Checkbox(label="Show RAG prompt", value=False)
|
| 230 |
+
btn_corregir = gr.Button("β¦ Correct with RAG", variant="primary")
|
| 231 |
|
| 232 |
gr.Examples(
|
| 233 |
examples=DEMO_EXAMPLES,
|
| 234 |
inputs=htr_input,
|
| 235 |
+
label="Demonstration examples",
|
| 236 |
)
|
| 237 |
|
| 238 |
with gr.Column(scale=2):
|
| 239 |
corrected_out = gr.Textbox(
|
| 240 |
+
label="Corrected text (RAG output)",
|
| 241 |
lines=6,
|
| 242 |
interactive=False,
|
| 243 |
)
|
|
|
|
| 245 |
|
| 246 |
with gr.Row():
|
| 247 |
with gr.Column():
|
| 248 |
+
docs_out = gr.Markdown(label="Documents recovered from the corpus")
|
| 249 |
with gr.Column():
|
| 250 |
+
analysis_out = gr.Markdown(label="Pattern analysis")
|
| 251 |
|
| 252 |
+
diff_out = gr.Markdown(label="Word-by-word differences")
|
| 253 |
+
prompt_out = gr.Markdown(label="Prompt sent to the LLM", visible=False)
|
| 254 |
|
| 255 |
btn_corregir.click(
|
| 256 |
fn=corregir,
|
|
|
|
| 259 |
)
|
| 260 |
|
| 261 |
# ββ PestaΓ±a 2: EvaluaciΓ³n βββββββββββββββββββββββββββββββββββββββββββββ
|
| 262 |
+
with gr.TabItem(" Evaluation with GT"):
|
| 263 |
+
gr.Markdown("Compare the RAG correction against the actual groundtruth to measure CER/WER and detect modernisms.")
|
| 264 |
with gr.Row():
|
| 265 |
+
eval_htr = gr.Textbox(label="HTR text", lines=4)
|
| 266 |
+
eval_gt = gr.Textbox(label="Groundtruth (reference)", lines=4)
|
| 267 |
+
btn_eval = gr.Button("Evaluate", variant="primary")
|
| 268 |
eval_out = gr.Markdown()
|
| 269 |
btn_eval.click(fn=evaluar_par, inputs=[eval_htr, eval_gt], outputs=eval_out)
|
| 270 |
|
| 271 |
# ββ PestaΓ±a 3: AΓ±adir al corpus βββββββββββββββββββββββββββββββββββββββ
|
| 272 |
+
with gr.TabItem("β Add to corpus"):
|
| 273 |
+
gr.Markdown("Add new pairs to the vector store to improve the RAG continuously.")
|
| 274 |
with gr.Row():
|
| 275 |
add_htr = gr.Textbox(label="Texto HTR", lines=4)
|
| 276 |
add_gt = gr.Textbox(label="Groundtruth corregido", lines=4)
|
| 277 |
with gr.Row():
|
| 278 |
+
add_type = gr.Textbox(label="Document type", placeholder="notarial / judicial / eclesiastico")
|
| 279 |
+
add_region = gr.Textbox(label="Region", placeholder="Castilla, AndalucΓaβ¦")
|
| 280 |
+
add_date = gr.Textbox(label="Date", placeholder="1542")
|
| 281 |
+
btn_add = gr.Button("Add to corpus", variant="primary")
|
| 282 |
add_out = gr.Markdown()
|
| 283 |
btn_add.click(
|
| 284 |
fn=add_to_corpus,
|
|
|
|
| 287 |
)
|
| 288 |
|
| 289 |
# ββ PestaΓ±a 4: Info del sistema βββββββββββββββββββββββββββββββββββββββ
|
| 290 |
+
with gr.TabItem("βΉ System"):
|
| 291 |
gr.Markdown(f"""
|
| 292 |
+
## System status
|
| 293 |
|
| 294 |
- **Modelo LLM:** {os.getenv('OPENAI_MODEL', 'gpt-4o')}
|
| 295 |
- **Vector store:** ChromaDB (persistente en `{os.getenv('CHROMA_PATH','./chroma_db')}`)
|