Straive-Kripa commited on
Commit
c05e03d
·
verified ·
1 Parent(s): fb5ee83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -6,6 +6,27 @@ def upload_file(filepath):
6
  name = Path(filepath).name
7
  return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download {name}", value=filepath, visible=True)]
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  def download_file():
10
  return [gr.UploadButton(visible=True), gr.DownloadButton(visible=False)]
11
 
@@ -13,10 +34,11 @@ with gr.Blocks() as demo:
13
  gr.Markdown("First upload a file and and then you'll be able download it (but only once!)")
14
  gr.Markdown("PII Anonymized:"+pii_anonymizer.anonymize_text_including_proper_nouns_and_addresses("Hello Kripa"))
15
  with gr.Row():
16
- u = gr.UploadButton("Upload a file", file_count="single")
17
  d = gr.DownloadButton("Download the file", visible=False)
18
 
19
- u.upload(upload_file, u, [u, d])
 
20
  d.click(download_file, None, [u, d])
21
 
22
 
 
6
  name = Path(filepath).name
7
  return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download {name}", value=filepath, visible=True)]
8
 
9
+ def scrub_file(filepath):
10
+ # Temporary list to hold stripped lines
11
+ stripped_lines = []
12
+
13
+ # Open the original file and strip each line
14
+ with open(filepath, 'r', encoding='utf-8') as file:
15
+ for line in file:
16
+ stripped_lines.append(line.strip())
17
+
18
+ # Overwrite the original file with stripped lines
19
+ with open(filepath, 'w', encoding='utf-8') as file:
20
+ for line in stripped_lines:
21
+ file.write(line + '\n') # Add '\n' to keep the file structure
22
+
23
+ # Extract the filename for the download button label
24
+ name = Path(filepath).name
25
+
26
+ # Return the Gradio interface elements
27
+ return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download {name}", value=filepath, visible=True)]
28
+
29
+
30
  def download_file():
31
  return [gr.UploadButton(visible=True), gr.DownloadButton(visible=False)]
32
 
 
34
  gr.Markdown("First upload a file and and then you'll be able download it (but only once!)")
35
  gr.Markdown("PII Anonymized:"+pii_anonymizer.anonymize_text_including_proper_nouns_and_addresses("Hello Kripa"))
36
  with gr.Row():
37
+ u = gr.UploadButton("Upload a file", file_count="single", filetypes=["txt", "csv", "tsv"])
38
  d = gr.DownloadButton("Download the file", visible=False)
39
 
40
+ #u.upload(upload_file, u, [u, d])
41
+ u.upload(scrub_file, u, [u, d])
42
  d.click(download_file, None, [u, d])
43
 
44