Spaces:
Runtime error
Runtime error
Liam Dyer
commited on
randomize filename and clean up
Browse files
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(
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|