Fung804 commited on
Commit
802f5e1
β€’
1 Parent(s): f46ba2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -5,27 +5,37 @@
5
  #!pip install transformers==4.24.0
6
  #<--able go to no error
7
 
8
- import random
9
- import re
 
10
  import torch
11
- import requests
12
- from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
13
  from torch import autocast
14
- import gradio
15
- import gradio as gr
16
 
17
- pipe = StableDiffusionPipeline.from_pretrained("Fung804/makoto-shinkai-v2", torch_dtype=torch.float16)
18
- pipe = pipe.to("cuda")
19
 
20
- def txt2img(prompt):
 
 
 
21
 
22
- image = pipe(prompt +",γ€€realistic, highly detailed, high quality", height=512, width=512, negative_prompt = "((low quality)),((poor quality)),((clone)),retro style, bad anatomy,((lowres)), blurry, (worst quality), ((low quality)), normal quality,bad anatomy, disfigured, deformed, mutation, mutilated, ugly, totem pole,(poorly drawn face), cloned face, several faces, long neck, mutated hands, bad hands, poorly drawn hands,extra limbs, malformed limbs, missing arms, missing fingers, extra fingers, fused fingers, too many fingers,missing legs, extra legs, malformed legs, extra digit, fewer digits, glitchy, cropped, jpeg artifacts, signature, watermark, username, text, errorretro style ,bad anatomy,((lowres)), blurry, (worst quality), normal quality,bad anatomy, disfigured, deformed, mutation, mutilated, ugly, totem pole,(poorly drawn face), cloned face, several faces, long neck, mutated hands, bad hands, poorly drawn hands,extra limbs, malformed limbs, missing arms, missing fingers, extra fingers, fused fingers, too many fingers,missing legs, extra legs, malformed legs, extra digit, fewer digits, glitchy, cropped, jpeg artifacts, signature, watermark, username, text, error", guidance_scale = 7.5,num_inference_steps = 50).images[0]
23
-
24
- image.save("sd_image.png")
 
 
25
 
26
- return image
27
 
28
- generate = gr.Interface(fn = txt2img, inputs="text",outputs="image",allow_flagging="never")
 
 
29
 
 
 
 
 
30
 
31
- generate.launch()
 
 
 
 
 
5
  #!pip install transformers==4.24.0
6
  #<--able go to no error
7
 
8
+ from tensorflow.keras.models import load_model
9
+ import tensorflow as tf
10
+ import os
11
  import torch
12
+ from diffusers import StableDiffusionPipeline
 
13
  from torch import autocast
 
 
14
 
 
 
15
 
16
+ model_path = "Fung804/makoto-shinkai-v2"
17
+ pipe = StableDiffusionPipeline.from_pretrained(model_path, torch_dtype=torch.float16)
18
+ pipe.to("cuda")
19
+ pipe.vae.enable_tiling()
20
 
21
+ prompt = "A train track with a sky background , realistic, highly detailed, high quality" #@param {type:"string"}
22
+ negative_prompt = "((low quality)),((poor quality)),((clone)),retro style, bad anatomy,((lowres)), blurry, (worst quality), ((low quality)), normal quality,bad anatomy, disfigured, deformed, mutation, mutilated, ugly, totem pole,(poorly drawn face), cloned face, several faces, long neck, mutated hands, bad hands, poorly drawn hands,extra limbs, malformed limbs, missing arms, missing fingers, extra fingers, fused fingers, too many fingers,missing legs, extra legs, malformed legs, extra digit, fewer digits, glitchy, cropped, jpeg artifacts, signature, watermark, username, text, errorretro style ,bad anatomy,((lowres)), blurry, (worst quality), normal quality,bad anatomy, disfigured, deformed, mutation, mutilated, ugly, totem pole,(poorly drawn face), cloned face, several faces, long neck, mutated hands, bad hands, poorly drawn hands,extra limbs, malformed limbs, missing arms, missing fingers, extra fingers, fused fingers, too many fingers,missing legs, extra legs, malformed legs, extra digit, fewer digits, glitchy, cropped, jpeg artifacts, signature, watermark, username, text, error" #@param {type:"string"}
23
+ n_samples = 4 #@param {type:"number"}
24
+ scale = 7.5 #@param {type:"number"}
25
+ timesteps = 50
26
 
 
27
 
28
+ # Sometimes the nsfw checker is confused by the images, you can disable
29
+ # it at your own risk here
30
+ disable_safety = True
31
 
32
+ if disable_safety:
33
+ def null_safety(images, **kwargs):
34
+ return images, False
35
+ pipe.safety_checker = null_safety
36
 
37
+ with autocast("cuda"):
38
+ images = pipe(n_samples*[prompt], guidance_scale=scale,num_inference_steps=timesteps).images
39
+
40
+ for idx, im in enumerate(images):
41
+ im.save(f"{idx:06}.png")