Yaron Koresh commited on
Commit
02471b0
·
verified ·
1 Parent(s): edc1d05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -71
app.py CHANGED
@@ -39,7 +39,7 @@ def translate(text,lang):
39
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15',
40
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
41
  ]
42
- url = f'https://www.google.com/search?q=translate to {lang}: {text}'
43
  print(url)
44
  resp = requests.get(
45
  url = url,
@@ -69,47 +69,23 @@ def generate_random_string(length):
69
  def Piper(_do):
70
  return pipe(
71
  _do,
72
- height=480,
73
- width=480,
74
  negative_prompt="",
75
  num_inference_steps=100,
76
- guidance_scale=9
77
  )
78
 
79
- def infer(prompt1,prompt2,prompt3,prompt4):
80
  name = generate_random_string(12)+".png"
81
-
82
- if prompt4 == None:
83
- prompt4 = " without text nor logo"
84
- else:
85
- prompt4 = " without text nor logo " + " nor ".join([translate(v,"english") for v in prompt4])
86
-
87
- prompt4 = prompt4.upper()
88
-
89
- if prompt1 == None:
90
- prompt1 = "focused elements" + prompt4
91
- else:
92
- prompt1 = ", ".join([ "primary "+(translate(v,"english")+prompt4) for v in prompt1 ])
93
-
94
- if prompt2 == None:
95
- prompt2 = "secondary elements" + prompt4
96
- else:
97
- prompt2 = ", ".join([ "secondary "+(translate(v,"english")+prompt4) for v in prompt2 ])
98
-
99
- if prompt3 == None:
100
- prompt3 = "event" + prompt4
101
- else:
102
- prompt3 = ", ".join([ (translate(v,"english")+" "+prompt4) for v in prompt3 ])
103
-
104
- _do = f'Rational fusion, from, {prompt3}, {prompt2}, {prompt1}'.upper()
105
-
106
  image = Piper(_do).images[0].save(name)
107
  return name
108
 
109
  css="""
110
  #col-container {
111
  margin: 0 auto;
112
- max-width: 13cm;
113
  }
114
  #image-container {
115
  aspect-ratio: 1 / 1;
@@ -124,55 +100,33 @@ if torch.cuda.is_available():
124
  else:
125
  power_device = "CPU"
126
 
 
 
 
127
  with gr.Blocks(theme=gr.themes.Soft(),css=css) as demo:
128
  with gr.Column(elem_id="col-container"):
129
  gr.Markdown(f"""
130
  # Image Generator
131
  Currently running on {power_device}.
132
  """)
133
- with gr.Column():
134
- with gr.Row():
135
- prompt1 = gr.Dropdown(
136
- multiselect=True,
137
- allow_custom_value=True,
138
- max_choices=1,
139
- label="Foreground Elements",
140
- show_label=True,
141
- container=True
142
- )
143
- with gr.Row():
144
- prompt2 = gr.Dropdown(
145
- multiselect=True,
146
- allow_custom_value=True,
147
- max_choices=2,
148
- label="Background Elements",
149
- show_label=True,
150
- container=True
151
- )
152
- with gr.Row():
153
- prompt3 = gr.Dropdown(
154
- multiselect=True,
155
- allow_custom_value=True,
156
- max_choices=1,
157
- label="Background Events",
158
- show_label=True,
159
- container=True
160
- )
161
- with gr.Row():
162
- prompt4 = gr.Dropdown(
163
- multiselect=True,
164
- allow_custom_value=True,
165
- max_choices=2,
166
- label="Forbidden Elements/Events",
167
- show_label=True,
168
- container=True
169
- )
170
- with gr.Row():
171
- run_button = gr.Button("Run")
172
  result = gr.Image(elem_id="image-container", label="Result", show_label=False, type='filepath')
 
 
 
 
 
173
  run_button.click(
174
  fn = infer,
175
- inputs = [prompt1,prompt2,prompt3,prompt4],
176
  outputs = [result]
177
  )
178
 
 
39
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15',
40
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
41
  ]
42
+ url = f'https://www.google.com/search?q={lang}: {text}'
43
  print(url)
44
  resp = requests.get(
45
  url = url,
 
69
  def Piper(_do):
70
  return pipe(
71
  _do,
72
+ height=512,
73
+ width=512,
74
  negative_prompt="",
75
  num_inference_steps=100,
76
+ guidance_scale=10
77
  )
78
 
79
+ def infer(prompt):
80
  name = generate_random_string(12)+".png"
81
+ _do = f'true {prompt1}:'.upper()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  image = Piper(_do).images[0].save(name)
83
  return name
84
 
85
  css="""
86
  #col-container {
87
  margin: 0 auto;
88
+ max-width: 15cm;
89
  }
90
  #image-container {
91
  aspect-ratio: 1 / 1;
 
100
  else:
101
  power_device = "CPU"
102
 
103
+ def limiter(txt):
104
+ return (re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', txt)).lower().strip())[:38]
105
+
106
  with gr.Blocks(theme=gr.themes.Soft(),css=css) as demo:
107
  with gr.Column(elem_id="col-container"):
108
  gr.Markdown(f"""
109
  # Image Generator
110
  Currently running on {power_device}.
111
  """)
112
+ with gr.Row():
113
+ prompt = gr.Textbox(
114
+ placeholder="Describe the photo...",
115
+ container=False,
116
+ rtl=True,
117
+ max_lines=1
118
+ )
119
+ with gr.Row():
120
+ run_button = gr.Button("Run")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  result = gr.Image(elem_id="image-container", label="Result", show_label=False, type='filepath')
122
+ prompt.change(
123
+ fn = limiter,
124
+ inputs = [prompt],
125
+ outputs = [prompt],
126
+ )
127
  run_button.click(
128
  fn = infer,
129
+ inputs = [prompt],
130
  outputs = [result]
131
  )
132