ncoop57
commited on
Commit
•
883ac11
1
Parent(s):
8f55818
Add cardifying additional content
Browse files
app.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import json
|
|
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
|
@@ -6,16 +8,46 @@ from autocards.autocards import Autocards
|
|
6 |
|
7 |
AUTO = Autocards()
|
8 |
|
9 |
-
def cardify(content):
|
10 |
global AUTO
|
11 |
|
12 |
AUTO.clear_qa()
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
AUTO.to_json("output.json", prefix="")
|
15 |
with open("output_basic.json") as f:
|
16 |
res = json.load(f)
|
|
|
|
|
|
|
|
|
17 |
|
18 |
return json.dumps(res)
|
19 |
|
20 |
-
iface = gr.Interface(
|
|
|
|
|
|
|
|
|
21 |
iface.launch()
|
|
|
1 |
import json
|
2 |
+
import os
|
3 |
+
import requests
|
4 |
|
5 |
import gradio as gr
|
6 |
|
|
|
8 |
|
9 |
AUTO = Autocards()
|
10 |
|
11 |
+
def cardify(content, mode):
|
12 |
global AUTO
|
13 |
|
14 |
AUTO.clear_qa()
|
15 |
+
if mode != "raw" and mode != "url":
|
16 |
+
r = requests.get(content)
|
17 |
+
if mode == "pdf":
|
18 |
+
with open("temp.pdf", 'wb') as f:
|
19 |
+
f.write(r.content)
|
20 |
+
AUTO.consume_pdf(content)
|
21 |
+
os.remove("temp.pdf")
|
22 |
+
elif mode == "epub":
|
23 |
+
with open("temp.epub", 'wb') as f:
|
24 |
+
f.write(r.content)
|
25 |
+
AUTO.consume_epub(content)
|
26 |
+
os.remove("temp.epub")
|
27 |
+
elif mode == "textfile":
|
28 |
+
with open("temp.txt", 'w') as f:
|
29 |
+
f.write(r.text)
|
30 |
+
AUTO.consume_textfile(content)
|
31 |
+
os.remove("temp.txt")
|
32 |
+
else:
|
33 |
+
if mode == "raw":
|
34 |
+
AUTO.consume_var(content)
|
35 |
+
elif mode == "url":
|
36 |
+
AUTO.consume_web(content)
|
37 |
+
|
38 |
AUTO.to_json("output.json", prefix="")
|
39 |
with open("output_basic.json") as f:
|
40 |
res = json.load(f)
|
41 |
+
|
42 |
+
# delete the output files
|
43 |
+
os.remove("output_basic.json")
|
44 |
+
os.remove("output_cloze.json")
|
45 |
|
46 |
return json.dumps(res)
|
47 |
|
48 |
+
iface = gr.Interface(
|
49 |
+
fn=cardify,
|
50 |
+
inputs=["text", gr.Radio(["pdf", "epub", "raw", "textfile", "url"])],
|
51 |
+
outputs="text"
|
52 |
+
)
|
53 |
iface.launch()
|