multimodalart HF staff commited on
Commit
300cc40
1 Parent(s): 020f124

Update script.py

Browse files
Files changed (1) hide show
  1. script.py +9 -1
script.py CHANGED
@@ -25,6 +25,12 @@ def do_train(script_args):
25
  if result.returncode != 0:
26
  raise Exception("Training failed.")
27
 
 
 
 
 
 
 
28
  def do_inference(dataset_name, output_dir, num_tokens):
29
  widget_content = []
30
  try:
@@ -68,7 +74,9 @@ def do_inference(dataset_name, output_dir, num_tokens):
68
 
69
  with open(f'{output_dir}/README.md', 'r') as file:
70
  readme_content = file.read()
71
- readme_content = readme_content.replace(f'{output_dir}', f'{username}/{output_dir}')
 
 
72
 
73
  card = RepoCard(readme_content)
74
  if widget_content:
 
25
  if result.returncode != 0:
26
  raise Exception("Training failed.")
27
 
28
+ def replace_output_dir(text, output_dir, replacement):
29
+ # Define a pattern that matches the output_dir followed by whitespace, '/', new line, or "'"
30
+ # Add system name from HF only in the correct spots
31
+ pattern = rf"{output_dir}(?=[\s/'\n])"
32
+ return re.sub(pattern, replacement, text)
33
+
34
  def do_inference(dataset_name, output_dir, num_tokens):
35
  widget_content = []
36
  try:
 
74
 
75
  with open(f'{output_dir}/README.md', 'r') as file:
76
  readme_content = file.read()
77
+
78
+
79
+ readme_content = replace_output_dir(readme_content, output_dir, f"{username}/{output_dir}")
80
 
81
  card = RepoCard(readme_content)
82
  if widget_content: