Spaces:
Runtime error
Runtime error
fix: UI and pdf output
Browse files- main.py +0 -37
- static/index.html +8 -4
- static/script.js +10 -3
main.py
CHANGED
|
@@ -120,43 +120,6 @@ def classifyFiles(file):
|
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
-
# # dict for counting doctypes
|
| 124 |
-
# doctype_dict = dict()
|
| 125 |
-
|
| 126 |
-
# # writer for csv
|
| 127 |
-
# with open("{}/doctype_count.csv".format(output_dir), 'w', newline='') as outcsv:
|
| 128 |
-
# writer = csv.writer(outcsv)
|
| 129 |
-
# writer.writerow(["Type", "Count"])
|
| 130 |
-
|
| 131 |
-
# for file in files:
|
| 132 |
-
# try:
|
| 133 |
-
# contents = file.file.read()
|
| 134 |
-
# classify_res = classify_acct_dtype_str(BytesIO(contents))
|
| 135 |
-
# except Exception as err:
|
| 136 |
-
# print(Exception, err)
|
| 137 |
-
# return {"message": "There was an error in uploading file(s)"}
|
| 138 |
-
# finally:
|
| 139 |
-
# file.file.close()
|
| 140 |
-
|
| 141 |
-
# print(classify_res)
|
| 142 |
-
|
| 143 |
-
# if (classify_res in doctype_dict):
|
| 144 |
-
# doctype_dict.update({classify_res : doctype_dict[classify_res] + 1})
|
| 145 |
-
# else:
|
| 146 |
-
# doctype_dict.update({classify_res : 1})
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
# export_media_type = 'text/csv'
|
| 151 |
-
# export_headers = {
|
| 152 |
-
# "Content-Disposition": "attachment; filename={file_name}.csv".format(file_name="output")
|
| 153 |
-
# }
|
| 154 |
-
# return StreamingResponse(csv_file_binary, headers=export_headers, media_type=export_media_type)
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
|
| 161 |
|
| 162 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
|
|
|
| 120 |
|
| 121 |
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
|
| 125 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
static/index.html
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
<title>Fast API 🤗 Space served with Uvicorn</title>
|
|
|
|
| 7 |
<link rel="stylesheet" href="style.css" />
|
| 8 |
<script type="module" src="script.js"></script>
|
| 9 |
</head>
|
|
@@ -19,12 +20,15 @@
|
|
| 19 |
target="_blank">donutclassifier_acctdocs_by_doctype</a>
|
| 20 |
</p>
|
| 21 |
<form class="doc-classification-form">
|
| 22 |
-
<
|
| 23 |
-
|
| 24 |
-
<
|
| 25 |
-
</
|
|
|
|
|
|
|
| 26 |
</form>
|
| 27 |
</section>
|
| 28 |
</main>
|
|
|
|
| 29 |
</body>
|
| 30 |
</html>
|
|
|
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
<title>Fast API 🤗 Space served with Uvicorn</title>
|
| 7 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
| 8 |
<link rel="stylesheet" href="style.css" />
|
| 9 |
<script type="module" src="script.js"></script>
|
| 10 |
</head>
|
|
|
|
| 20 |
target="_blank">donutclassifier_acctdocs_by_doctype</a>
|
| 21 |
</p>
|
| 22 |
<form class="doc-classification-form">
|
| 23 |
+
<div class="input-group mb-3">
|
| 24 |
+
<label class="input-group-text" for="doc-input">Upload document</label>
|
| 25 |
+
<input id="doc-input" class="form-control" type="file" multiple="multiple" accept="image/jpeg, image/png, image/jpg, application/pdf">
|
| 26 |
+
</div>
|
| 27 |
+
|
| 28 |
+
<a id="doc-output-link" role="button" class="btn btn-primary disabled" tabindex="-1">Download</a>
|
| 29 |
</form>
|
| 30 |
</section>
|
| 31 |
</main>
|
| 32 |
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.min.js" integrity="sha384-BBtl+eGJRgqQAUMxJ7pMwbEyER4l1g+O15P+16Ep7Q9Q+zqX6gSbd85u4mG4QzX+" crossorigin="anonymous"></script>
|
| 33 |
</body>
|
| 34 |
</html>
|
static/script.js
CHANGED
|
@@ -17,13 +17,20 @@ const outputDocLink = document.getElementById('doc-output-link');
|
|
| 17 |
|
| 18 |
inputDoc.addEventListener("change", async event =>{
|
| 19 |
/* hide Download button when in classification process */
|
| 20 |
-
outputDocLink.style.visibility = "hidden";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
const files = event.target.files;
|
| 22 |
|
| 23 |
/* make Download button's visible, and add the link to download the resulting .csv file */
|
| 24 |
await classifyImages(files).then(async (result) => {
|
| 25 |
-
outputDocLink.style.visibility = "visible";
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
const disposition = result.headers.get('Content-Disposition');
|
| 29 |
const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
|
|
|
| 17 |
|
| 18 |
inputDoc.addEventListener("change", async event =>{
|
| 19 |
/* hide Download button when in classification process */
|
| 20 |
+
// outputDocLink.style.visibility = "hidden";
|
| 21 |
+
|
| 22 |
+
// dlOutputBtn.disabled = true;
|
| 23 |
+
outputDocLink.ariaDisabled = "true";
|
| 24 |
+
outputDocLink.classList.add("disabled");
|
| 25 |
+
|
| 26 |
const files = event.target.files;
|
| 27 |
|
| 28 |
/* make Download button's visible, and add the link to download the resulting .csv file */
|
| 29 |
await classifyImages(files).then(async (result) => {
|
| 30 |
+
// outputDocLink.style.visibility = "visible";
|
| 31 |
+
// dlOutputBtn.disabled = false;
|
| 32 |
+
outputDocLink.ariaDisabled = "false";
|
| 33 |
+
outputDocLink.classList.remove("disabled");
|
| 34 |
|
| 35 |
const disposition = result.headers.get('Content-Disposition');
|
| 36 |
const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|