Rooni commited on
Commit
939f8da
·
1 Parent(s): 002797e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -8,6 +8,9 @@ def generate_image(prompt, code):
8
  if code != os.getenv("code"):
9
  raise gr.Error("❗ Не верный ключ!")
10
  return None
 
 
 
11
  headers = {
12
  "Authorization": f"Bearer {api_key}",
13
  "Content-Type": "application/json",
@@ -23,13 +26,16 @@ def generate_image(prompt, code):
23
  image_url = response_json["data"][0]["url"]
24
 
25
  return image_url
 
26
  css = """
27
  footer {visibility: hidden !important;}
28
  """
29
  # Создание интерфейса с помощью Gradio
30
  with gr.Blocks(css=css, theme='YTheme/Sketch') as demo:
31
  with gr.Row():
32
- code = gr.Textbox(label="Ключ доступа", type="password")
 
 
33
  with gr.Row():
34
  prompt_input = gr.Textbox(label="Описание изображения")
35
  submit_btn = gr.Button("Генерация", variant='primary')
 
8
  if code != os.getenv("code"):
9
  raise gr.Error("❗ Не верный ключ!")
10
  return None
11
+ # Сохраняем код в куки после успешной проверки
12
+ gr.set_cookie("access_code", code)
13
+
14
  headers = {
15
  "Authorization": f"Bearer {api_key}",
16
  "Content-Type": "application/json",
 
26
  image_url = response_json["data"][0]["url"]
27
 
28
  return image_url
29
+
30
  css = """
31
  footer {visibility: hidden !important;}
32
  """
33
  # Создание интерфейса с помощью Gradio
34
  with gr.Blocks(css=css, theme='YTheme/Sketch') as demo:
35
  with gr.Row():
36
+ # Загружаем сохранённый код из куки, если он существует
37
+ saved_code = gr.get_cookie("access_code")
38
+ code = gr.Textbox(label="Ключ доступа", type="password", value=saved_code or "")
39
  with gr.Row():
40
  prompt_input = gr.Textbox(label="Описание изображения")
41
  submit_btn = gr.Button("Генерация", variant='primary')