jbilcke-hf HF Staff commited on
Commit
312f580
·
verified ·
1 Parent(s): ab20abe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -25,6 +25,8 @@ from io import BytesIO
25
  import base64
26
  import re
27
 
 
 
28
  # Regex pattern to match data URI scheme
29
  data_uri_pattern = re.compile(r'data:image/(png|jpeg|jpg|webp);base64,')
30
 
@@ -104,7 +106,11 @@ def resize_image(img, target_height):
104
  return resized_img
105
 
106
  # @spaces.GPU(enable_queue=True)
107
- def inference(input_image_b64, prompt, a_prompt, n_prompt, denoise_steps, upscale, alpha, cfg, seed):
 
 
 
 
108
  input_image = readb64(input_image_b64)
109
 
110
  input_image = resize_image(input_image, 512)
@@ -172,6 +178,7 @@ with gr.Blocks() as demo:
172
  with gr.Column():
173
  with gr.Row():
174
  with gr.Column():
 
175
  input_image_b64 = gr.Textbox()
176
  prompt_in = gr.Textbox(label="Prompt", value="Frog")
177
  with gr.Accordion(label="Advanced settings", open=False):
@@ -189,6 +196,7 @@ with gr.Blocks() as demo:
189
  submit_btn.click(
190
  fn = inference,
191
  inputs = [
 
192
  input_image_b64, prompt_in,
193
  added_prompt, neg_prompt,
194
  denoise_steps,
 
25
  import base64
26
  import re
27
 
28
+ SECRET_TOKEN = os.getenv('SECRET_TOKEN', 'default_secret')
29
+
30
  # Regex pattern to match data URI scheme
31
  data_uri_pattern = re.compile(r'data:image/(png|jpeg|jpg|webp);base64,')
32
 
 
106
  return resized_img
107
 
108
  # @spaces.GPU(enable_queue=True)
109
+ def inference(secret_token, input_image_b64, prompt, a_prompt, n_prompt, denoise_steps, upscale, alpha, cfg, seed):
110
+ if secret_token != SECRET_TOKEN:
111
+ raise gr.Error(
112
+ f'Invalid secret token. Please fork the original space if you want to use it for yourself.')
113
+
114
  input_image = readb64(input_image_b64)
115
 
116
  input_image = resize_image(input_image, 512)
 
178
  with gr.Column():
179
  with gr.Row():
180
  with gr.Column():
181
+ secret_token = gr.Textbox()
182
  input_image_b64 = gr.Textbox()
183
  prompt_in = gr.Textbox(label="Prompt", value="Frog")
184
  with gr.Accordion(label="Advanced settings", open=False):
 
196
  submit_btn.click(
197
  fn = inference,
198
  inputs = [
199
+ secret_token,
200
  input_image_b64, prompt_in,
201
  added_prompt, neg_prompt,
202
  denoise_steps,