Kvikontent commited on
Commit
8e5c6f4
1 Parent(s): 64b6267

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from PIL import Image
4
+ from diffusers import DiffusionPipeline
5
+
6
+ # Load model and scheduler
7
+ ldm = DiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large-256")
8
+
9
+ def generate_image(prompt, negative_prompt, width, height):
10
+ # Run pipeline in inference (sample random noise and denoise)
11
+ images = ldm([prompt], num_inference_steps=50, eta=0.3, guidance_scale=6, negative_prompts=[negative_prompt]).images
12
+ # Resize image to desired width and height
13
+ resized_images = [image.resize((width, height)) for image in images]
14
+ # Save images
15
+ for idx, image in enumerate(resized_images):
16
+ image.save(f"squirrel-{idx}.png")
17
+ return "Images generated successfully!"
18
+
19
+ # Define the interface
20
+ iface = gr.Interface(
21
+ fn=generate_image,
22
+ inputs=["text", "text", "number", "number"],
23
+ outputs="text",
24
+ layout="vertical",
25
+ title="Image Generation",
26
+ description="Generate images based on prompts.",
27
+ article="For more information, visit the documentation: [link](https://docs.gradio.app/)",
28
+ )
29
+
30
+ # Launch the interface
31
+ iface.launch()