Yaron Koresh commited on
Commit
db8d483
·
verified ·
1 Parent(s): f3e4728

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -16
app.py CHANGED
@@ -71,10 +71,26 @@ def Piper(_do, _dont):
71
 
72
  def infer(prompt1,prompt2,prompt3,prompt4):
73
  name = generate_random_string(12)+".png"
74
- prompt1 = " and ".join([translate(v,"english").upper() for v in prompt1])
75
- prompt2 = " and ".join([translate(v,"english").upper() for v in prompt2])
76
- prompt3 = " and ".join([translate(v,"english").upper() for v in prompt3])
77
- prompt4 = " or ".join([translate(v,"english").upper() for v in prompt4])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  _do = f'Show an authentic {prompt3} scene, while focusing on the details, of {prompt1}, as the main elements, and, showing {prompt2} in the background.'
79
  _dont = f'ANY usage of {prompt4}...'
80
  image = Piper(_do, _dont).images[0].save(name)
@@ -83,7 +99,7 @@ def infer(prompt1,prompt2,prompt3,prompt4):
83
  css="""
84
  #col-container {
85
  margin: 0 auto;
86
- max-width: 15cm;
87
  }
88
  #image-container {
89
  aspect-ratio: 1 / 1;
@@ -95,7 +111,7 @@ if torch.cuda.is_available():
95
  else:
96
  power_device = "CPU"
97
 
98
- with gr.Blocks(css=css) as demo:
99
  with gr.Column(elem_id="col-container"):
100
  gr.Markdown(f"""
101
  # Image Generator
@@ -109,8 +125,7 @@ with gr.Blocks(css=css) as demo:
109
  max_choices=3,
110
  label="Foreground Elements",
111
  show_label=True,
112
- container=False,
113
- value="any"
114
  )
115
  with gr.Row():
116
  prompt2 = gr.Dropdown(
@@ -119,8 +134,7 @@ with gr.Blocks(css=css) as demo:
119
  max_choices=4,
120
  label="Background Elements",
121
  show_label=True,
122
- container=False,
123
- value="any"
124
  )
125
  with gr.Row():
126
  prompt3 = gr.Dropdown(
@@ -129,21 +143,19 @@ with gr.Blocks(css=css) as demo:
129
  max_choices=2,
130
  label="Background Events",
131
  show_label=True,
132
- container=False,
133
- value="any"
134
  )
135
  with gr.Row():
136
  prompt4 = gr.Dropdown(
137
  multiselect=True,
138
  allow_custom_value=True,
139
- max_choices=6,
140
  label="Forbidden Elements/Events",
141
  show_label=True,
142
- container=False,
143
- value="None"
144
  )
145
  with gr.Row():
146
- run_button = gr.Button("Run", scale=0)
147
  result = gr.Image(elem_id="image-container", label="Result", show_label=False, type='filepath')
148
  run_button.click(
149
  fn = infer,
 
71
 
72
  def infer(prompt1,prompt2,prompt3,prompt4):
73
  name = generate_random_string(12)+".png"
74
+ if prompt1 == None:
75
+ prompt1 = "any"
76
+ else:
77
+ prompt1 = " and ".join([translate(v,"english").upper() for v in prompt1])
78
+
79
+ if prompt2 == None:
80
+ prompt2 = "any"
81
+ else:
82
+ prompt2 = " and ".join([translate(v,"english").upper() for v in prompt2])
83
+
84
+ if prompt3 == None:
85
+ prompt3 = "any"
86
+ else:
87
+ prompt3 = " and ".join([translate(v,"english").upper() for v in prompt3])
88
+
89
+ if prompt4 == None:
90
+ prompt4 = "none"
91
+ else:
92
+ prompt4 = " or ".join([translate(v,"english").upper() for v in prompt4])
93
+
94
  _do = f'Show an authentic {prompt3} scene, while focusing on the details, of {prompt1}, as the main elements, and, showing {prompt2} in the background.'
95
  _dont = f'ANY usage of {prompt4}...'
96
  image = Piper(_do, _dont).images[0].save(name)
 
99
  css="""
100
  #col-container {
101
  margin: 0 auto;
102
+ max-width: 13cm;
103
  }
104
  #image-container {
105
  aspect-ratio: 1 / 1;
 
111
  else:
112
  power_device = "CPU"
113
 
114
+ with gr.Blocks(theme=gr.themes.Glass(primary_hue="white", secondary_hue="black",spacing_size="xl",radius_size="xl"),css=css) as demo:
115
  with gr.Column(elem_id="col-container"):
116
  gr.Markdown(f"""
117
  # Image Generator
 
125
  max_choices=3,
126
  label="Foreground Elements",
127
  show_label=True,
128
+ container=True
 
129
  )
130
  with gr.Row():
131
  prompt2 = gr.Dropdown(
 
134
  max_choices=4,
135
  label="Background Elements",
136
  show_label=True,
137
+ container=True
 
138
  )
139
  with gr.Row():
140
  prompt3 = gr.Dropdown(
 
143
  max_choices=2,
144
  label="Background Events",
145
  show_label=True,
146
+ container=True
 
147
  )
148
  with gr.Row():
149
  prompt4 = gr.Dropdown(
150
  multiselect=True,
151
  allow_custom_value=True,
152
+ max_choices=5,
153
  label="Forbidden Elements/Events",
154
  show_label=True,
155
+ container=True
 
156
  )
157
  with gr.Row():
158
+ run_button = gr.Button("Run")
159
  result = gr.Image(elem_id="image-container", label="Result", show_label=False, type='filepath')
160
  run_button.click(
161
  fn = infer,