Update app.py
Browse files
app.py
CHANGED
|
@@ -8,9 +8,6 @@ def generate_image(prompt, code):
|
|
| 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",
|
|
@@ -30,12 +27,25 @@ def generate_image(prompt, code):
|
|
| 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')
|
|
|
|
| 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",
|
|
|
|
| 27 |
css = """
|
| 28 |
footer {visibility: hidden !important;}
|
| 29 |
"""
|
| 30 |
+
js = """
|
| 31 |
+
document.addEventListener('DOMContentLoaded', (event) => {
|
| 32 |
+
if (document.cookie.split(';').some((item) => item.trim().startsWith('code='))) {
|
| 33 |
+
const codeValue = document.cookie.split('; ').find(row => row.startsWith('code=')).split('=')[1];
|
| 34 |
+
document.getElementById('code').value = codeValue;
|
| 35 |
+
}
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
function saveCode() {
|
| 39 |
+
const codeValue = document.getElementById('code').value;
|
| 40 |
+
document.cookie = 'code=' + codeValue + ';max-age=31536000'; // Сохраняем на 1 год
|
| 41 |
+
}
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
# Создание интерфейса с помощью Gradio
|
| 45 |
with gr.Blocks(css=css, theme='YTheme/Sketch') as demo:
|
| 46 |
+
gr.HTML(f"<script>{js}</script>")
|
| 47 |
with gr.Row():
|
| 48 |
+
code = gr.Textbox(label="Ключ доступа", type="password", elem_id="code", change=saveCode)
|
|
|
|
|
|
|
| 49 |
with gr.Row():
|
| 50 |
prompt_input = gr.Textbox(label="Описание изображения")
|
| 51 |
submit_btn = gr.Button("Генерация", variant='primary')
|