teelinsan commited on
Commit
a5044c6
1 Parent(s): 8ac92f5

Add display images

Browse files
Files changed (1) hide show
  1. app.py +22 -7
app.py CHANGED
@@ -1,8 +1,10 @@
1
  import gradio as gr
2
  import re
 
3
  import subprocess
4
  import argparse
5
 
 
6
  def remove_color_codes(text):
7
  color_pattern = re.compile(r'\x1b\[\d+m')
8
  clean_text = re.sub(color_pattern, '', text)
@@ -30,12 +32,26 @@ def to_html(document):
30
  formatted_document = '<br>'.join(formatted_lines)
31
  return formatted_document
32
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  def upload_file(file, paper_type):
35
- file_name = file.name.replace(" ", "\ ")
36
- command = f"python3 aclpubcheck-main/aclpubcheck/formatchecker.py --paper_type {paper_type} {file_name}"
 
 
37
  out = subprocess.run(command, shell=True, stdout=subprocess.PIPE, text=True, stderr=subprocess.STDOUT)
38
- return to_html(remove_color_codes(out.stdout))
39
 
40
 
41
  with gr.Blocks() as demo:
@@ -48,8 +64,8 @@ with gr.Blocks() as demo:
48
  gr.HTML(header)
49
  gr.Markdown("Drop or upload your paper here to have it checked for [*ACL conferences](https://www.aclweb.org/) guidelines.")
50
  dropdown = gr.Dropdown(
51
- ["long", "short", "demo", "other"], label="Paper type", value="long"
52
- )
53
  file_output = gr.File(file_types=[".pdf"])
54
  button = gr.Button("Check your PDF!", variant="primary")
55
  out = gr.HTML()
@@ -57,9 +73,8 @@ with gr.Blocks() as demo:
57
  "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)")
58
  gr.Markdown(
59
  "No data is collected. If you prefer you can also duplicate this Space to run it privately. [![Duplicate Space](https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14)](https://huggingface.co/spaces/teelinsan/aclpubcheck?duplicate=true)")
60
-
61
- button.click(upload_file, [file_output, dropdown], out)
62
 
 
63
 
64
  if __name__ == '__main__':
65
  parser = argparse.ArgumentParser()
 
1
  import gradio as gr
2
  import re
3
+ import os
4
  import subprocess
5
  import argparse
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)
 
32
  formatted_document = '<br>'.join(formatted_lines)
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 += '</div>'
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 upload_file(file, paper_type):
49
+ file_name_cmd = file.name.replace(" ", "\ ")
50
+ file_name = os.path.basename(file.name).split(".")[0]
51
+ clear_cached_images(file_name)
52
+ command = f"python3 aclpubcheck-main/aclpubcheck/formatchecker.py --paper_type {paper_type} {file_name_cmd}"
53
  out = subprocess.run(command, shell=True, stdout=subprocess.PIPE, text=True, stderr=subprocess.STDOUT)
54
+ return to_html(remove_color_codes(out.stdout)) + add_images(file_name)
55
 
56
 
57
  with gr.Blocks() as demo:
 
64
  gr.HTML(header)
65
  gr.Markdown("Drop or upload your paper here to have it checked for [*ACL conferences](https://www.aclweb.org/) guidelines.")
66
  dropdown = gr.Dropdown(
67
+ ["long", "short", "demo", "other"], label="Paper type", value="long"
68
+ )
69
  file_output = gr.File(file_types=[".pdf"])
70
  button = gr.Button("Check your PDF!", variant="primary")
71
  out = gr.HTML()
 
73
  "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)")
74
  gr.Markdown(
75
  "No data is collected. If you prefer you can also duplicate this Space to run it privately. [![Duplicate Space](https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14)](https://huggingface.co/spaces/teelinsan/aclpubcheck?duplicate=true)")
 
 
76
 
77
+ button.click(upload_file, [file_output, dropdown], out)
78
 
79
  if __name__ == '__main__':
80
  parser = argparse.ArgumentParser()