taltaf9133 commited on
Commit
f20af30
1 Parent(s): 5c8f1c8
Files changed (2) hide show
  1. app.py +67 -0
  2. requirements.txt +9 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ import matplotlib.pyplot as plt
3
+ from PIL import Image
4
+
5
+
6
+ import torch
7
+ from torch import autocast
8
+ from diffusers import StableDiffusionPipeline, DDIMScheduler
9
+
10
+
11
+ import gradio as gr
12
+
13
+ from gradio.components import Textbox, Image
14
+
15
+ import torch
16
+ from torch import autocast
17
+ from diffusers import StableDiffusionPipeline, DDIMScheduler
18
+
19
+ pipe = StableDiffusionPipeline.from_pretrained("taltaf9133/finetuned-stable-diffusion-log", torch_dtype=torch.float32) #.to('cuda')
20
+ #pipe.enable_xformers_memory_efficient_attention()
21
+
22
+ prompt = "tv with sofa, realistic, hd, vivid"
23
+ negative_prompt = "bad anatomy, ugly, deformed, desfigured, distorted, blurry, low quality, low definition, lowres, out of frame, out of image, cropped, cut off, signature, watermark"
24
+ num_samples = 1
25
+ guidance_scale = 7.5
26
+ num_inference_steps = 30
27
+ height = 512
28
+ width = 512
29
+
30
+ #seed = random.randint(0, 2147483647)
31
+ #print("Seed: {}".format(str(seed)))
32
+ #generator = torch.Generator(device='cuda').manual_seed(seed)
33
+
34
+ def predict(prompt, negative_prompt):
35
+ #with autocast("cuda"), torch.inference_mode():
36
+ img = pipe(
37
+ prompt,
38
+ negative_prompt=negative_prompt,
39
+ height=height, width=width,
40
+ num_images_per_prompt=num_samples,
41
+ num_inference_steps=num_inference_steps,
42
+ guidance_scale=guidance_scale,
43
+ #generator=generator
44
+ ).images[0]
45
+ return img
46
+
47
+ title = "Stable Diffusion Demo"
48
+ description = "Stable diffusion demo"
49
+
50
+
51
+ # Input from user
52
+ neg_p = "bad anatomy, ugly, deformed, desfigured, distorted, blurry, low quality, low definition, lowres, out of frame, out of image, cropped, cut off, signature, watermark"
53
+ in_prompt = gradio.inputs.Textbox(lines=5, placeholder=None, default="ldg with scn style", label='Enter prompt')
54
+ in_neg_prompt = gradio.inputs.Textbox(lines=5, placeholder=None, default=neg_p, label='Enter negative prompt')
55
+
56
+ # Output response
57
+ out_response = Image(label="Generated image:")
58
+
59
+ # Create the Gradio demo
60
+ demo = gradio.Interface(fn=predict, # mapping function from input to output
61
+ inputs=[in_prompt, in_neg_prompt],
62
+ outputs=gradio.Image(),
63
+ title=title,
64
+ description=description,)
65
+
66
+ # Launch the demo!
67
+ demo.launch(debug = True, share=True)
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ accelerate
2
+ transformers
3
+ ftfy
4
+ bitsandbytes==0.35.0
5
+ natsort
6
+ safetensors
7
+ xformers
8
+ diffusers
9
+ gradio