Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -23,42 +23,18 @@ def generate_image(prompt, code):
|
|
23 |
image_url = response_json["data"][0]["url"]
|
24 |
|
25 |
return image_url
|
26 |
-
|
27 |
css = """
|
28 |
footer {visibility: hidden !important;}
|
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"
|
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()
|
|
|
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')
|
36 |
image_output = gr.Image(label="Изображение")
|
37 |
|
|
|
|
|
|
|
|
|
38 |
submit_btn.click(fn=generate_image, inputs=[prompt_input, code], outputs=image_output)
|
39 |
|
40 |
demo.launch()
|