lewtun's picture
lewtun HF staff
Tidy up README
2022859
raw
history blame
1.76 kB
import datetime
import re
import subprocess
from pathlib import Path
import pandas as pd
import typer
SUBMISSION_FILES = ["README.md", "expert.py", "model.pt"]
app = typer.Typer()
def _update_submission_name(submission_name: str):
replacement = ""
with open("README.md", "r") as f:
lines = f.readlines()
for line in lines:
if line.startswith("submission_name:"):
changes = re.sub(r"submission_name:.+", f"submission_name: {submission_name}", line)
replacement += changes
else:
replacement += line
with open("README.md", "w") as f:
f.write(replacement)
@app.command()
def validate():
# Check that all the expected files exist
for file in SUBMISSION_FILES:
if not Path(file).is_file():
raise ValueError(f"File {file} not found! Please include {file} in your submission")
typer.echo("All submission files validated! ✨ πŸš€ ✨")
typer.echo("Now you can make a submission πŸ€—")
@app.command()
def submit(submission_name: str = typer.Option(..., prompt="Please provide a name for your submission, e.g. HuBERT 😁")):
subprocess.call("git pull origin main".split())
_update_submission_name(submission_name)
subprocess.call(["git", "add", "model.pt", "README.md"])
subprocess.call(["git", "commit", "-m", f"Submission: {submission_name} "])
subprocess.call(["git", "push"])
today = datetime.date.today()
# MON = 0, SUN = 6 -> SUN = 0 .. SAT = 6
idx = (today.weekday() + 1) % 7
sun = today + datetime.timedelta(7 - idx)
typer.echo("Submission successful! πŸŽ‰ πŸ₯³ πŸŽ‰")
typer.echo(f"Your submission will be evaulated on {sun:%A %d %B %Y} ⏳")
if __name__ == "__main__":
app()