Spaces:
Runtime error
Runtime error
test: classify endpoint
Browse files- main.py +20 -7
- static/index.html +4 -0
- static/script.js +9 -0
main.py
CHANGED
|
@@ -11,10 +11,25 @@ pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
|
|
| 11 |
|
| 12 |
@app.get("/infer_t5")
|
| 13 |
def t5(input):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 20 |
|
|
@@ -25,8 +40,6 @@ def index() -> FileResponse:
|
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
import re
|
| 31 |
import torch
|
| 32 |
from transformers import DonutProcessor, VisionEncoderDecoderModel
|
|
@@ -136,4 +149,4 @@ def classify_acct_dtype_str(input_path):
|
|
| 136 |
|
| 137 |
return dtype_inf
|
| 138 |
|
| 139 |
-
classify_acct_dtype_str("https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg")
|
|
|
|
| 11 |
|
| 12 |
@app.get("/infer_t5")
|
| 13 |
def t5(input):
|
| 14 |
+
output = pipe_flan(input)
|
| 15 |
+
return {"output": output[0]["generated_text"]}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# @app.post("/classify/")
|
| 19 |
+
# async def classify_doc(file: UploadFile):
|
| 20 |
+
# return {"file_size": len(file)}
|
| 21 |
+
|
| 22 |
+
@app.post("/classify/")
|
| 23 |
+
async def classify_doc(files: List[UploadFile] = File(...)):
|
| 24 |
+
for file in files:
|
| 25 |
+
try:
|
| 26 |
+
contents = file.file.read()
|
| 27 |
+
classify_res = classify_acct_dtype_str(contents.stream)
|
| 28 |
+
except Exception:
|
| 29 |
+
return {"message": "There was an error in uploading file(s)"}
|
| 30 |
+
finally:
|
| 31 |
+
file.file.close()
|
| 32 |
+
return {"message": f"Successfuly uploaded {[(file.filename+ " " + classify_res) for file in files]}"}
|
| 33 |
|
| 34 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 35 |
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
|
|
|
|
|
|
|
| 43 |
import re
|
| 44 |
import torch
|
| 45 |
from transformers import DonutProcessor, VisionEncoderDecoderModel
|
|
|
|
| 149 |
|
| 150 |
return dtype_inf
|
| 151 |
|
| 152 |
+
# classify_acct_dtype_str("https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg")
|
static/index.html
CHANGED
|
@@ -31,6 +31,10 @@
|
|
| 31 |
<p class="text-gen-output"></p>
|
| 32 |
</form>
|
| 33 |
</section>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
</main>
|
| 35 |
</body>
|
| 36 |
</html>
|
|
|
|
| 31 |
<p class="text-gen-output"></p>
|
| 32 |
</form>
|
| 33 |
</section>
|
| 34 |
+
<section>
|
| 35 |
+
<button id="img-gen-submit">Submit</button>
|
| 36 |
+
<p class="img-gen-output"></p>
|
| 37 |
+
</section>
|
| 38 |
</main>
|
| 39 |
</body>
|
| 40 |
</html>
|
static/script.js
CHANGED
|
@@ -18,4 +18,13 @@ textGenForm.addEventListener('submit', async (event) => {
|
|
| 18 |
} catch (err) {
|
| 19 |
console.error(err);
|
| 20 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
});
|
|
|
|
| 18 |
} catch (err) {
|
| 19 |
console.error(err);
|
| 20 |
}
|
| 21 |
+
});
|
| 22 |
+
|
| 23 |
+
const imgGenSubmitBtn = document.querySelector('.img-gen-submit');
|
| 24 |
+
|
| 25 |
+
// const getDocClass = async (text)
|
| 26 |
+
|
| 27 |
+
imgGenSubmitBtn.addEventListener('onclick', async(event) => {
|
| 28 |
+
const imgGenInput = document.getElementById('img-gen-input');
|
| 29 |
+
imgGenInput.textContent = "aaa";
|
| 30 |
});
|