How to Create A.I. Art with Stable Diffusion and Python | Part 1

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 ต.ค. 2024

ความคิดเห็น • 40

  • @ThisCozyStudio
    @ThisCozyStudio  ปีที่แล้ว +5

    What do you all think of the new 3D intro!?!? Big thanks to our 3D designer Caelin for creating it 💖

  • @wrcz
    @wrcz 5 หลายเดือนก่อน +1

    Thank you, as somebody who uses PyCharm and Windows this is exactly what I was looking for. One suggestion, could you please make your text in the IDE bigger. Because for us plebs at 1080p resolution it's almost unreadable and so you have to fullscreen everytime you ALT TAB to read the syntax :)

  • @jomarnuguid291
    @jomarnuguid291 ปีที่แล้ว +4

    Here's the code since it was not funnily provided in the source link lol. This works if you're using a computer with a GPU (meaning, not apple silicon macs) import os
    from torch import autocast
    from diffusers import StableDiffusionPipeline
    SDV5_MODEL_PATH = os.getenv("SDV5_MODEL_PATH")
    SAVE_PATH = os.path.join(os.environ['USERPROFILE'], "Desktop", "SDV5_OUTPUT")
    if not os.path.exists(SAVE_PATH):
    os.mkdir(SAVE_PATH)
    def uniquify(path):
    filename, extension = os.path.splitext(path)
    counter = 1
    while os.path.exists(path):
    path = filename + " (" + str(counter) + ")" + extension
    counter += 1
    return path
    prompt = "A dog rising"
    print(f"Characters in prompt: {len(prompt)}, limit: 200")
    pipe = StableDiffusionPipeline.from_pretrained(SDV5_MODEL_PATH)
    pipe = pipe.to('cuda')
    with autocast('cuda'):
    image = pipe(prompt).image[0]
    # Save the image
    image_path = uniquify(os.path.join(SAVE_PATH, (prompt[:25] + "...") if len(prompt) > 25 else prompt) + ".png")
    print(image_path)
    image.save(image_path)

  • @blaafferd
    @blaafferd ปีที่แล้ว +2

    First of all: love the new intro!
    Second: I've encountered a problem with running this on my machine. I've installed the correct version of everything and I believe the code is correct as well. The error I'm getting is as follows:
    Traceback (most recent call last):
    File "C:\Users\[username]\PycharmProjects\stable_diffusion_project\main.py", line 27, in
    pipe = StableDiffusionPipeline.from_pretrained(SDV5_MODEL_PATH)
    File "C:\Users\[username]\AppData\Local\Programs\Python\Python39\lib\site-packages\diffusers\pipeline_utils.py", line 430, in from_pretrained
    if not os.path.isdir(pretrained_model_name_or_path):
    File "C:\Users\[username]\AppData\Local\Programs\Python\Python39\lib\genericpath.py", line 42, in isdir
    st = os.stat(s)
    TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
    Seems to be a generic error according to some fora. Do you have any clue what this could be and how I could solve this?

    • @ThisCozyStudio
      @ThisCozyStudio  ปีที่แล้ว +2

      Hmm, seems like there is something wrong with the path you set the environment variable SDV5_MODEL_PATH. I suggest opening the console in admin mode and then retrying to set the variable there. Let me know if that works!
      If not, you could just use the following in place of the environment variable line:
      SDV5_MODEL_PATH = r"C:\Path\To\stable-diffusion-v1-5"

    • @blaafferd
      @blaafferd ปีที่แล้ว +1

      @@ThisCozyStudio Running command prompt as admin totally worked! Thanks for the quick reaction, making images now :D

    • @ThisCozyStudio
      @ThisCozyStudio  ปีที่แล้ว +1

      Np! Glad it worked!

    • @HackFight
      @HackFight ปีที่แล้ว

      @@ThisCozyStudio YES! Thanks so much... I had the same problem.

    • @p4yd1rt76
      @p4yd1rt76 ปีที่แล้ว +2

      @@blaafferd @This Cozy Studio @HackFight
      Hey sorry, I'm running into the same issue and I dont really understand how to correct this in command prompt or in PyCharm. Have any tips?

  • @burakkizilkaya99
    @burakkizilkaya99 2 หลายเดือนก่อน

    I want to work without doing API requests. so if I download the model to my computer like you did, can I generate images for free?

  • @Arnogorter
    @Arnogorter ปีที่แล้ว +1

    Great video! one more piece of advice, if you're trying to run this on CPU, remove the autocast line!

    • @ThisCozyStudio
      @ThisCozyStudio  ปีที่แล้ว

      Thanks for the tip! We go into more detail about CPU rendering in Part 2 (linked in the description) ;)

  • @ormenachem341
    @ormenachem341 ปีที่แล้ว

    i tried doing it with coda and it did the progress bar thing pretty fast but gave an error when it was done and didnt work. then i changed it to cpu and it worked but it is pretty slow. anyway i can make it faster?

  • @JudWhite1
    @JudWhite1 7 หลายเดือนก่อน

    git clone --depth 1, if you're just going to delete the .git directory anyway. This will download much faster than pulling down the full history.

  • @davidbenjamin-d9k
    @davidbenjamin-d9k 2 หลายเดือนก่อน

    bro my downloading for stable diffusion 1.5 exceeded 65gb why?

  • @nirajbava799
    @nirajbava799 ปีที่แล้ว

    Sir I can use my model stable diffusion 1.5 7.5gb file directly with out downloading all model file became I have very low internet data to download model file

  • @liloplayz95
    @liloplayz95 10 หลายเดือนก่อน

    im getting ''Torch not compiled with CUDA enabled'' even tho i did download cuda 12.3

  • @HackFight
    @HackFight ปีที่แล้ว

    Can I make it work with a non Nvidia GPU?
    (edit): I tried using "cpu" instead of "cuda" but I have this error:
    Characters in prompt: 20, limit 200
    ftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.
    0%| | 0/51 [00:00

  • @SoulbreakerNB
    @SoulbreakerNB ปีที่แล้ว

    That stable-diffusion-v1-5 is not in my users/username/ path but I did download the repository tho. I checked the C/Users folder/pathsize and it has the files inside. Hidden files and folders are already viewable in my os. What should I do in this situation?
    EDIT: found mine. I instead installed the repository in system32 XD my bad.

  • @eternalsunshine313
    @eternalsunshine313 9 หลายเดือนก่อน

    great video! how can we load up LoRas?

  • @niethelemaaljofel
    @niethelemaaljofel ปีที่แล้ว

    any idea how i can run this on my 8gig vram card? it just gives me an out of memory error. ive seen others edit some script/txt2img file, but i dont seem to have it

    • @ThisCozyStudio
      @ThisCozyStudio  ปีที่แล้ว +1

      I'm currently looking into this, I know there is a method and will include it in my next video! For now I'd recommend checking out the examples in the Huggingface diffusers readme file, I think there is some useful information about this topic there.

  • @amineproductions3055
    @amineproductions3055 ปีที่แล้ว

    I love you, my friend. I hope you will continue in the field of learning artificial intelligence. Thank you. Thank you. Thank you

    • @ThisCozyStudio
      @ThisCozyStudio  ปีที่แล้ว

      Wow thank you for the kind words! And likewise!

  • @brosjay94
    @brosjay94 ปีที่แล้ว

    Can you do ones where you rather translate text prompt+image to another image?

  • @RaNdUmGuY1
    @RaNdUmGuY1 11 หลายเดือนก่อน

    I'm unsure what I did wrong? I received this error after following everything to a T. I even followed your advice in the comments to see if it could remedy the error.
    Traceback (most recent call last):
    File "C:\Users\[user]\PycharmProjects\stable_diffusion_test1\main.py", line 9, in
    os.mkdir(SAVE_PATH)
    FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\[user]\\Desktop\\SD_OUTPUT'

  • @AITOOLS-m8k
    @AITOOLS-m8k ปีที่แล้ว

    Are all the programs free?

    • @oksidmi6716
      @oksidmi6716 4 หลายเดือนก่อน

      Yeah

  • @WackyJay9
    @WackyJay9 ปีที่แล้ว

    Amazing

  • @jesterjunk
    @jesterjunk ปีที่แล้ว +1

    88 GB now

  • @Jesuslovesyou86
    @Jesuslovesyou86 ปีที่แล้ว

    I can't see the code 😭

  • @lumi7610
    @lumi7610 4 หลายเดือนก่อน

    ah thanks, the python 3.9 thing really affected the code a lot

  • @kimschmidt8911
    @kimschmidt8911 ปีที่แล้ว

    There is Mac Computers with a dedicated GPU

  • @elad3958
    @elad3958 ปีที่แล้ว

    32Gigs for a tutorial. Not practical

    • @arjoai
      @arjoai ปีที่แล้ว +1

      That's why there are inference servers, and there is never a stable diffusion model working on the edge side

  • @maxprono2071
    @maxprono2071 ปีที่แล้ว +1

    i'm a photographer and this tutorial is awesome ,but i receive this error ,not idea where is my mistake ,can you help me pls? C:\Users\Makxxx\PycharmProjects\stable_diffusion_tutorial\venv\Scripts\python.exe C:\Users\Makxxx\PycharmProjects\stable_diffusion_tutorial\main.py
    Character in prompt: 19, limit: 200
    Traceback (most recent call last):
    File "C:\Users\Makxxx\PycharmProjects\stable_diffusion_tutorial\main.py", line 28, in
    pipe = StableDiffusionPipeline.from_pretrained(SDV5_MODEL_PATH)
    File "C:\Users\Makxxx\AppData\Local\Programs\Python\Python39\lib\site-packages\diffusers\pipelines\pipeline_utils.py", line 461, in from_pretrained
    if not os.path.isdir(pretrained_model_name_or_path):
    File "C:\Users\Makxxx\AppData\Local\Programs\Python\Python39\lib\genericpath.py", line 42, in isdir
    st = os.stat(s)
    TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
    Process finished with exit code 1

    • @cogs6743
      @cogs6743 ปีที่แล้ว

      I to am experiencing the same error, would love a response.

    • @cogs6743
      @cogs6743 ปีที่แล้ว +1

      I got it working by adding the model_id line and changing the "pipe =" line to this below. I also added "import torch" to the top. Lastly, I don't think this does anything but I changed the name of the file where the model was to what he had exactly which was "stable-diffusion-v1-5"
      model_id = "runwayml/stable-diffusion-v1-5"
      pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
      (Just leaving the code I commented out).
      #pipe = StableDiffusionPipeline.from_pretrained(SDV5_MODEL_PATH)

  • @tusharrohilla7154
    @tusharrohilla7154 ปีที่แล้ว

    amazing