Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -29,30 +29,36 @@ footer {visibility: hidden !important;}
|
|
29 |
"""
|
30 |
js = """
|
31 |
function saveCode() {
|
32 |
-
const codeValue = document.getElementById('code').value;
|
33 |
-
document.cookie = 'code=' + codeValue + ';max-age=31536000'; // Сохраняем на 1 год
|
34 |
}
|
35 |
|
36 |
-
|
37 |
-
const codeInput = document.getElementById('code');
|
38 |
-
|
39 |
-
|
|
|
40 |
codeInput.value = codeValue;
|
41 |
}
|
42 |
-
|
43 |
-
|
|
|
44 |
"""
|
45 |
|
46 |
# Создание интерфейса с помощью Gradio
|
47 |
with gr.Blocks(css=css, theme='YTheme/Sketch') as demo:
|
48 |
gr.HTML(f"<script>{js}</script>")
|
49 |
with gr.Row():
|
50 |
-
code = gr.Textbox(label="Ключ доступа", type="password", elem_id="code")
|
51 |
with gr.Row():
|
52 |
prompt_input = gr.Textbox(label="Описание изображения")
|
53 |
submit_btn = gr.Button("Генерация", variant='primary')
|
54 |
image_output = gr.Image(label="Изображение")
|
55 |
|
|
|
|
|
|
|
|
|
56 |
submit_btn.click(fn=generate_image, inputs=[prompt_input, code], outputs=image_output)
|
57 |
|
58 |
demo.launch()
|
|
|
29 |
"""
|
30 |
js = """
|
31 |
function saveCode() {
|
32 |
+
const codeValue = document.getElementById('code-input').value;
|
33 |
+
document.cookie = 'code=' + encodeURIComponent(codeValue) + ';max-age=31536000;path=/'; // Сохраняем на 1 год
|
34 |
}
|
35 |
|
36 |
+
function loadCode() {
|
37 |
+
const codeInput = document.getElementById('code-input');
|
38 |
+
const codeCookie = document.cookie.split('; ').find(row => row.startsWith('code='));
|
39 |
+
if (codeCookie) {
|
40 |
+
const codeValue = decodeURIComponent(codeCookie.split('=')[1]);
|
41 |
codeInput.value = codeValue;
|
42 |
}
|
43 |
+
}
|
44 |
+
|
45 |
+
document.addEventListener('DOMContentLoaded', loadCode);
|
46 |
"""
|
47 |
|
48 |
# Создание интерфейса с помощью Gradio
|
49 |
with gr.Blocks(css=css, theme='YTheme/Sketch') as demo:
|
50 |
gr.HTML(f"<script>{js}</script>")
|
51 |
with gr.Row():
|
52 |
+
code = gr.Textbox(label="Ключ доступа", type="password", elem_id="code-input", visible=True)
|
53 |
with gr.Row():
|
54 |
prompt_input = gr.Textbox(label="Описание изображения")
|
55 |
submit_btn = gr.Button("Генерация", variant='primary')
|
56 |
image_output = gr.Image(label="Изображение")
|
57 |
|
58 |
+
# Добавляем обработчик события oninput непосредственно в HTML элемент
|
59 |
+
code_input_html = f'<input type="password" id="code-input" oninput="saveCode()" placeholder="Ключ доступа">'
|
60 |
+
gr.HTML(code_input_html)
|
61 |
+
|
62 |
submit_btn.click(fn=generate_image, inputs=[prompt_input, code], outputs=image_output)
|
63 |
|
64 |
demo.launch()
|