ppppssss commited on
Commit
ba85b94
·
1 Parent(s): 29a787b

Upload ppp.txt

Browse files
Files changed (1) hide show
  1. ppp.txt +70 -0
ppp.txt ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ou aren't part of it already
2
+ !curl -X POST -H 'Authorization: Bearer '$hf_token -H 'Content-Type: application/json' https://huggingface.co/organizations/sd-concepts-library/share/VcLXJtzwwxnHYCkNMLpSJCdnNFZHQwWywv
3
+ images_upload = os.listdir("my_concept")
4
+ image_string = ""
5
+ repo_id = f"sd-concepts-library/{slugify(name_of_your_concept)}"
6
+ for i, image in enumerate(images_upload):
7
+ image_string = f'''{image_string}![{placeholder_token} {i}](https://huggingface.co/{repo_id}/resolve/main/concept_images/{image})
8
+ '''
9
+ if(what_to_teach == "style"):
10
+ what_to_teach_article = f"a `{what_to_teach}`"
11
+ else:#@title Save your newly created concept to the [library of concepts](https://huggingface.co/sd-concepts-library)?
12
+
13
+ save_concept_to_public_library = True #@param {type:"boolean"}
14
+ name_of_your_concept = "tzuyu m" #@param {type:"string"}
15
+ #@markdown `hf_token_write`: leave blank if you logged in with a token with `write access` in the [Initial Setup](#scrollTo=KbzZ9xe6dWwf). If not, [go to your tokens settings and create a write access token](https://huggingface.co/settings/tokens)
16
+ hf_token_write = "" #@param {type:"string"}
17
+
18
+ if(save_concept_to_public_library):
19
+ from slugify import slugify
20
+ from huggingface_hub import HfApi, HfFolder, CommitOperationAdd
21
+ from huggingface_hub import create_repo
22
+ repo_id = f"sd-concepts-library/{slugify(name_of_your_concept)}"
23
+ output_dir = hyperparameters["output_dir"]
24
+ if(not hf_token_write):
25
+ with open(HfFolder.path_token, 'r') as fin: hf_token = fin.read();
26
+ else:
27
+ hf_token = hf_token_write
28
+ #Join the Concepts Library organization if y
29
+ what_to_teach_article = f"an `{what_to_teach}`"
30
+ readme_text = f'''---
31
+ license: mit
32
+ ---
33
+ ### {name_of_your_concept} on Stable Diffusion
34
+ This is the `{placeholder_token}` concept taught to Stable Diffusion via Textual Inversion. You can load this concept into the [Stable Conceptualizer](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/stable_conceptualizer_inference.ipynb) notebook. You can also train your own concepts and load them into the concept libraries using [this notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/sd_textual_inversion_training.ipynb).
35
+
36
+ Here is the new concept you will be able to use as {what_to_teach_article}:
37
+ {image_string}
38
+ '''
39
+ #Save the readme to a file
40
+ readme_file = open("README.md", "w")
41
+ readme_file.write(readme_text)
42
+ readme_file.close()
43
+ #Save the token identifier to a file
44
+ text_file = open("token_identifier.txt", "w")
45
+ text_file.write(placeholder_token)
46
+ text_file.close()
47
+ #Save the type of teached thing to a file
48
+ type_file = open("type_of_concept.txt","w")
49
+ type_file.write(what_to_teach)
50
+ type_file.close()
51
+ operations = [
52
+ CommitOperationAdd(path_in_repo="learned_embeds.bin", path_or_fileobj=f"{output_dir}/learned_embeds.bin"),
53
+ CommitOperationAdd(path_in_repo="token_identifier.txt", path_or_fileobj="token_identifier.txt"),
54
+ CommitOperationAdd(path_in_repo="type_of_concept.txt", path_or_fileobj="type_of_concept.txt"),
55
+ CommitOperationAdd(path_in_repo="README.md", path_or_fileobj="README.md"),
56
+ ]
57
+ create_repo(repo_id,private=True, token=hf_token)
58
+ api = HfApi()
59
+ api.create_commit(
60
+ repo_id=repo_id,
61
+ operations=operations,
62
+ commit_message=f"Upload the concept {name_of_your_concept} embeds and token",
63
+ token=hf_token
64
+ )
65
+ api.upload_folder(
66
+ folder_path=save_path,
67
+ path_in_repo="concept_images",
68
+ repo_id=repo_id,
69
+ token=hf_token
70
+ )