Dhruv Diddi commited on
Commit
22ce981
β€’
1 Parent(s): e1d4069

feat: any lang to sd test

Browse files
Files changed (2) hide show
  1. app.py +32 -14
  2. requirements.txt +1 -4
app.py CHANGED
@@ -4,6 +4,10 @@ from PIL import Image
4
  import flag
5
  import os
6
 
 
 
 
 
7
  stable_diffusion = gr.Blocks.load(name="spaces/stabilityai/stable-diffusion")
8
  ### β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
9
 
@@ -13,6 +17,13 @@ def get_images(prompt):
13
  gallery_dir = stable_diffusion(prompt, fn_index=2)
14
  return [os.path.join(gallery_dir, img) for img in os.listdir(gallery_dir)]
15
 
 
 
 
 
 
 
 
16
 
17
  css = """
18
  .container {
@@ -151,6 +162,15 @@ css = """
151
  --tw-gradient-to: #4caf50;
152
  border-color: #8bc34a;
153
  }
 
 
 
 
 
 
 
 
 
154
  #notice {
155
  padding: 20px 14px 10px;
156
  display: flex;
@@ -187,16 +207,8 @@ with gr.Blocks(css=css) as demo:
187
  </p>
188
 
189
  ''')
190
- # with gr.Row(elem_id="w2sd_container"):
191
- # with gr.Column():
192
-
193
- gr.Markdown(
194
- """
195
- ## 1. Stable Diffusion Config
196
- """
197
- )
198
-
199
-
200
 
201
  with gr.Accordion(label="Stable Diffusion Settings", elem_id="sd_settings", visible=False):
202
  with gr.Row():
@@ -212,7 +224,7 @@ with gr.Blocks(css=css) as demo:
212
 
213
  with gr.Row():
214
 
215
- transcripted_output = gr.Textbox(
216
  label="Enter prompt",
217
  lines=3,
218
  elem_id="transcript"
@@ -221,18 +233,17 @@ with gr.Blocks(css=css) as demo:
221
  with gr.Column():
222
  translated_output = gr.Textbox(
223
  label="in English",
224
- lines=4,
225
  elem_id="translated"
226
  )
227
  with gr.Row():
228
  clear_btn = gr.Button(value="Clear")
 
229
  diffuse_btn = gr.Button(value="YES", elem_id="diffuse_btn")
230
 
231
  clear_btn.click(fn=lambda value: gr.update(value=""), inputs=clear_btn, outputs=translated_output)
232
 
233
 
234
-
235
-
236
 
237
  # with gr.Column():
238
 
@@ -288,6 +299,13 @@ with gr.Blocks(css=css) as demo:
288
  outputs = sd_output
289
  )
290
 
 
 
 
 
 
 
 
291
 
292
  if __name__ == "__main__":
293
  demo.launch()
 
4
  import flag
5
  import os
6
 
7
+ from libretranslatepy import LibreTranslateAPI
8
+ lt = LibreTranslateAPI("https://translate.argosopentech.com/")
9
+
10
+
11
  stable_diffusion = gr.Blocks.load(name="spaces/stabilityai/stable-diffusion")
12
  ### β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
13
 
 
17
  gallery_dir = stable_diffusion(prompt, fn_index=2)
18
  return [os.path.join(gallery_dir, img) for img in os.listdir(gallery_dir)]
19
 
20
+ def get_translation(text):
21
+ lang_detected = lt.detect(text)[0]['language']
22
+ print(lang_detected)
23
+ english_translated = lt.translate(text, lang_detected, "en")
24
+ print(english_translated)
25
+ return english_translated
26
+
27
 
28
  css = """
29
  .container {
 
162
  --tw-gradient-to: #4caf50;
163
  border-color: #8bc34a;
164
  }
165
+ #translate_btn {
166
+ color: #fff;
167
+ font-size: 1em;
168
+ margin-bottom: 20px;
169
+ --tw-gradient-from: #4caf50;
170
+ --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);
171
+ --tw-gradient-to: #4caf50;
172
+ border-color: #8bc34a;
173
+ }
174
  #notice {
175
  padding: 20px 14px 10px;
176
  display: flex;
 
207
  </p>
208
 
209
  ''')
210
+
211
+
 
 
 
 
 
 
 
 
212
 
213
  with gr.Accordion(label="Stable Diffusion Settings", elem_id="sd_settings", visible=False):
214
  with gr.Row():
 
224
 
225
  with gr.Row():
226
 
227
+ enter_prompt = gr.Textbox(
228
  label="Enter prompt",
229
  lines=3,
230
  elem_id="transcript"
 
233
  with gr.Column():
234
  translated_output = gr.Textbox(
235
  label="in English",
236
+ lines=3,
237
  elem_id="translated"
238
  )
239
  with gr.Row():
240
  clear_btn = gr.Button(value="Clear")
241
+ translate_btn = gr.Button(value="Translate", elem_id="translate_btn")
242
  diffuse_btn = gr.Button(value="YES", elem_id="diffuse_btn")
243
 
244
  clear_btn.click(fn=lambda value: gr.update(value=""), inputs=clear_btn, outputs=translated_output)
245
 
246
 
 
 
247
 
248
  # with gr.Column():
249
 
 
299
  outputs = sd_output
300
  )
301
 
302
+ translate_btn.click(get_translation,
303
+ inputs = [
304
+ enter_prompt
305
+ ],
306
+ outputs = translated_output
307
+ )
308
+
309
 
310
  if __name__ == "__main__":
311
  demo.launch()
requirements.txt CHANGED
@@ -1,7 +1,4 @@
1
- #torch
2
  scipy
3
  ftfy
4
- #transformers
5
  emoji-country-flag
6
- #git+https://github.com/LambdaLabsML/lambda-diffusers.git#egg=lambda-diffusers
7
- git+https://github.com/openai/whisper.git
 
 
1
  scipy
2
  ftfy
 
3
  emoji-country-flag
4
+ libretranslatepy