Prgckwb commited on
Commit
c3d14af
1 Parent(s): 207d269

:tada: add external model

Browse files
Files changed (2) hide show
  1. app.py +40 -13
  2. example.csv +0 -4
app.py CHANGED
@@ -1,4 +1,7 @@
 
 
1
  import gradio as gr
 
2
  import spaces
3
  import torch
4
  from PIL import Image
@@ -33,11 +36,39 @@ if device == 'cuda':
33
  ).to(device)
34
 
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  @spaces.GPU()
37
  @torch.inference_mode()
38
  def inference(
39
- model_id: str,
40
  prompt: str,
 
41
  negative_prompt: str = "",
42
  width: int = 512,
43
  height: int = 512,
@@ -86,19 +117,22 @@ def inference(
86
 
87
 
88
  if __name__ == "__main__":
89
- with gr.Blocks() as demo:
 
 
90
  gr.Markdown(f"# Stable Diffusion Demo")
91
 
92
  with gr.Row():
93
  with gr.Column():
 
 
94
  model_id = gr.Dropdown(
95
  label="Model ID",
96
  choices=MODEL_CHOICES,
97
  value="stabilityai/stable-diffusion-3-medium-diffusers",
98
  )
99
- prompt = gr.Text(label="Prompt", value="")
100
 
101
- with gr.Accordion("Additional Settings (W.I.P)", open=False):
102
  negative_prompt = gr.Text(label="Negative Prompt", value="")
103
 
104
  with gr.Row():
@@ -114,8 +148,8 @@ if __name__ == "__main__":
114
  output_image = gr.Image(label="Image", type="pil")
115
 
116
  inputs = [
117
- model_id,
118
  prompt,
 
119
  negative_prompt,
120
  width,
121
  height,
@@ -132,14 +166,7 @@ if __name__ == "__main__":
132
  )
133
 
134
  gr.Examples(
135
- examples=[
136
- ['stabilityai/stable-diffusion-3-medium-diffusers', 'A cat holding a sign that says Hello world', ""],
137
- ['stabilityai/stable-diffusion-3-medium-diffusers',
138
- 'Beautiful pixel art of a Wizard with hovering text "Achivement unlocked: Diffusion models can spell now"',
139
- ''],
140
- ['stabilityai/stable-diffusion-3-medium-diffusers', 'A corgi wearing sunglasses says "U-Net is OVER!!"',
141
- ''],
142
- ],
143
  inputs=inputs,
144
  )
145
 
 
1
+ import dataclasses
2
+
3
  import gradio as gr
4
+ import requests
5
  import spaces
6
  import torch
7
  from PIL import Image
 
36
  ).to(device)
37
 
38
 
39
+ @dataclasses.dataclass
40
+ class Input:
41
+ prompt: str
42
+ model_id: str = "stabilityai/stable-diffusion-3-medium-diffusers"
43
+ negative_prompt: str = ''
44
+ width: int = 1024
45
+ height: int = 1024
46
+ guidance_scale: float = 7.5
47
+ num_inference_step: int = 28
48
+ num_images: int = 4
49
+
50
+ def to_list(self):
51
+ return [
52
+ self.prompt, self.model_id, self.negative_prompt,
53
+ self.width, self.height, self.guidance_scale,
54
+ self.num_inference_step, self.num_images
55
+ ]
56
+
57
+
58
+ EXAMPLES = [
59
+ Input(prompt='A cat holding a sign that says Hello world').to_list(),
60
+ Input(
61
+ prompt='Beautiful pixel art of a Wizard with hovering text "Achivement unlocked: Diffusion models can spell now"'
62
+ ).to_list(),
63
+ Input(prompt='A corgi wearing sunglasses says "U-Net is OVER!!"').to_list(),
64
+ ]
65
+
66
+
67
  @spaces.GPU()
68
  @torch.inference_mode()
69
  def inference(
 
70
  prompt: str,
71
+ model_id: str = "stabilityai/stable-diffusion-3-medium-diffusers",
72
  negative_prompt: str = "",
73
  width: int = 512,
74
  height: int = 512,
 
117
 
118
 
119
  if __name__ == "__main__":
120
+ theme = gr.themes.Default(primary_hue=gr.themes.colors.emerald)
121
+
122
+ with gr.Blocks(theme=theme) as demo:
123
  gr.Markdown(f"# Stable Diffusion Demo")
124
 
125
  with gr.Row():
126
  with gr.Column():
127
+ prompt = gr.Text(label="Prompt", placeholder="Enter a prompt here")
128
+
129
  model_id = gr.Dropdown(
130
  label="Model ID",
131
  choices=MODEL_CHOICES,
132
  value="stabilityai/stable-diffusion-3-medium-diffusers",
133
  )
 
134
 
135
+ with gr.Accordion("Additional Settings", open=False):
136
  negative_prompt = gr.Text(label="Negative Prompt", value="")
137
 
138
  with gr.Row():
 
148
  output_image = gr.Image(label="Image", type="pil")
149
 
150
  inputs = [
 
151
  prompt,
152
+ model_id,
153
  negative_prompt,
154
  width,
155
  height,
 
166
  )
167
 
168
  gr.Examples(
169
+ examples=EXAMPLES,
 
 
 
 
 
 
 
170
  inputs=inputs,
171
  )
172
 
example.csv DELETED
@@ -1,4 +0,0 @@
1
- model_uri,description,additional_info
2
- stabilityai/stable-diffusion-3-medium-diffusers,"A cat holding a sign that says Hello world",
3
- stabilityai/stable-diffusion-3-medium-diffusers,"Beautiful pixel art of a Wizard with hovering text "Achivement unlocked: Diffusion models can spell now"",
4
- stabilityai/stable-diffusion-3-medium-diffusers,"A corgi wearing sunglasses says ""U-Net is OVER!!"",