File size: 1,285 Bytes
1ba0699
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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:
        return "Неверный пароль!"

def send_data(text):
    """Функция для сохранения данных на диск."""
    global data
    data = text
    with open("data.txt", "w") as f:
        f.write(data)
    return "Данные успешно сохранены!"

with gr.Blocks() 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=text_input, outputs=output_text)

demo.launch()