import gradio as gr
import re
import subprocess
import argparse
def remove_color_codes(text):
color_pattern = re.compile(r'\x1b\[\d+m')
clean_text = re.sub(color_pattern, '', text)
return clean_text
def to_html(document):
lines = document.split('\n')
formatted_lines = []
for line in lines:
if line.startswith("Error"):
formatted_line = f'{line}'
elif line.startswith("Warning"):
formatted_line = f'{line}'
elif line.startswith("Parsing Error:"):
formatted_line = f'{line}'
elif line == "All Clear!":
formatted_line = f'{line}'
else:
formatted_line = line
formatted_lines.append(formatted_line)
formatted_document = '
'.join(formatted_lines)
return formatted_document
def upload_file(file, paper_type):
command = f"python3 aclpubcheck-main/aclpubcheck/formatchecker.py --paper_type {paper_type} {file.name}"
out = subprocess.run(command, shell=True, stdout=subprocess.PIPE, text=True, stderr=subprocess.STDOUT)
return to_html(remove_color_codes(out.stdout))
with gr.Blocks() as demo:
header = """