Next7years commited on
Commit
9366435
1 Parent(s): 5c3f0cc
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import gradio as gr
2
- from datasets import load_dataset
3
  from PIL import Image
4
  import re
5
  import os
@@ -14,13 +13,13 @@ from share_btn import community_icon_html, loading_icon_html, share_js
14
 
15
 
16
  model_id = "Next7years/stable-diffusion-v1-5-CatHeiHei-v1"
17
- device = "cuda"
18
- #device = "cpu"
19
 
20
  #word_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt", use_auth_token=True)
21
  #word_list = word_list_dataset["train"]['text']
22
 
23
-
24
  is_gpu_busy = False
25
  '''
26
  def infer(prompt):
@@ -46,12 +45,14 @@ def infer(prompt):
46
  def infer(prompt):
47
  samples = 4
48
  steps = 50
49
- scale = 7.5
50
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
51
- #pipe = StableDiffusionPipeline.from_pretrained(model_id, device='cpu')
 
 
52
  pipe = pipe.to(device)
53
  images = []
54
- results = pipe(prompt, num_images_per_prompt=samples, num_inference_steps=steps, guidance_scale=scale).images
55
  print(results)
56
  for image in results:
57
  jpeg_image = io.BytesIO()
@@ -187,42 +188,27 @@ css = """
187
 
188
  block = gr.Blocks(css=css)
189
 
190
- examples = [
191
- [
192
- 'The spirit of a tamagotchi wandering in the city of Paris',
193
- # 4,
194
- # 45,
195
- # 7.5,
196
- # 1024,
197
- ],
198
- [
199
- 'A delicious ceviche cheesecake slice',
200
- # 4,
201
- # 45,
202
- # 7,
203
- # 1024,
204
- ],
205
- [
206
- 'A pao de queijo foodcart in front of a japanese castle',
207
- # 4,
208
- # 45,
209
- # 7,
210
- # 1024,
211
- ],
212
- [
213
- 'alone in the amusement park by Edward Hopper',
214
- # 4,
215
- # 45,
216
- # 7,
217
- # 1024,
218
- ],
219
- [
220
- "A large cabin on top of a sunny mountain in the style of Dreamworks, artstation",
221
- # 4,
222
- # 45,
223
- # 7,
224
- # 1024,
225
- ],
226
  ]
227
 
228
 
@@ -238,14 +224,21 @@ with block:
238
  font-size: 1.75rem;
239
  "
240
  >
241
- <h1 style="font-weight: 900; margin-bottom: 7px;">
242
- CatHeiHei Stable Diffusion v1.5 Model
243
  </h1>
244
  </div>
245
- <p style="margin-bottom: 10px; font-size: 94%">
246
- Stable Diffusion v1-5 is the latest version of the state of the art text-to-image model.<br>For faster generation you can try
247
- <a href="https://app.runwayml.com/ai-tools/text-to-image"
248
- style="text-decoration: underline;" target="_blank">text to image tool at Runway.</a>
 
 
 
 
 
 
 
249
  </p>
250
  </div>
251
  """
@@ -296,7 +289,7 @@ with block:
296
  randomize=True,
297
  )
298
 
299
- ex = gr.Examples(examples=examples, fn=infer, inputs=text, outputs=[gallery], cache_examples=False, postprocess=False)
300
  ex.dataset.headers = [""]
301
 
302
  text.submit(infer, inputs=text, outputs=[gallery], postprocess=False)
@@ -320,16 +313,15 @@ with block:
320
  )
321
  gr.HTML(
322
  """
323
- <div class="footer">
324
- <p>Model by <a href="https://huggingface.co/CompVis" style="text-decoration: underline;" target="_blank">CompVis</a> and <a href="https://runwayml.com/" style="text-decoration: underline;" target="_blank">Runway</a> supported by <a href="https://huggingface.co/stabilityai" style="text-decoration: underline;" target="_blank">Stability AI</a> - backend running JAX on TPUs due to generous support of <a href="https://sites.research.google/trc/about/" style="text-decoration: underline;" target="_blank">Google TRC program</a> - Gradio Demo by 🤗 Hugging Face
 
 
 
 
 
325
  </p>
326
  </div>
327
- <div class="acknowledgments">
328
- <p><h4>LICENSE</h4>
329
- The model is licensed with a <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" style="text-decoration: underline;" target="_blank">CreativeML Open RAIL-M</a> license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" target="_blank" style="text-decoration: underline;" target="_blank">read the license</a></p>
330
- <p><h4>Biases and content acknowledgment</h4>
331
- Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the <a href="https://laion.ai/blog/laion-5b/" style="text-decoration: underline;" target="_blank">LAION-5B dataset</a>, which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5" style="text-decoration: underline;" target="_blank">model card</a></p>
332
- </div>
333
  """
334
  )
335
 
 
1
  import gradio as gr
 
2
  from PIL import Image
3
  import re
4
  import os
 
13
 
14
 
15
  model_id = "Next7years/stable-diffusion-v1-5-CatHeiHei-v1"
16
+ device = torch.device("cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu")
17
+ print("info: running device type: " + device.type )
18
 
19
  #word_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt", use_auth_token=True)
20
  #word_list = word_list_dataset["train"]['text']
21
 
22
+ example_dir = "prompt_examples"
23
  is_gpu_busy = False
24
  '''
25
  def infer(prompt):
 
45
  def infer(prompt):
46
  samples = 4
47
  steps = 50
48
+ scale = 7.5
49
+ if device.type == "cuda" or device.type == "mps":
50
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
51
+ else:
52
+ pipe = StableDiffusionPipeline.from_pretrained(model_id)
53
  pipe = pipe.to(device)
54
  images = []
55
+ results = pipe(prompt, negative_prompt=default_negative_prompt, num_images_per_prompt=samples, num_inference_steps=steps, guidance_scale=scale).images
56
  print(results)
57
  for image in results:
58
  jpeg_image = io.BytesIO()
 
188
 
189
  block = gr.Blocks(css=css)
190
 
191
+ def read_files_from_directory(directory):
192
+ file_contents = []
193
+ for filename in os.listdir(directory):
194
+ if filename.endswith(".txt"):
195
+ file_path = os.path.join(directory, filename)
196
+ with open(file_path, 'r') as f:
197
+ content = f.read()
198
+ file_contents.append([content])
199
+ return file_contents
200
+
201
+ examples = read_files_from_directory(example_dir)
202
+
203
+ metadata = [
204
+ {"title": "Positive Example",
205
+ "description": "A positive example input.",
206
+ "thumbnail": "https://example.com/images/positive.jpg",
207
+ "label": "Positive"},
208
+ {"title": "Negative Example",
209
+ "description": "A negative example input.",
210
+ "thumbnail": "https://example.com/images/negative.jpg",
211
+ "label": "Negative"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  ]
213
 
214
 
 
224
  font-size: 1.75rem;
225
  "
226
  >
227
+ <h1 style="font-weight: 900; margin-bottom: 12px;">
228
+ Welcome to CatHeiHei v1 Model
229
  </h1>
230
  </div>
231
+ <p style="margin-bottom: 10px">
232
+
233
+ We're excited to open-source this unique AI model, designed specifically to generate images of the world-famous Cat HeiHei.
234
+ Our goal is to foster creativity and collaboration within the community, and we can't wait to see the amazing artwork you'll create!
235
+
236
+ <p>Follow us on Instagram:
237
+ <a href="https://www.instagram.com/cat_heihei/" style="display: inline;">
238
+ <img src="https://www.instagram.com/static/images/ico/favicon-192.png/68d99ba29cc8.png" alt="Instagram Logo" style="display: inline; width: 20px; height: 20px; margin-right: 5px;">
239
+ @cat_heihei
240
+ </a>
241
+ </p>
242
  </p>
243
  </div>
244
  """
 
289
  randomize=True,
290
  )
291
 
292
+ ex = gr.Examples(examples=examples, label="Example prompt to generate CatHeiHei", fn=infer, inputs=text, outputs=[gallery], cache_examples=False, postprocess=False)
293
  ex.dataset.headers = [""]
294
 
295
  text.submit(infer, inputs=text, outputs=[gallery], postprocess=False)
 
313
  )
314
  gr.HTML(
315
  """
316
+ <div class="footer" style="padding-top: 20px;">
317
+ <p>Thanks for using the <b>Cat HeiHei </b> Customized Model! We appreciate your support and creativity. Share your feedback, suggestions, and content ideas by messaging us on Instagram
318
+ <a href="https://www.instagram.com/cat_heihei/" style="display: inline;">
319
+ <img src="https://www.instagram.com/static/images/ico/favicon-192.png/68d99ba29cc8.png" alt="Instagram Logo" style="display: inline; width: 20px; height: 20px; margin-right: 5px;">
320
+ @cat_heihei
321
+ </a>.
322
+ Let's make the Cat HeiHei community a fun, creative space for all! Happy creating! 🐾💖
323
  </p>
324
  </div>
 
 
 
 
 
 
325
  """
326
  )
327
 
prompt_examples/catheihei_baking.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Create a photo-realistic image of CatHeiHei cat making bakery treats while wearing a chef hat. CatHeiHei cat should have white, orange, and black calico fur patterns and yellow eyes. The cat should be sitting on a kitchen counter, surrounded by baking ingredients and utensils, with its front paws playfully handling the dough. The setting should be a warm, inviting kitchen filled with delicious baked goods. The image must have a realistic, photographic style, avoiding any anime or cartoon-like elements
prompt_examples/catheihei_bathing.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Create a photo-realistic image of CatHeiHei cat taking a delightful bath at night, outdoors under a starry sky with a visible moon. CatHeiHei cat should have white, orange, and black calico fur patterns and captivating yellow eyes. The cat should be sitting or partially submerged in a warm, bubbly bathtub, with steam or hot water aura rising from the surface.
2
+
3
+ Surround the bathtub with gently flickering candles, casting a warm and soothing glow on HeiHei and the immediate surroundings. The focus should be on CatHeiHei cat's adorable expressions and relaxed demeanor, capturing the essence of a serene and enjoyable bathing experience. The background should feature a clear, star-filled sky with a bright moon illuminating the scene.
4
+
5
+ The image must have a realistic, photographic style, avoiding any anime or cartoon-like elements.
prompt_examples/catheihei_winebrand.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Create a photo-realistic image of CatHeiHei cat lean against a bottle of wine. (face on the label of the bottle), CatHeiHei cat should have white, orange, and black calico fur patterns and yellow eyes. The cat should be sitting upright, gently holding the wine bottle with its front paws. The setting should be elegant, with a dimly lit background, creating a cozy atmosphere. The image must have a realistic, photographic style, avoiding any anime or cartoon-like elements.
requirements.txt CHANGED
@@ -8,4 +8,6 @@ numpy
8
  matplotlib
9
  uuid
10
  opencv-python
 
 
11
  git+https://github.com/openai/CLIP.git
 
8
  matplotlib
9
  uuid
10
  opencv-python
11
+ accelerate
12
+ gradio
13
  git+https://github.com/openai/CLIP.git