Commit
·
25c48b5
1
Parent(s):
02c53c0
Update script.py
Browse files
script.py
CHANGED
@@ -18,9 +18,11 @@ def parse_arguments():
|
|
18 |
|
19 |
def do_train(script_args):
|
20 |
# Pass all arguments to trainer.py
|
|
|
21 |
subprocess.run(['python', 'trainer.py'] + script_args)
|
22 |
|
23 |
def do_inference(dataset_name, output_dir, num_tokens):
|
|
|
24 |
dataset = load_dataset(dataset_name)
|
25 |
pipe = AutoPipelineForText2Image.from_pretrained(
|
26 |
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
|
@@ -51,17 +53,19 @@ def do_inference(dataset_name, output_dir, num_tokens):
|
|
51 |
readme_content = file.read()
|
52 |
|
53 |
updated_readme_content = re.sub(r'(widget:\n)(.*?)(?=\n\S+:)', f'\\1{card_string}', readme_content, flags=re.DOTALL)
|
54 |
-
|
55 |
with open('README.md', 'w') as file:
|
56 |
file.write(updated_readme_content)
|
57 |
from huggingface_hub import HfApi
|
58 |
api = HfApi()
|
59 |
username = api.whoami()["name"]
|
|
|
60 |
api.upload_folder(
|
61 |
folder_path=output_dir,
|
62 |
repo_id=f"{username}/{output_dir}",
|
63 |
repo_type="model",
|
64 |
)
|
|
|
65 |
|
66 |
import sys
|
67 |
import argparse
|
@@ -86,7 +90,8 @@ def main():
|
|
86 |
|
87 |
# Proceed with training and inference
|
88 |
do_train(script_args)
|
|
|
89 |
do_inference(args.dataset_name, args.output_dir, args.num_new_tokens_per_abstraction)
|
90 |
-
|
91 |
if __name__ == "__main__":
|
92 |
main()
|
|
|
18 |
|
19 |
def do_train(script_args):
|
20 |
# Pass all arguments to trainer.py
|
21 |
+
print("Starting training...")
|
22 |
subprocess.run(['python', 'trainer.py'] + script_args)
|
23 |
|
24 |
def do_inference(dataset_name, output_dir, num_tokens):
|
25 |
+
print("Starting inference to generate example images...")
|
26 |
dataset = load_dataset(dataset_name)
|
27 |
pipe = AutoPipelineForText2Image.from_pretrained(
|
28 |
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
|
|
|
53 |
readme_content = file.read()
|
54 |
|
55 |
updated_readme_content = re.sub(r'(widget:\n)(.*?)(?=\n\S+:)', f'\\1{card_string}', readme_content, flags=re.DOTALL)
|
56 |
+
print("Images generated!")
|
57 |
with open('README.md', 'w') as file:
|
58 |
file.write(updated_readme_content)
|
59 |
from huggingface_hub import HfApi
|
60 |
api = HfApi()
|
61 |
username = api.whoami()["name"]
|
62 |
+
print("Starting upload...")
|
63 |
api.upload_folder(
|
64 |
folder_path=output_dir,
|
65 |
repo_id=f"{username}/{output_dir}",
|
66 |
repo_type="model",
|
67 |
)
|
68 |
+
print("Upload finished!")
|
69 |
|
70 |
import sys
|
71 |
import argparse
|
|
|
90 |
|
91 |
# Proceed with training and inference
|
92 |
do_train(script_args)
|
93 |
+
print("Training finished!")
|
94 |
do_inference(args.dataset_name, args.output_dir, args.num_new_tokens_per_abstraction)
|
95 |
+
print("All finished!")
|
96 |
if __name__ == "__main__":
|
97 |
main()
|