Maaz66 commited on
Commit
203d66f
1 Parent(s): bf63320

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from googletrans import Translator
2
+ from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
3
+ import torch
4
+ import gradio as gr
5
+
6
+ translator = Translator()
7
+
8
+ model_id = "stabilityai/stable-diffusion-2-1"
9
+ access_token="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"
10
+
11
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, use_auth_token=access_token
12
+ )
13
+
14
+ pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
15
+ pipe = pipe.to("cuda")
16
+
17
+ def generate(prompt, inference_steps, guidance_scale, neg_prompt):
18
+ if not neg_prompt:
19
+ neg_prompt = ""
20
+
21
+ prompt_eng = translator.translate(prompt, dest='en').text
22
+ image = pipe(prompt_eng, guidance_scale= int(guidance_scale), num_inference_steps = int(inference_steps), negative_prompt = neg_prompt).images[0]
23
+ return image
24
+
25
+ gr.Interface(
26
+ generate,
27
+ title = 'Image to Image using Diffusers',
28
+ inputs=[
29
+ gr.Textbox(label="Prompt"),
30
+ gr.Slider(50, 700, value=50, label ="Inference steps"),
31
+ gr.Slider(1, 10, value=5, label ="Guidance scale"),
32
+ gr.Textbox(label="Negative prompt (include things you DO NOT want in the image")
33
+ ],
34
+ outputs = [
35
+ gr.Image(elem_id="output-image"),
36
+
37
+ ], css = "#output-image, #input-image, #image-preview {border-radius: 40px !important; background-color : gray !important;} "
38
+ ).launch()