|
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() |