mohansathya commited on
Commit
719468d
·
1 Parent(s): 904ddf4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import random
4
+ from getpass import getpass
5
+ from glob import glob
6
+ from natsort import natsorted
7
+ import matplotlib.pyplot as plt
8
+ from PIL import Image
9
+
10
+ import torch
11
+ from torch import autocast
12
+ from diffusers import StableDiffusionPipeline, DDIMScheduler
13
+ from IPython.display import display
14
+
15
+
16
+ import gradio as gr
17
+
18
+ from gradio.components import Textbox, Image
19
+
20
+
21
+ repo_name = 'mohansathya/twosd' # YOUR REPO NAME
22
+ pipe2 = StableDiffusionPipeline.from_pretrained(repo_name, torch_dtype=torch.float16).to('cuda')
23
+
24
+
25
+
26
+ def generate_query_response(prompt):
27
+ negative_prompt = "bad anatomy, ugly, deformed, desfigured, distorted, poorly drawn, blurry, low quality, low definition, lowres, out of frame, out of image, cropped, cut off, signature, watermark"
28
+ num_samples = 5
29
+ guidance_scale = 7.5
30
+ num_inference_steps = 30
31
+ height = 512
32
+ width = 512
33
+
34
+ seed = random.randint(0, 2147483647)
35
+ print("Seed: {}".format(str(seed)))
36
+ generator = torch.Generator(device='cuda').manual_seed(seed)
37
+
38
+ with autocast("cuda"), torch.inference_mode():
39
+ imgs = pipe2(
40
+ prompt,
41
+ negative_prompt=negative_prompt,
42
+ height=height, width=width,
43
+ num_images_per_prompt=num_samples,
44
+ num_inference_steps=num_inference_steps,
45
+ guidance_scale=guidance_scale,
46
+ generator=generator
47
+ ).images
48
+
49
+ for img in imgs:
50
+ return img
51
+
52
+
53
+ # Input from user
54
+ in_prompt = Textbox(label="Enter a prompt:")
55
+
56
+ # Output response
57
+ out_response = Image(label="Generated image:")
58
+
59
+ # Gradio interface to generate UI link
60
+ iface = gr.Interface(
61
+ fn=generate_query_response, inputs=in_prompt, outputs=out_response)
62
+
63
+ # Launch the interface to generate UI
64
+ iface.launch()