jin-nin commited on
Commit
3ceee2b
1 Parent(s): dee0fc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -15
app.py CHANGED
@@ -7,12 +7,17 @@ import string
7
  import time
8
  from queue import Queue
9
  from threading import Thread
 
10
  import emoji
11
 
 
 
 
12
 
13
  text_gen=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
14
  def get_prompts(prompt_text):
15
  return text_gen("photo, " + prompt_text)
 
16
  proc1=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
17
 
18
  def restart_script_periodically():
@@ -54,28 +59,41 @@ def send_it(inputs, noise_level, proc1=proc1):
54
 
55
  with gr.Blocks(css='style.css') as demo:
56
  with gr.Column(elem_id="col-container"):
 
 
 
 
 
 
 
 
 
 
 
 
57
  with gr.Row(variant="compact"):
58
  input_text = gr.Textbox(
59
- label="Short Prompt",
60
  show_label=False,
61
  max_lines=2,
62
- placeholder="Enter a basic idea and click 'Magic Prompt'",
63
  ).style(
64
  container=False,
65
  )
66
- see_prompts = gr.Button(" Magic Prompt ✨").style(full_width=False)
67
-
68
 
69
  with gr.Row(variant="compact"):
70
- with gr.Column():
71
- prompt = gr.Textbox(
72
- label="Enter your prompt",
73
- show_label=False,
74
- max_lines=2,
75
- placeholder="Full Prompt",
76
- ).style(
77
- container=False,
78
- )
 
 
79
  with gr.Column():
80
  noise_level = gr.Slider(minimum=0.0, maximum=3, step=0.1, label="Noise Level")
81
 
@@ -93,11 +111,12 @@ with gr.Blocks(css='style.css') as demo:
93
  run4 = gr.Button("Generate").style(full_width=False)
94
  output4=gr.Image()
95
 
 
96
  see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
97
  run1.click(send_it, inputs=[prompt, noise_level], outputs=[output1])
98
  run2.click(send_it, inputs=[prompt, noise_level], outputs=[output2])
99
- run3.click(send_it, inputs=[prompt, noise_level], outputs=[output3])
100
- run4.click(send_it, inputs=[prompt, noise_level], outputs=[output4])
101
 
102
 
103
  demo.launch(enable_queue=True, inline=True)
 
7
  import time
8
  from queue import Queue
9
  from threading import Thread
10
+ from transformers import pipeline
11
  import emoji
12
 
13
+ ru2en = pipeline("translation", model="Helsinki-NLP/opus-mt-ru-en")
14
+ def translate(text):
15
+ return ru2en(text)[0]["translation_text"]
16
 
17
  text_gen=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
18
  def get_prompts(prompt_text):
19
  return text_gen("photo, " + prompt_text)
20
+
21
  proc1=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
22
 
23
  def restart_script_periodically():
 
59
 
60
  with gr.Blocks(css='style.css') as demo:
61
  with gr.Column(elem_id="col-container"):
62
+
63
+ with gr.Row(variant="compact"):
64
+ input_text_ru = gr.Textbox(
65
+ label="Short Ru Prompt",
66
+ show_label=False,
67
+ max_lines=2,
68
+ placeholder="Enter a basic idea on Russian",
69
+ ).style(
70
+ container=False,
71
+ )
72
+ Translate = gr.Button("Ru ▶ En").style(full_width=False)
73
+
74
  with gr.Row(variant="compact"):
75
  input_text = gr.Textbox(
76
+ label="Short En Prompt",
77
  show_label=False,
78
  max_lines=2,
79
+ placeholder="Enter a basic idea",
80
  ).style(
81
  container=False,
82
  )
83
+ Translate = gr.Button("Ru En").style(full_width=False)
 
84
 
85
  with gr.Row(variant="compact"):
86
+ prompt = gr.Textbox(
87
+ label="Enter your prompt",
88
+ show_label=False,
89
+ max_lines=2,
90
+ placeholder="Full Prompt",
91
+ ).style(
92
+ container=False,
93
+ )
94
+ see_prompts = gr.Button("✨ Magic Prompt ✨").style(full_width=False)
95
+
96
+ with gr.Row(variant="compact"):
97
  with gr.Column():
98
  noise_level = gr.Slider(minimum=0.0, maximum=3, step=0.1, label="Noise Level")
99
 
 
111
  run4 = gr.Button("Generate").style(full_width=False)
112
  output4=gr.Image()
113
 
114
+ Translate.click(translate, inputs=[input_text_ru], outputs=[input_text], queue=False)
115
  see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
116
  run1.click(send_it, inputs=[prompt, noise_level], outputs=[output1])
117
  run2.click(send_it, inputs=[prompt, noise_level], outputs=[output2])
118
+ run3.click(send_it, inputs=[prompt, noise_level], outputs=[output3], queue=False)
119
+ run4.click(send_it, inputs=[prompt, noise_level], outputs=[output4], queue=False)
120
 
121
 
122
  demo.launch(enable_queue=True, inline=True)