|
import os |
|
|
|
import gradio as gr |
|
import pandas as pd |
|
import pymarc |
|
|
|
from marcai.predict import predict_onnx |
|
from marcai.process import process |
|
from marcai.utils import load_config |
|
from marcai.utils.parsing import record_dict |
|
|
|
demo_dir = os.path.dirname(os.path.realpath(__file__)) |
|
|
|
|
|
def compare(file1, file2): |
|
|
|
record1 = pymarc.parse_xml_to_array(file1)[0] |
|
record2 = pymarc.parse_xml_to_array(file2)[0] |
|
|
|
|
|
df1 = pd.DataFrame.from_dict([record_dict(record1)]) |
|
df2 = pd.DataFrame.from_dict([record_dict(record2)]) |
|
|
|
df = process(df1, df2) |
|
|
|
|
|
config = load_config(os.path.join(demo_dir, "config.yaml")) |
|
|
|
|
|
model_onnx = os.path.join(demo_dir, "model.onnx") |
|
input_df = df[config["model"]["features"]] |
|
prediction = predict_onnx(model_onnx, input_df).item() |
|
|
|
return {"match": prediction, "not match": 1 - prediction} |
|
|
|
|
|
interface = gr.Interface( |
|
fn=compare, |
|
inputs=[gr.File(label="MARC XML File 1"), gr.File(label="MARC XML File 2")], |
|
outputs=gr.Label(label="Classification"), |
|
title="MARC Record Matcher", |
|
description="Upload two MARC XML files with one record each.", |
|
allow_flagging="never", |
|
) |
|
interface.launch() |
|
|