File size: 1,881 Bytes
f8b1353
8b8400a
f8b1353
8b8400a
 
 
fd207f2
ce59b01
 
8b8400a
 
3b45285
 
76374c1
8b8400a
3b45285
8b8400a
3b45285
8b8400a
 
 
 
 
 
fd207f2
 
150077a
8b8400a
 
 
 
 
 
 
fd207f2
 
150077a
717e95e
 
a620d06
717e95e
a620d06
717e95e
8b8400a
 
3b45285
c742adc
8b8400a
 
 
 
 
 
a8e6637
8b8400a
 
 
 
319a4e8
 
96f218f
319a4e8
 
 
 
8b8400a
319a4e8
8b8400a
 
f8b1353
8b8400a
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
import gradio as gr
import os

# Define the path to the local storage file
local_storage_file = "local_storage.txt"

# Specify the secret value
save_secret_value = os.getenv("save_secret_value")
secret_value = os.getenv("secret_value")

# Function to retrieve data from query parameters in the URL
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!"


# Function to load data from local storage
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"

# Create Gradio interface
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"
)

# Combine interfaces
demo = gr.TabbedInterface([iface1, iface2, iface3], ["Save Data", "Load Data", "Delete Data"])

# Launch the app
demo.launch()