Liam Dyer commited on
Commit
efce880
1 Parent(s): 1f0ed21

randomize filename and clean up

Browse files
Files changed (1) hide show
  1. app.py +19 -4
app.py CHANGED
@@ -1,13 +1,28 @@
1
  import gradio as gr
2
  import os
3
  import spaces
 
 
 
 
 
 
 
4
 
5
 
6
  @spaces.GPU
7
- def convert(file):
8
- os.system(f"pandoc {file} -t markdown -o output.md")
9
- with open("output.md", "r") as f:
10
- return f.read()
 
 
 
 
 
 
 
 
11
 
12
 
13
  gr.Interface(
 
1
  import gradio as gr
2
  import os
3
  import spaces
4
+ import string
5
+ import random
6
+
7
+
8
+ def random_word(length):
9
+ letters = string.ascii_lowercase
10
+ return "".join(random.choice(letters) for _ in range(length))
11
 
12
 
13
  @spaces.GPU
14
+ def convert(input_file):
15
+ # Convert the file to markdown with pandoc
16
+ output_file = f"{random_word(16)}.md"
17
+ os.system(f"pandoc {input_file} -t markdown -o {output_file}")
18
+
19
+ # Read the file and delete
20
+ markdown = ""
21
+ with open(output_file, "r") as f:
22
+ markdown = f.read()
23
+ os.remove(output_file)
24
+
25
+ return markdown
26
 
27
 
28
  gr.Interface(