cardify / app.py
ncoop57
Fix radio issue
872ae6a
import json
import os
import requests
import gradio as gr
from autocards.autocards import Autocards
AUTO = Autocards()
def cardify(content, mode):
global AUTO
AUTO.clear_qa()
if mode != "raw" and mode != "url":
r = requests.get(content)
if mode == "pdf":
with open("temp.pdf", 'wb') as f:
f.write(r.content)
AUTO.consume_pdf(content)
os.remove("temp.pdf")
elif mode == "epub":
with open("temp.epub", 'wb') as f:
f.write(r.content)
AUTO.consume_epub(content)
os.remove("temp.epub")
elif mode == "textfile":
with open("temp.txt", 'w') as f:
f.write(r.text)
AUTO.consume_textfile(content)
os.remove("temp.txt")
else:
if mode == "raw":
AUTO.consume_var(content)
elif mode == "url":
AUTO.consume_web(content)
AUTO.to_json("output.json", prefix="")
with open("output_basic.json") as f:
res = json.load(f)
# delete the output files
os.remove("output_basic.json")
os.remove("output_cloze.json")
return json.dumps(res)
iface = gr.Interface(
fn=cardify,
inputs=["text", gr.inputs.Radio(["raw", "epub", "pdf", "textfile", "url"])],
outputs="text"
)
iface.launch()