Update app.py
Browse files
app.py
CHANGED
@@ -15,14 +15,17 @@ def get_data(password):
|
|
15 |
else:
|
16 |
raise gr.Error("Неверный пароль!")
|
17 |
|
18 |
-
def send_data(text):
|
19 |
"""Функция для сохранения данных на диск."""
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
26 |
|
27 |
css = """
|
28 |
footer {visibility: hidden !important;}
|
@@ -40,6 +43,6 @@ with gr.Blocks(css=css) as demo:
|
|
40 |
output_text = gr.Textbox(label="Результат:")
|
41 |
|
42 |
get_button.click(get_data, inputs=password_input, outputs=output_text)
|
43 |
-
send_button.click(send_data, inputs=text_input, outputs=output_text)
|
44 |
|
45 |
demo.launch()
|
|
|
15 |
else:
|
16 |
raise gr.Error("Неверный пароль!")
|
17 |
|
18 |
+
def send_data(password, text):
|
19 |
"""Функция для сохранения данных на диск."""
|
20 |
+
if password == os.environ.get("password"):
|
21 |
+
global data
|
22 |
+
data = text
|
23 |
+
with open("data.txt", "w") as f:
|
24 |
+
f.write(data)
|
25 |
+
raise gr.Info("Данные успешно сохранены!")
|
26 |
+
return get_data()
|
27 |
+
else:
|
28 |
+
raise gr.Error("Неверный пароль!")
|
29 |
|
30 |
css = """
|
31 |
footer {visibility: hidden !important;}
|
|
|
43 |
output_text = gr.Textbox(label="Результат:")
|
44 |
|
45 |
get_button.click(get_data, inputs=password_input, outputs=output_text)
|
46 |
+
send_button.click(send_data, inputs=[password_input, text_input], outputs=output_text)
|
47 |
|
48 |
demo.launch()
|