File size: 2,734 Bytes
3045ff2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6792abf
3045ff2
 
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
import subprocess

import gradio as gr

EXAMPLE_INPUT = """@inproceedings{li-etal-2019-survey,
    title = "A Sophisticated Survey about Chinese Poem and Beers",
    author = "Li, Bai  and
     Ha, Pi  and
     Jin, Shibai  and
     Xue, Hua  and
     Mao, Tai",
    booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP)",
    month = nov,
    year = "2019",
    address = "Hong Kong, China",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/D19-1214",
    doi = "10.18653/v1/D19-1214",
    pages = "2078--2087",
    abstract = "Intent detection and slot filling are two main tasks for building a spoken language understanding (SLU) system. The two tasks are closely tied and the slots often highly depend on the intent. In this paper, we propose a novel framework for SLU to better incorporate the intent information, which further guiding the slot filling. In our framework, we adopt a joint model with Stack-Propagation which can directly use the intent information as input for slot filling, thus to capture the intent semantic knowledge. In addition, to further alleviate the error propagation, we perform the token-level intent detection for the Stack-Propagation framework. Experiments on two publicly datasets show that our model achieves the state-of-the-art performance and outperforms other previous methods by a large margin. Finally, we use the Bidirectional Encoder Representation from Transformer (BERT) model in our framework, which further boost our performance in SLU task.",
}"""


def sim_biber(references: str, keep_keys: str) -> list[str]:
    with open("input.txt", "w") as f:
        f.write(references)
    with open("keep_keys.cfg", "w") as f:
        f.write(keep_keys)
    result = subprocess.run(
        "simbiber -i input.txt -o output.txt",
        shell=True,
        capture_output=True,
        text=True,
    )
    if result.returncode == 0:
        with open("output.txt", "r") as f:
            output = f.read()
        return output, result.stdout
    else:
        return "", result.stderr


demo = gr.Interface(
    fn=sim_biber,
    inputs=[
        gr.Textbox(label="References to be simplified", value=EXAMPLE_INPUT, lines=16),
        gr.Textbox(label="Keep keys", value="booktitle,pages,journal"),
    ],
    outputs=[
        gr.Textbox(label="Simplified References"),
        gr.Textbox(label="Command Line Output"),
    ],
    title="SimBiber",
    description="A tool to simplify bibtex references using SimBiber. Visit https://github.com/MLNLP-World/SimBiber for more information.",
)
demo.launch()