CoolFace
Apppublic

stevafernandes/Fine-Tuning-HunyuanOCR

sourceHugging Faceapache-2.0updated 1mo agoView on Hugging Face
0likes
ui.py110 linesDownload Raw Back to root
1"""Gradio interface definition for the MuseumSCAT transcription app.2 3Kept separate from app.py so the layout can be built and tested without4loading model weights.5"""6 7import gradio as gr8 9CSS = """10.gradio-container {11    background: #ffffff !important;12    color: #000000 !important;13    max-width: 980px !important;14    margin: 0 auto !important;15    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;16}17#header h1 {18    color: #000000;19    font-size: 1.45rem;20    font-weight: 600;21    margin: 0 0 0.3rem 0;22}23#header p {24    color: #222222;25    font-size: 0.95rem;26    margin: 0 0 1.2rem 0;27    line-height: 1.5;28}29#header {30    border-bottom: 1px solid #000000;31    padding: 1.2rem 0 1rem 0;32    margin-bottom: 1.2rem;33}34.block, .form, .panel, fieldset {35    background: #ffffff !important;36    border-color: #d9d9d9 !important;37}38label span, .label-wrap span {39    color: #000000 !important;40}41input, textarea {42    background: #ffffff !important;43    color: #000000 !important;44    border: 1px solid #bbbbbb !important;45}46input:disabled, textarea:disabled {47    color: #000000 !important;48    -webkit-text-fill-color: #000000 !important;49    opacity: 1 !important;50}51button.primary {52    background: #000000 !important;53    color: #ffffff !important;54    border: 1px solid #000000 !important;55    border-radius: 3px !important;56    box-shadow: none !important;57}58button.primary:hover {59    background: #333333 !important;60}61footer { display: none !important; }62"""63 64HEADER_HTML = (65    "<div id='header'>"66    "<h1>MuseumSCAT Label Transcription</h1>"67    "<p>HunyuanOCR-1.5 fine-tuned on specimen labels from the Natural History Museum "68    "of Denmark dung beetle collection. Upload a specimen image to extract the "69    "collection date and locality exactly as written on its labels. Fields that are "70    "not present are reported as MISSING, and each field includes a model confidence "71    "between 0 and 1.</p>"72    "</div>"73)74 75 76def build_demo(transcribe_fn):77    theme = gr.themes.Base(78        primary_hue=gr.themes.colors.neutral,79        neutral_hue=gr.themes.colors.neutral,80    ).set(81        body_background_fill="#ffffff",82        body_text_color="#000000",83        block_background_fill="#ffffff",84        block_label_text_color="#000000",85        block_title_text_color="#000000",86        input_background_fill="#ffffff",87    )88    with gr.Blocks(css=CSS, title="MuseumSCAT Label Transcription", theme=theme) as demo:89        gr.HTML(HEADER_HTML)90        with gr.Row():91            with gr.Column(scale=1):92                image_input = gr.Image(type="pil", label="Specimen image")93                run_button = gr.Button("Transcribe", variant="primary")94            with gr.Column(scale=1):95                with gr.Row():96                    date_output = gr.Textbox(label="verbatimDate", interactive=False, scale=3)97                    date_conf_output = gr.Textbox(label="Confidence", interactive=False, scale=1)98                with gr.Row():99                    locality_output = gr.Textbox(label="verbatimLocality", interactive=False, scale=3)100                    locality_conf_output = gr.Textbox(label="Confidence", interactive=False, scale=1)101                raw_output = gr.Textbox(label="Raw model output", interactive=False, lines=3)102 103        run_button.click(104            transcribe_fn,105            inputs=[image_input],106            outputs=[date_output, date_conf_output, locality_output, locality_conf_output, raw_output],107            api_name="transcribe",108        )109    return demo110