Spaces:
Running
Running
Merge PR #1
Browse files
app.py
CHANGED
|
@@ -6,13 +6,13 @@ import argparse
|
|
| 6 |
|
| 7 |
|
| 8 |
def remove_color_codes(text):
|
| 9 |
-
color_pattern = re.compile(r
|
| 10 |
-
clean_text = re.sub(color_pattern,
|
| 11 |
return clean_text
|
| 12 |
|
| 13 |
|
| 14 |
def to_html(document):
|
| 15 |
-
lines = document.split(
|
| 16 |
formatted_lines = []
|
| 17 |
|
| 18 |
for line in lines:
|
|
@@ -29,22 +29,25 @@ def to_html(document):
|
|
| 29 |
|
| 30 |
formatted_lines.append(formatted_line)
|
| 31 |
|
| 32 |
-
formatted_document =
|
| 33 |
return formatted_document
|
| 34 |
|
|
|
|
| 35 |
def add_images(file_name):
|
| 36 |
html = '<div align="center">'
|
| 37 |
for file in os.listdir("."):
|
| 38 |
if file.startswith(f"errors-{file_name}") and file.endswith(".png"):
|
| 39 |
html += f'<img src="file/{file}">'
|
| 40 |
-
html +=
|
| 41 |
return html
|
| 42 |
|
|
|
|
| 43 |
def clear_cached_images(file_name):
|
| 44 |
for file in os.listdir("."):
|
| 45 |
if file.startswith(f"errors-{file_name}") and file.endswith(".png"):
|
| 46 |
os.remove(file)
|
| 47 |
|
|
|
|
| 48 |
def get_filename(file):
|
| 49 |
file_name = os.path.basename(file).split(".")[0]
|
| 50 |
if "_" in file_name:
|
|
@@ -52,12 +55,15 @@ def get_filename(file):
|
|
| 52 |
file_name = file_name.split("_")[0]
|
| 53 |
return file_name
|
| 54 |
|
|
|
|
| 55 |
def upload_file(file, paper_type):
|
| 56 |
file_name_cmd = file.name.replace(" ", "\ ")
|
| 57 |
file_name = get_filename(file.name)
|
| 58 |
clear_cached_images(file_name)
|
| 59 |
-
command = f"
|
| 60 |
-
out = subprocess.run(
|
|
|
|
|
|
|
| 61 |
return to_html(remove_color_codes(out.stdout)) + add_images(file_name)
|
| 62 |
|
| 63 |
|
|
@@ -69,7 +75,9 @@ with gr.Blocks() as demo:
|
|
| 69 |
</div>
|
| 70 |
"""
|
| 71 |
gr.HTML(header)
|
| 72 |
-
gr.Markdown(
|
|
|
|
|
|
|
| 73 |
dropdown = gr.Dropdown(
|
| 74 |
["long", "short", "demo", "other"], label="Paper type", value="long"
|
| 75 |
)
|
|
@@ -77,16 +85,18 @@ with gr.Blocks() as demo:
|
|
| 77 |
button = gr.Button("Check your PDF!", variant="primary")
|
| 78 |
out = gr.HTML()
|
| 79 |
gr.Markdown(
|
| 80 |
-
"This graphical interface is using the official [aclpubcheck tool](https://github.com/acl-org/aclpubcheck). Check the [Github repo for more information.](https://github.com/teelinsan/aclpubcheck-gui)"
|
|
|
|
| 81 |
gr.Markdown(
|
| 82 |
-
"No data is collected. If you prefer you can also duplicate this Space to run it privately. [](https://huggingface.co/spaces/teelinsan/aclpubcheck?duplicate=true)"
|
|
|
|
| 83 |
|
| 84 |
button.click(upload_file, [file_output, dropdown], out)
|
| 85 |
|
| 86 |
-
if __name__ ==
|
| 87 |
parser = argparse.ArgumentParser()
|
| 88 |
-
parser.add_argument(
|
| 89 |
-
parser.add_argument(
|
| 90 |
args = parser.parse_args()
|
| 91 |
|
| 92 |
-
demo.launch(server_name=args.host, server_port=args.port)
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def remove_color_codes(text):
|
| 9 |
+
color_pattern = re.compile(r"\x1b\[\d+m")
|
| 10 |
+
clean_text = re.sub(color_pattern, "", text)
|
| 11 |
return clean_text
|
| 12 |
|
| 13 |
|
| 14 |
def to_html(document):
|
| 15 |
+
lines = document.split("\n")
|
| 16 |
formatted_lines = []
|
| 17 |
|
| 18 |
for line in lines:
|
|
|
|
| 29 |
|
| 30 |
formatted_lines.append(formatted_line)
|
| 31 |
|
| 32 |
+
formatted_document = "<br>".join(formatted_lines)
|
| 33 |
return formatted_document
|
| 34 |
|
| 35 |
+
|
| 36 |
def add_images(file_name):
|
| 37 |
html = '<div align="center">'
|
| 38 |
for file in os.listdir("."):
|
| 39 |
if file.startswith(f"errors-{file_name}") and file.endswith(".png"):
|
| 40 |
html += f'<img src="file/{file}">'
|
| 41 |
+
html += "</div>"
|
| 42 |
return html
|
| 43 |
|
| 44 |
+
|
| 45 |
def clear_cached_images(file_name):
|
| 46 |
for file in os.listdir("."):
|
| 47 |
if file.startswith(f"errors-{file_name}") and file.endswith(".png"):
|
| 48 |
os.remove(file)
|
| 49 |
|
| 50 |
+
|
| 51 |
def get_filename(file):
|
| 52 |
file_name = os.path.basename(file).split(".")[0]
|
| 53 |
if "_" in file_name:
|
|
|
|
| 55 |
file_name = file_name.split("_")[0]
|
| 56 |
return file_name
|
| 57 |
|
| 58 |
+
|
| 59 |
def upload_file(file, paper_type):
|
| 60 |
file_name_cmd = file.name.replace(" ", "\ ")
|
| 61 |
file_name = get_filename(file.name)
|
| 62 |
clear_cached_images(file_name)
|
| 63 |
+
command = f"aclpubcheck --paper_type {paper_type} {file_name_cmd}"
|
| 64 |
+
out = subprocess.run(
|
| 65 |
+
command, shell=True, stdout=subprocess.PIPE, text=True, stderr=subprocess.STDOUT
|
| 66 |
+
)
|
| 67 |
return to_html(remove_color_codes(out.stdout)) + add_images(file_name)
|
| 68 |
|
| 69 |
|
|
|
|
| 75 |
</div>
|
| 76 |
"""
|
| 77 |
gr.HTML(header)
|
| 78 |
+
gr.Markdown(
|
| 79 |
+
"Drop or upload your paper here to have it checked for [*ACL conferences](https://www.aclweb.org/) guidelines."
|
| 80 |
+
)
|
| 81 |
dropdown = gr.Dropdown(
|
| 82 |
["long", "short", "demo", "other"], label="Paper type", value="long"
|
| 83 |
)
|
|
|
|
| 85 |
button = gr.Button("Check your PDF!", variant="primary")
|
| 86 |
out = gr.HTML()
|
| 87 |
gr.Markdown(
|
| 88 |
+
"This graphical interface is using the official [aclpubcheck tool](https://github.com/acl-org/aclpubcheck). Check the [Github repo for more information.](https://github.com/teelinsan/aclpubcheck-gui)"
|
| 89 |
+
)
|
| 90 |
gr.Markdown(
|
| 91 |
+
"No data is collected. If you prefer you can also duplicate this Space to run it privately. [](https://huggingface.co/spaces/teelinsan/aclpubcheck?duplicate=true)"
|
| 92 |
+
)
|
| 93 |
|
| 94 |
button.click(upload_file, [file_output, dropdown], out)
|
| 95 |
|
| 96 |
+
if __name__ == "__main__":
|
| 97 |
parser = argparse.ArgumentParser()
|
| 98 |
+
parser.add_argument("--host", default="0.0.0.0", type=str)
|
| 99 |
+
parser.add_argument("--port", default=7860, type=int)
|
| 100 |
args = parser.parse_args()
|
| 101 |
|
| 102 |
+
demo.launch(server_name=args.host, server_port=args.port)
|