| import gradio as gr |
| import os |
| import requests |
|
|
| |
| 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_url = "https://aihubyufi-aihub.static.hf.space/style.css" |
|
|
| |
| response = requests.get(css_url) |
| css = response.text |
|
|
| 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() |