Adding delete function.
Browse files
app.py
CHANGED
@@ -25,6 +25,10 @@ def get_query_params(request: gr.Request):
|
|
25 |
|
26 |
# Function to load data from local storage
|
27 |
def load_data():
|
|
|
|
|
|
|
|
|
28 |
if os.path.exists(local_storage_file):
|
29 |
with open(local_storage_file, "r") as file:
|
30 |
data = file.read()
|
@@ -32,13 +36,23 @@ def load_data():
|
|
32 |
else:
|
33 |
return "No data found!"
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
# Create Gradio interface
|
37 |
iface1 = gr.Interface(
|
38 |
fn=get_query_params,
|
39 |
inputs=[],
|
40 |
outputs="text",
|
41 |
-
live=True,
|
42 |
title="Save Data"
|
43 |
)
|
44 |
|
|
|
25 |
|
26 |
# Function to load data from local storage
|
27 |
def load_data():
|
28 |
+
if "secret" not in request.query_params:
|
29 |
+
return
|
30 |
+
if request.query_params["secret"] != "nevergonnagiveyouup":
|
31 |
+
return
|
32 |
if os.path.exists(local_storage_file):
|
33 |
with open(local_storage_file, "r") as file:
|
34 |
data = file.read()
|
|
|
36 |
else:
|
37 |
return "No data found!"
|
38 |
|
39 |
+
def delete_data():
|
40 |
+
if "secret" not in request.query_params:
|
41 |
+
return
|
42 |
+
if request.query_params["secret"] != "nevergonnagiveyouup":
|
43 |
+
return
|
44 |
+
if os.path.exists(local_storage_file):
|
45 |
+
os.remove(local_storage_file)
|
46 |
+
print("Data deleted successfully")
|
47 |
+
else:
|
48 |
+
print("No data found")
|
49 |
+
|
50 |
|
51 |
# Create Gradio interface
|
52 |
iface1 = gr.Interface(
|
53 |
fn=get_query_params,
|
54 |
inputs=[],
|
55 |
outputs="text",
|
|
|
56 |
title="Save Data"
|
57 |
)
|
58 |
|