Neo Anderson commited on
Commit
851f851
·
1 Parent(s): 6ce788a
Files changed (1) hide show
  1. app.py +68 -18
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from diffusers import AutoPipelineForText2Image
3
  import torch
 
4
 
5
  if torch.backends.mps.is_available():
6
  device = "mps"
@@ -30,27 +31,76 @@ def infer(prompt):
30
 
31
  return image
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
- examples = [
35
- "A cinematic shot of a baby racoon wearing an intricate kungfu master robe.",
36
- "A cartoonish drawing of a tiger with a rainbow mane.",
37
- "A realistic painting of a futuristic cityscape with flying cars.",
38
- "A watercolor painting of a whimsical fairy in a mystical forest.",
39
  ]
40
 
41
- demo = gr.Interface(
42
- fn=infer,
43
- inputs=gr.Textbox(
44
- label="Prompt",
45
- placeholder="Enter your prompt",
46
- lines=3,
47
- ),
48
- outputs=gr.Image(label="Result", type="numpy"),
49
- title="Text-to-Image",
50
- description="Generate images from text prompts.",
51
- theme="compact",
52
- examples=examples,
53
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  if __name__ == "__main__":
56
  demo.launch()
 
1
  import gradio as gr
2
  from diffusers import AutoPipelineForText2Image
3
  import torch
4
+ import random
5
 
6
  if torch.backends.mps.is_available():
7
  device = "mps"
 
31
 
32
  return image
33
 
34
+ # Lists for random prompt generation
35
+ subjects = [
36
+ "a cute red panda", "a robot", "a steampunk owl", "a magical crystal",
37
+ "a floating island", "a cybernetic dolphin", "a time-traveling historian",
38
+ "a ghost pianist", "a rainbow dragon", "a space explorer", "a majestic tiger",
39
+ "a giant mushroom", "a neon cityscape", "a cosmic jellyfish", "a dreamy unicorn",
40
+ "a celestial mermaid", "a mechanical spider", "a mystical forest", "a futuristic city",
41
+ "a whimsical fairy", "a mythical phoenix", "a cosmic nebula", "a magical castle",
42
+ "a cyberpunk samurai", "a time-traveling astronaut", "a crystal cavern",
43
+ ]
44
+
45
+ contexts = [
46
+ "in an ancient library", "during a neon sunset", "floating in space",
47
+ "deep underwater", "in a floating market", "on top of a giant mushroom",
48
+ "inside a clockwork machine", "in a crystal cave", "during a meteor shower",
49
+ "in a bamboo forest", "in a futuristic cityscape", "on a magical island",
50
+ "in a cyberpunk alleyway", "in a steampunk workshop",
51
+ "in a post-apocalyptic wasteland", "in a dreamy cloud kingdom",
52
+ ]
53
+
54
+ styles = [
55
+ "cyberpunk style", "watercolor painting", "digital art", "oil painting",
56
+ "studio ghibli style", "synthwave aesthetics", "detailed pencil sketch",
57
+ "photorealistic", "vaporwave style", "low poly art", "lo-fi aesthetics",
58
+ "grainy film photography", "comic book style", "minimalist design",
59
+ ]
60
 
61
+ image_qualities = [
62
+ "highly detailed", "8K resolution", "dramatic lighting",
63
+ "professional photography", "cinematic composition", "hyperrealistic",
64
+ "atmospheric", "stunning", "award-winning", "masterpiece",
65
+ "low quality", "grainy", "blurry", "abstract", "surreal",
66
  ]
67
 
68
+ def generate_not_hot_dog_prompt():
69
+ subject = random.choice(subjects)
70
+ context = random.choice(contexts)
71
+ style = random.choice(styles)
72
+ quality = random.choice(image_qualities)
73
+ return f"{subject} {context}, {style}, {quality}"
74
+
75
+ hot_dog_prompt = "A cinematic shot of a gourmet hotdog in extreme close-up, sitting in a rustic brioche bun, garnished with perfectly drizzled mustard and ketchup. The hotdog glistens under dramatic studio lighting with a slight overhead angle. Shallow depth of field with professional food photography styling. The background is dark and moody with subtle bokeh effects. Shot with a high-end DSLR camera, f/2.8 aperture, warm color grading reminiscent of a Wes Anderson film. Photorealistic quality, 8K resolution."
76
+
77
+
78
+ def generate_hot_dog():
79
+ return infer(hot_dog_prompt)
80
+
81
+ def generate_not_hot_dog():
82
+ return infer(generate_not_hot_dog_prompt())
83
+
84
+ with gr.Blocks(theme="compact") as demo:
85
+ gr.Markdown("# What Do You Want To Create?")
86
+
87
+ with gr.Row():
88
+ hot_dog_btn = gr.Button("🌭 Hot Dog", variant="primary")
89
+ not_hot_dog_btn = gr.Button("❌ Not Hot Dog", variant="primary")
90
+
91
+ output_image = gr.Image(label="Generated Image", type="numpy")
92
+
93
+ hot_dog_btn.click(
94
+ fn=generate_hot_dog,
95
+ inputs=[],
96
+ outputs=output_image
97
+ )
98
+
99
+ not_hot_dog_btn.click(
100
+ fn=generate_not_hot_dog,
101
+ inputs=[],
102
+ outputs=output_image
103
+ )
104
 
105
  if __name__ == "__main__":
106
  demo.launch()