ciaochaos commited on
Commit
464a7c2
1 Parent(s): 90ba4c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -62
app.py CHANGED
@@ -18,22 +18,57 @@ import gradio as gr
18
  showDetailsBool = False
19
  showSeedBool = False
20
 
21
-
22
- async def CleanBlock():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  return gr.update(value='')
24
 
25
 
26
- async def ChangeBlock():
27
- global showDetailsBool
28
- if not showDetailsBool:
29
- showDetailsBool = not showDetailsBool
30
- return gr.Button.update(value="Hide Details"), gr.update(visible=True)
31
- else:
32
- showDetailsBool = not showDetailsBool
33
- return gr.Button.update(value="Show Details"), gr.update(visible=False)
34
-
35
-
36
- async def ChangeSeedBlock():
37
  global showSeedBool
38
  if not showSeedBool:
39
  showSeedBool = not showSeedBool
@@ -57,37 +92,20 @@ async def greet(my_prompt, control_weight, correct_level, padding_ratio, point_s
57
  }
58
 
59
  full_response: str = ""
60
- point_style_out = 0
61
- if correct_level == "L(7%)":
62
- correct_level_out = 1
63
- elif correct_level == "M(15%)":
64
- correct_level_out = 0
65
- else:
66
- if correct_level == "Q(25%)":
67
- correct_level_out = 3
68
- else:
69
- correct_level_out = 2
70
- if size == "768*768":
71
- width_out, height_out = 768, 768
72
- else:
73
- width_out, height_out = 1024, 1024
74
- if point_style == "Normal":
75
- point_style_out = 0
76
- elif point_style == "circle":
77
- point_style_out = 1
78
- else:
79
- if point_style == "minimum":
80
- point_style_out = 2
81
  payload = {
82
  'url': 'https://qrbtf.com/',
83
  'prompt': my_prompt,
84
  'controlnet_weight': control_weight,
85
- 'correct_level': correct_level_out,
86
  'padding_ratio': padding_ratio,
87
- 'point_style': point_style_out,
88
  'seed': my_seed,
89
- 'width': width_out,
90
- 'height': height_out,
91
  }
92
 
93
  async with aiohttp.ClientSession(headers=headers) as session:
@@ -131,46 +149,38 @@ with gr.Blocks() as demo:
131
  value="1girl, flowers, birds",
132
  interactive=True
133
  )
134
- showDetails = gr.Button("Show Details")
135
- with gr.Column(visible=False) as detailColumn:
136
- with gr.Row():
137
- randomSeed = gr.Checkbox(label="Random Seed?", value=True, interactive=True)
138
- promptsTuning = gr.Checkbox(label="Prompts Tuning?", value=True, interactive=True)
139
- seed = gr.Textbox(
140
  label="Seed",
141
- placeholder="Seed",
142
- value="-1",
 
 
143
  interactive=True,
144
- visible=False
145
  )
146
- ControlWeight = gr.Slider(0, 2, value=1.5, label="ControlWeight",
147
- info="Controls the weight of QR_Controlnet", interactive=True) # 滑动条
148
 
149
- marginScale = gr.Slider(0, 0.5, value=0.2, label="Margin Scale",
150
- info="Controls how far margin is", interactive=True) # 滑动条
151
  SizeSelection = gr.Dropdown(
152
- ["768*768", "1024*1024"], value="768*768", label="Size", interactive=True)
153
  errorRate = gr.Dropdown(
154
- ["L(7%)", "M(15%)", "Q(25%)", "H(30%)"], value="H(30%)", label="Error Correction Rate",
155
  interactive=True)
156
  anchorStyle = gr.Dropdown(
157
- ["Normal", "circle", "minimum"], value="Normal", label="AnchorStyle", interactive=True)
158
-
159
- showDetails.click(ChangeBlock, [], [showDetails, detailColumn])
160
 
161
  with gr.Column():
162
  with gr.Row():
163
- clear_btn = gr.Button(
164
- "Clear",
165
- )
166
  btn = gr.Button(
167
  "Call API",
168
  variant="primary"
169
  )
170
- out = gr.Image(shape=(1, 1))
 
171
 
172
  btn.click(greet, [prompt, ControlWeight, errorRate, marginScale, anchorStyle, seed, SizeSelection], out)
173
- clear_btn.click(CleanBlock, [], prompt)
174
- randomSeed.change(ChangeSeedBlock, [], seed)
175
 
176
  demo.launch()
 
18
  showDetailsBool = False
19
  showSeedBool = False
20
 
21
+ anchor_styles = [
22
+ {
23
+ "value": 0,
24
+ "label": "Square",
25
+ },
26
+ {
27
+ "value": 1,
28
+ "label": "Circle",
29
+ },
30
+ {
31
+ "value": 2,
32
+ "label": "Minimal",
33
+ },
34
+ ]
35
+
36
+ sizes = [
37
+ {
38
+ "label": "1152 × 1152",
39
+ "value": 768
40
+ },
41
+ {
42
+ "label": "1536 × 1536",
43
+ "value": 1024
44
+ },
45
+ ]
46
+
47
+ correct_levels = [
48
+ {
49
+ "value": 1,
50
+ "label": "L (7%)",
51
+ },
52
+ {
53
+ "value": 0,
54
+ "label": "M (15%)",
55
+ },
56
+ {
57
+ "value": 3,
58
+ "label": "Q (25%)",
59
+ },
60
+ {
61
+ "value": 2,
62
+ "label": "H (30%)",
63
+ },
64
+ ]
65
+
66
+
67
+ async def clean_block():
68
  return gr.update(value='')
69
 
70
 
71
+ async def change_seed_block():
 
 
 
 
 
 
 
 
 
 
72
  global showSeedBool
73
  if not showSeedBool:
74
  showSeedBool = not showSeedBool
 
92
  }
93
 
94
  full_response: str = ""
95
+
96
+ correct_level_value = correct_levels[correct_level]['value']
97
+ size_value = sizes[size]['value']
98
+ point_style_value = anchor_styles[point_style]['value']
99
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  payload = {
101
  'url': 'https://qrbtf.com/',
102
  'prompt': my_prompt,
103
  'controlnet_weight': control_weight,
104
+ 'correct_level': correct_level_value,
105
  'padding_ratio': padding_ratio,
106
+ 'point_style': point_style_value,
107
  'seed': my_seed,
108
+ 'size': size_value,
 
109
  }
110
 
111
  async with aiohttp.ClientSession(headers=headers) as session:
 
149
  value="1girl, flowers, birds",
150
  interactive=True
151
  )
152
+ with gr.Accordion("More options", open=False):
153
+ promptsTuning = gr.Checkbox(label="Prompts tuning", value=True, interactive=True)
154
+ seed = gr.Slider(
 
 
 
155
  label="Seed",
156
+ minimum=-1,
157
+ maximum=9999,
158
+ step=1,
159
+ value=-1,
160
  interactive=True,
 
161
  )
162
+ ControlWeight = gr.Slider(0, 2, value=1.5, label="ControlNet weight",
163
+ info="", interactive=True) # 滑动条
164
 
165
+ marginScale = gr.Slider(0, 0.5, value=0.2, label="Padding ratio",
166
+ info="", interactive=True) # 滑动条
167
  SizeSelection = gr.Dropdown(
168
+ [size['label'] for size in sizes], value=sizes[0]['label'], label="Size", type="index", interactive=True)
169
  errorRate = gr.Dropdown(
170
+ [level['label'] for level in correct_levels], value=correct_levels[0]['label'], label="Error correction", type="index",
171
  interactive=True)
172
  anchorStyle = gr.Dropdown(
173
+ [anchor['label'] for anchor in anchor_styles], value=anchor_styles[0]['label'], label="Anchor style", type="index", interactive=True)
 
 
174
 
175
  with gr.Column():
176
  with gr.Row():
 
 
 
177
  btn = gr.Button(
178
  "Call API",
179
  variant="primary"
180
  )
181
+ with gr.Row():
182
+ out = gr.Image(shape=(1, 1))
183
 
184
  btn.click(greet, [prompt, ControlWeight, errorRate, marginScale, anchorStyle, seed, SizeSelection], out)
 
 
185
 
186
  demo.launch()