hltdx commited on
Commit
8b8400a
·
unverified ·
1 Parent(s): 2e97062

Adding local file storage.

Browse files
Files changed (1) hide show
  1. app.py +55 -3
app.py CHANGED
@@ -1,8 +1,60 @@
1
  import gradio as gr
 
 
2
 
 
 
 
 
 
3
  def get_query_params(request: gr.Request):
4
- query_params = request.query_params
5
- return f"Query Parameters: {query_params}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- demo = gr.Interface(fn=get_query_params, inputs=[], outputs="text", live=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  demo.launch()
 
 
1
  import gradio as gr
2
+ import os
3
+ from urllib.parse import urlparse, parse_qs
4
 
5
+ # Define the path to the local storage file
6
+ local_storage_file = "local_storage.txt"
7
+
8
+
9
+ # Function to retrieve data from query parameters in the URL
10
  def get_query_params(request: gr.Request):
11
+ parsed_url = urlparse(request)
12
+ query_params = parse_qs(parsed_url.query)
13
+ if "secret" not in query_params:
14
+ return
15
+ if query_params["secret"] != "nevergonnagiveyouup":
16
+ return
17
+ data = ""
18
+ if "filename" in query_params:
19
+ filename = query_params["filename"]
20
+ data = data + "\n" + filename + "\n"
21
+ if "dataset" in query_params:
22
+ dataset = query_params["dataset"]
23
+ data = data + dataset
24
+ with open(local_storage_file, "a+") as file:
25
+ file.write(data)
26
+ return "Data saved successfully!"
27
+
28
+
29
+ # Function to load data from local storage
30
+ def load_data():
31
+ if os.path.exists(local_storage_file):
32
+ with open(local_storage_file, "r") as file:
33
+ data = file.read()
34
+ return data
35
+ else:
36
+ return "No data found!"
37
+
38
 
39
+ # Create Gradio interface
40
+ iface1 = gr.Interface(
41
+ fn=get_query_params,
42
+ inputs=[],
43
+ outputs="text",
44
+ live=True,
45
+ title="Save Data"
46
+ )
47
+
48
+ iface2 = gr.Interface(
49
+ fn=load_data,
50
+ inputs=[],
51
+ outputs="text",
52
+ title="Load Data"
53
+ )
54
+
55
+ # Combine interfaces
56
+ demo = gr.TabbedInterface([iface1, iface2], ["Save Data", "Load Data"])
57
+
58
+ # Launch the app
59
  demo.launch()
60
+