File size: 2,082 Bytes
dba19eb
 
 
 
 
 
 
 
 
 
 
 
 
b9492b6
dba19eb
b9492b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!pip install --upgrade pip
!pip install diffusers==0.9.0
#it is still work for 0.9.0, if problem get, use below command
!pip install --upgrade diffusers transformers scipy
#!pip install transformers==4.24.0
#<--able go to no error

from tensorflow.keras.models import load_model
import cv2
import tensorflow as tf
import os
from matplotlib import pyplot as plt
import numpy as np
import torch
from diffusers import StableDiffusionPipeline
from torch import autocast
import gradio
import gradio as gr

pipe = StableDiffusionPipeline.from_pretrained("Fung804/makoto-shinkai-v2", torch_dtype=torch.float16)  
pipe = pipe.to("cuda")

def txt2img(prompt):

  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]
    
  image.save("sd_image.png")

  return image


generate = gr.Interface(fn = txt2img, inputs="text",outputs="image",allow_flagging="never")

generate.launch(inline = False)