|
import gradio as gr |
|
import os |
|
|
|
|
|
local_storage_file = "local_storage.txt" |
|
|
|
|
|
save_secret_value = os.getenv("save_secret_value") |
|
secret_value = os.getenv("secret_value") |
|
|
|
|
|
def save_data(secret, dataset, filename=None): |
|
if secret != save_secret_value: |
|
return "Secret is incorrect" |
|
data = "" |
|
if filename: |
|
data = data + "\n" + filename + "\n" |
|
data = data + dataset |
|
with open(local_storage_file, "a+") as file: |
|
file.write(data) |
|
return "Data saved successfully!" |
|
|
|
|
|
|
|
def load_data(secret): |
|
if secret != secret_value: |
|
return "Secret is incorrect" |
|
if os.path.exists(local_storage_file): |
|
with open(local_storage_file, "r") as file: |
|
data = file.read() |
|
return data |
|
else: |
|
return "No data found!" |
|
|
|
def delete_data(secret): |
|
if secret != secret_value: |
|
return "Secret is incorrect" |
|
if os.path.exists(local_storage_file): |
|
os.remove(local_storage_file) |
|
return "Data deleted successfully" |
|
else: |
|
return "No data found" |
|
|
|
|
|
iface1 = gr.Interface( |
|
fn=save_data, |
|
inputs=[gr.Textbox(label="Secret", type="password", render=False), "text", "text"], |
|
outputs="text", |
|
title="Save Data" |
|
) |
|
|
|
iface2 = gr.Interface( |
|
fn=load_data, |
|
inputs=gr.Textbox(label="Secret", type="password", render=False), |
|
outputs="text", |
|
title="Load Data" |
|
) |
|
|
|
iface3 = gr.Interface( |
|
fn=delete_data, |
|
inputs=gr.Textbox(label="Secret", type="password", render=False), |
|
outputs="text", |
|
title="Delete Data" |
|
) |
|
|
|
|
|
demo = gr.TabbedInterface([iface1, iface2, iface3], ["Save Data", "Load Data", "Delete Data"]) |
|
|
|
|
|
demo.launch() |
|
|
|
|