(Bill) Yuchen Lin commited on
Commit
4835e80
1 Parent(s): 668ce62

update the web design

Browse files
Files changed (1) hide show
  1. app.py +81 -12
app.py CHANGED
@@ -2,24 +2,36 @@ import gradio as gr
2
  import rebiber
3
  import os
4
  import uuid
5
-
6
 
7
 
8
  # Load Bib Database
9
  filepath = os.path.abspath(rebiber.__file__).replace("__init__.py","")
10
  bib_list_path = os.path.join(filepath, "bib_list.txt")
11
- bib_db = rebiber.construct_bib_db(bib_list_path, start_dir=filepath)
12
 
 
13
 
 
14
 
15
 
16
- def process(input_bib):
 
 
 
 
17
  random_id = uuid.uuid4().hex
18
  with open(f"input_{random_id}.bib", "w") as f:
19
  f.write(input_bib.replace("\t", " "))
20
  all_bib_entries = rebiber.load_bib_file(f"input_{random_id}.bib")
21
  print("# Input Bib Entries:", len(all_bib_entries))
22
- rebiber.normalize_bib(bib_db, all_bib_entries, f"output_{random_id}.bib")
 
 
 
 
 
 
 
23
  with open(f"output_{random_id}.bib") as f:
24
  output_bib = f.read().replace("\n ", "\n ")
25
  # delete both files
@@ -34,23 +46,80 @@ example_input = """
34
  journal={arXiv preprint arXiv:2005.00683},
35
  year={2020}
36
  }
 
37
  """
38
 
39
  examples = [[example_input]]
40
 
41
 
42
- iface = gr.Interface(fn=process,
43
- inputs=gr.inputs.Textbox(lines=30, label="Input BIB"),
44
- outputs=gr.outputs.Textbox(label="Output BIB").style(show_copy_button=True),
45
- examples=examples,
46
- allow_flagging="never"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  )
48
-
49
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
 
52
  if __name__ == "__main__":
53
- iface.launch()
54
 
55
 
56
  """
 
2
  import rebiber
3
  import os
4
  import uuid
 
5
 
6
 
7
  # Load Bib Database
8
  filepath = os.path.abspath(rebiber.__file__).replace("__init__.py","")
9
  bib_list_path = os.path.join(filepath, "bib_list.txt")
10
+ abbr_tsv_path = os.path.join(filepath, "abbr.tsv")
11
 
12
+ bib_db = rebiber.construct_bib_db(bib_list_path, start_dir=filepath)
13
 
14
+ abbr_dict = rebiber.normalize.load_abbr_tsv(abbr_tsv_path)
15
 
16
 
17
+ def process(input_bib, shorten, remove_keys, deduplicate, sort):
18
+ if "@" not in input_bib:
19
+ return "N/A"
20
+ global abbr_dict
21
+ # print(f"remove_keys={remove_keys}")
22
  random_id = uuid.uuid4().hex
23
  with open(f"input_{random_id}.bib", "w") as f:
24
  f.write(input_bib.replace("\t", " "))
25
  all_bib_entries = rebiber.load_bib_file(f"input_{random_id}.bib")
26
  print("# Input Bib Entries:", len(all_bib_entries))
27
+ abbr_dict_pass = []
28
+ if shorten:
29
+ abbr_dict_pass = abbr_dict
30
+ rebiber.normalize_bib(bib_db, all_bib_entries, f"output_{random_id}.bib",
31
+ abbr_dict=abbr_dict_pass,
32
+ deduplicate=deduplicate,
33
+ sort=sort,
34
+ removed_value_names=remove_keys)
35
  with open(f"output_{random_id}.bib") as f:
36
  output_bib = f.read().replace("\n ", "\n ")
37
  # delete both files
 
46
  journal={arXiv preprint arXiv:2005.00683},
47
  year={2020}
48
  }
49
+
50
  """
51
 
52
  examples = [[example_input]]
53
 
54
 
55
+ # iface = gr.Interface(fn=process,
56
+ # inputs=gr.inputs.Textbox(lines=30, label="Input BIB"),
57
+ # outputs=gr.outputs.Textbox(label="Output BIB").style(show_copy_button=True),
58
+ # examples=examples,
59
+ # allow_flagging="never"
60
+ # )
61
+
62
+
63
+
64
+
65
+
66
+ with gr.Blocks() as demo:
67
+
68
+ gr.Markdown(
69
+ '''# Rebiber: A tool for normalizing bibtex with official info.
70
+
71
+ <table>
72
+ <tr>
73
+ <td>
74
+ <a href="https://yuchenlin.xyz/">
75
+ <img src="https://img.shields.io/badge/Yuchen%20Lin-🐼-white?style=social">
76
+ </a>
77
+ </td>
78
+ <td>
79
+ <a href="https://github.com/yuchenlin/rebiber">
80
+ <img src="https://img.shields.io/badge/Github--blue?style=social&logo=github">
81
+ </a>
82
+ </td>
83
+ <td>
84
+ <a href="https://twitter.com/billyuchenlin/status/1353850378438070272?s=20">
85
+ <img src="https://img.shields.io/badge/Tweet--blue?style=social&logo=twitter">
86
+ </a>
87
+ </td>
88
+ </tr>
89
+ </table>
90
+
91
+ We often cite papers using their arXiv versions without noting that they are already __PUBLISHED__ in some conferences. These unofficial bib entries might violate rules about submissions or camera-ready versions for some conferences.
92
+ We introduce __Rebiber__, a simple tool in Python to fix them automatically. It is based on the official conference information from the [DBLP](https://dblp.org/) or [the ACL anthology](https://www.aclweb.org/anthology/) (for NLP conferences)!
93
+ Apart from handling outdated arXiv citations, __Rebiber__ also normalizes citations in a unified way (DBLP-style), supporting abbreviation and value selection.
94
+ Note that you can copy the output bib file by clicking the top-right button.
95
+ '''
96
  )
97
+
98
+ with gr.Row():
99
+ with gr.Column(scale=3):
100
+ input_bib = gr.Textbox(lines=20, label="Input BIB", value=example_input, interactive=True)
101
+ removekeys = gr.CheckboxGroup(["url", "biburl", "address", "publisher", "pages", "doi", "volume", "bibsource"],
102
+ value=[False, False, False, False, False, False, False, False],
103
+ label="Remove Keys", info="Which keys to remove?")
104
+ shorten = gr.Checkbox(label="Abbreviation", info="Shorten the conference/journal names (e.g., `Proceedings of the 2020 International Conference of ...` --> `Proc. of ICML')", value=False)
105
+ dedup = gr.Checkbox(label="Deduplicate entries.", value=False)
106
+ sort = gr.Checkbox(label="Sort alphabetically by ID.", value=False)
107
+ button = gr.Button("Submit")
108
+ with gr.Column(scale=3):
109
+ output=gr.outputs.Textbox(label="Output BIB").style(show_copy_button=True, interactive=True)
110
+ button.click(process, inputs=[input_bib, shorten, removekeys, dedup, sort], outputs=output, api_name = "process")
111
+
112
+ # gr.Interface(fn=process,
113
+ # outputs=gr.outputs.Textbox(label="Output BIB").style(show_copy_button=True),
114
+ # examples=examples,
115
+ # allow_flagging="never",
116
+ # scroll_to_output=True,
117
+ # show_progress=True,
118
+ # )
119
 
120
 
121
  if __name__ == "__main__":
122
+ demo.launch()
123
 
124
 
125
  """