File size: 3,300 Bytes
1ba0699
 
 
d18a176
 
 
 
 
 
1ba0699
 
d18a176
1ba0699
 
 
9c876a9
1ba0699
113590b
d18a176
113590b
 
 
d18a176
 
113590b
d18a176
 
113590b
 
1ba0699
94b7a9f
 
1846b35
39e03e0
 
 
 
 
 
 
 
 
 
 
 
 
1846b35
39e03e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1846b35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94b7a9f
 
 
1ba0699
 
 
 
 
 
 
 
 
 
 
113590b
1ba0699
d18a176
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import gradio as gr
import os

# Загрузка данных с диска, если они есть
try:
    with open("data.txt", "r") as f:
        data = f.read()
except FileNotFoundError:
    data = ""

def get_data(password):
    """Функция для получения данных с диска."""
    if password == os.environ.get("password"):
        return data
    else:
        raise gr.Error("Неверный пароль!")

def send_data(password, text):
    """Функция для сохранения данных на диск."""
    if password == os.environ.get("password"):
        global data
        data = text
        with open("data.txt", "w") as f:
            f.write(data)
        raise gr.Info("Данные успешно сохранены!")
        with open("data.txt", "r") as l:
            return l.read()
    else:
        raise gr.Error("Неверный пароль!")

css = """
footer {visibility: hidden !important;}

.dark {
    --container-radius: 18px !important;
    --block-border-width: 0px !important;
    --block-radius: 18px !important;
    --border-color-primary: #2c0039 !important;
    --block-background-fill: #202020 !important;
    --body-background-fill: #000000 !important;
    --input-background-fill: #151515 !important;
    --input-radius: 14px !important;
    --checkbox-label-border-width: 0px !important;
    --block-label-border-width: 0px !important;
    --input-border-width: 0px !important;
}

.primary {
    color: #FFF !important;
    font-size: 16px !important;
    padding: 10px 20px !important;
    border: 3px solid rgb(234 181 238) !important;
    border-radius: 15px !important;
    text-decoration: none !important;
    transition: 0.5s ease-in-out !important;
    font-weight: normal !important;
    background: none !important;
}
.primary:hover {
    background: rgb(234 181 238) !important;
    color: #000 !important;
}
div.svelte-19hvt5v {
    border: 0px solid #510067 !important;
    background: #101010;
}
.selected.svelte-1uw5tnk {
    border-color: #510067 !important;
    border-width: 0px !important;
}
.tab-nav.svelte-1uw5tnk {
    border-bottom: 0px solid #510067 !important;
}
.secondary {
    color: #FFF !important;
    font-size: 18px !important;
    border: 3px solid rgb(96 55 103) !important;
    border-radius: 20px !important;
    transition: background-color 0.5s ease-in-out !important;
    width: 100% !important;
    background-color: transparent !important;
    height: 50px !important;
    font-weight: bold !important;
    align-items: center !important;
    justify-content: center !important;
}
.secondary:hover {
    background-color: rgb(96 55 103);
}
"""

with gr.Blocks(css=css) as demo:
    with gr.Row():
        password_input = gr.Textbox(type="password", label="Введите пароль:")
    with gr.Row():
        text_input = gr.Textbox(label="Введите текст:")
    with gr.Row():
        get_button = gr.Button("Получить")
        send_button = gr.Button("Отправить")
    with gr.Row():
        output_text = gr.Textbox(label="Результат:")

    get_button.click(get_data, inputs=password_input, outputs=output_text)
    send_button.click(send_data, inputs=[password_input, text_input], outputs=output_text)

demo.launch()