Yaron Koresh commited on
Commit
7300f25
·
verified ·
1 Parent(s): e341b7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -12
app.py CHANGED
@@ -59,21 +59,21 @@ def generate_random_string(length):
59
  return ''.join(random.choice(characters) for _ in range(length))
60
 
61
  @spaces.GPU
62
- def Piper(english_prompt):
63
  return pipe(
64
- english_prompt,
65
  height=512,
66
  width=512,
67
- negative_prompt="",
68
  num_inference_steps=400,
69
- guidance_scale=9
70
  )
71
 
72
- def infer(prompt):
73
  name = generate_random_string(12)+".png"
74
- english_prompt = f'REAL {translate(prompt,"english").upper()}:'
75
- print(f'Final prompt: {english_prompt}')
76
- image = Piper(english_prompt).images[0].save(name)
77
  return name
78
 
79
  css="""
@@ -98,18 +98,29 @@ with gr.Blocks(css=css) as demo:
98
  Currently running on {power_device}.
99
  """)
100
  with gr.Row():
101
- prompt = gr.Text(
102
- label="Prompt",
103
  show_label=False,
104
  max_lines=1,
105
- placeholder="Enter your prompt",
 
 
 
 
 
 
 
 
 
 
 
 
106
  container=False,
107
  )
108
  run_button = gr.Button("Run", scale=0)
109
  result = gr.Image(elem_id="image-container", label="Result", show_label=False, type='filepath')
110
  run_button.click(
111
  fn = infer,
112
- inputs = [prompt],
113
  outputs = [result]
114
  )
115
 
 
59
  return ''.join(random.choice(characters) for _ in range(length))
60
 
61
  @spaces.GPU
62
+ def Piper(_do, _dont):
63
  return pipe(
64
+ _do,
65
  height=512,
66
  width=512,
67
+ negative_prompt=_dont,
68
  num_inference_steps=400,
69
+ guidance_scale=10
70
  )
71
 
72
+ def infer(prompt1,prompt2,prompt3):
73
  name = generate_random_string(12)+".png"
74
+ _do = f'BACKGROUND: show an authentic {translate(prompt2,"english")}; FOREGROUND: be focused on a real {translate(prompt1,"english")}.'
75
+ _dont = f'ANY usage of {translate(prompt3,"english").upper()}...'
76
+ image = Piper(_do, _dont).images[0].save(name)
77
  return name
78
 
79
  css="""
 
98
  Currently running on {power_device}.
99
  """)
100
  with gr.Row():
101
+ prompt2 = gr.Text(
 
102
  show_label=False,
103
  max_lines=1,
104
+ placeholder="(The Overall Scene)",
105
+ container=False,
106
+ )
107
+ prompt1 = gr.Text(
108
+ show_label=False,
109
+ max_lines=1,
110
+ placeholder="(The Main Content)",
111
+ container=False,
112
+ )
113
+ prompt3 = gr.Text(
114
+ show_label=False,
115
+ max_lines=1,
116
+ placeholder="(What Things Are Forbidden?)",
117
  container=False,
118
  )
119
  run_button = gr.Button("Run", scale=0)
120
  result = gr.Image(elem_id="image-container", label="Result", show_label=False, type='filepath')
121
  run_button.click(
122
  fn = infer,
123
+ inputs = [prompt1,prompt2,prompt3],
124
  outputs = [result]
125
  )
126