Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -33,6 +33,8 @@ from random import randint, sample
|
|
33 |
from enum import Enum
|
34 |
from re import sub
|
35 |
|
|
|
|
|
36 |
|
37 |
import logging
|
38 |
|
@@ -51,7 +53,7 @@ class QType(Enum):
|
|
51 |
|
52 |
routes = ...
|
53 |
|
54 |
-
|
55 |
|
56 |
middleware = [
|
57 |
Middleware(
|
@@ -67,28 +69,46 @@ sys_random = SystemRandom()
|
|
67 |
|
68 |
#pytesseract.pytesseract.tesseract_cmd = r"C:\Users\Admin\AppData\Local\Programs\Tesseract-OCR\tesseract.exe"
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
async def __mltest(request):
|
72 |
pass
|
73 |
|
74 |
async def __save_temp(request):
|
75 |
-
file_id = sys_random.randbytes(
|
76 |
content = ""
|
77 |
# async with request.form(max_fields=3) as form:
|
78 |
form = await request.json()
|
79 |
content = form['content']
|
80 |
title = form['title']
|
81 |
keywords = form['keywords']
|
82 |
-
|
|
|
|
|
83 |
print(file_id)
|
84 |
return PlainTextResponse(file_id, 200)
|
85 |
|
86 |
async def __get_temp(request, entry = 1):
|
87 |
-
return JSONResponse(
|
88 |
|
89 |
async def __remove_temp(request):
|
90 |
try:
|
91 |
-
|
92 |
except:
|
93 |
return PlainTextResponse("", 500)
|
94 |
|
@@ -362,7 +382,8 @@ async def generate_questions(request):
|
|
362 |
|
363 |
# parse paragraphs from document file
|
364 |
try:
|
365 |
-
|
|
|
366 |
except:
|
367 |
return JSONResponse({}, 500)
|
368 |
|
@@ -495,9 +516,12 @@ async def convert2html(request):
|
|
495 |
|
496 |
async def get_flashcards(request):
|
497 |
# [title, content, keywords]
|
498 |
-
|
|
|
|
|
|
|
499 |
__lang = request.path_params['lang']
|
500 |
-
__keywords = [r.strip() for r in
|
501 |
|
502 |
__tldr = await tldr(__content, __lang)
|
503 |
print(__tldr)
|
|
|
33 |
from enum import Enum
|
34 |
from re import sub
|
35 |
|
36 |
+
import redis.asyncio as redis
|
37 |
+
r = redis.Redis()
|
38 |
|
39 |
import logging
|
40 |
|
|
|
53 |
|
54 |
routes = ...
|
55 |
|
56 |
+
|
57 |
|
58 |
middleware = [
|
59 |
Middleware(
|
|
|
69 |
|
70 |
#pytesseract.pytesseract.tesseract_cmd = r"C:\Users\Admin\AppData\Local\Programs\Tesseract-OCR\tesseract.exe"
|
71 |
|
72 |
+
async def __internal_tmp_w(id, content:any):
|
73 |
+
async with r.pipeline(transaction=True) as pipeline:
|
74 |
+
ok = await pipeline.set(id, json.dumps(content).encode("utf-8")).execute()
|
75 |
+
return ok
|
76 |
+
|
77 |
+
async def __internal_tmp_r(id):
|
78 |
+
async with r.pipeline(transaction=True) as pipeline:
|
79 |
+
res = await (pipeline.get(id).execute())
|
80 |
+
if res[-1] == None:
|
81 |
+
return [None, None, None]
|
82 |
+
res = res[-1].decode("utf-8")
|
83 |
+
return json.loads(res)
|
84 |
+
|
85 |
+
async def __internal_tmp_d(id):
|
86 |
+
async with r.pipeline(transaction=True) as pipeline:
|
87 |
+
res = await (pipeline.del(id).execute())
|
88 |
|
89 |
async def __mltest(request):
|
90 |
pass
|
91 |
|
92 |
async def __save_temp(request):
|
93 |
+
file_id = sys_random.randbytes(20).hex()
|
94 |
content = ""
|
95 |
# async with request.form(max_fields=3) as form:
|
96 |
form = await request.json()
|
97 |
content = form['content']
|
98 |
title = form['title']
|
99 |
keywords = form['keywords']
|
100 |
+
|
101 |
+
await __internal_tmp_w(file_id, [title, content, keywords])
|
102 |
+
|
103 |
print(file_id)
|
104 |
return PlainTextResponse(file_id, 200)
|
105 |
|
106 |
async def __get_temp(request, entry = 1):
|
107 |
+
return JSONResponse(await __internal_tmp_r(request.path_params['id']))
|
108 |
|
109 |
async def __remove_temp(request):
|
110 |
try:
|
111 |
+
__internal_tmp_d(request.path_params['id'])
|
112 |
except:
|
113 |
return PlainTextResponse("", 500)
|
114 |
|
|
|
382 |
|
383 |
# parse paragraphs from document file
|
384 |
try:
|
385 |
+
__cont = await __internal_tmp_r(requests.path_params['id'])
|
386 |
+
__ps = await __parse_paragraphs(__cont[1], batching=True)
|
387 |
except:
|
388 |
return JSONResponse({}, 500)
|
389 |
|
|
|
516 |
|
517 |
async def get_flashcards(request):
|
518 |
# [title, content, keywords]
|
519 |
+
|
520 |
+
__file = await __internal_tmp_r(requests.path_params['id'])
|
521 |
+
__content = __file[1]
|
522 |
+
|
523 |
__lang = request.path_params['lang']
|
524 |
+
__keywords = [r.strip() for r in __file[2] if len(r) > 0]
|
525 |
|
526 |
__tldr = await tldr(__content, __lang)
|
527 |
print(__tldr)
|