YoBatM commited on
Commit
fb2826f
·
verified ·
1 Parent(s): e334184

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -8,6 +8,9 @@ from pdf2image.exceptions import (
8
  PDFPageCountError,
9
  PDFSyntaxError
10
  )
 
 
 
11
  def format(codigo:str):
12
  return f"""\\documentclass{{article}}
13
  \\begin{{document}}
@@ -19,11 +22,11 @@ def get_bytes_value(image):
19
  img_byte_arr = io.BytesIO()
20
  image.save(img_byte_arr, format='JPEG')
21
  return img_byte_arr.getvalue()
22
- imags=[]
23
  templates = Jinja2Templates(directory="templates")
24
  @app.get("/image",response_class=Response)
25
  def img(request: Request):
26
- return Response(content=b64.b64decode(images[0]),media_type="image/jpeg") if len(images)>0 else "No image"
27
  @app.get("/",response_class=HTMLResponse)
28
  def test(request: Request,q:str="ls",body:bool=True):
29
  with open("./v.tex","w") as k:
@@ -32,13 +35,12 @@ def test(request: Request,q:str="ls",body:bool=True):
32
  if r.stderr:
33
  return r.stderr
34
  else:
35
- global imgs
36
 
37
  images=convert_from_path("v.pdf")
38
  images[0].save("v.jpg",format="JPEG")
39
  with open("v.jpg","rb") as t:
40
  v=b64.b64encode(t.read()).decode('UTF-8')
41
- imgs=[v]
42
  return templates.TemplateResponse("latex.html",
43
  {
44
  "q":q,
 
8
  PDFPageCountError,
9
  PDFSyntaxError
10
  )
11
+ class BaseImage:
12
+ img:str=None
13
+
14
  def format(codigo:str):
15
  return f"""\\documentclass{{article}}
16
  \\begin{{document}}
 
22
  img_byte_arr = io.BytesIO()
23
  image.save(img_byte_arr, format='JPEG')
24
  return img_byte_arr.getvalue()
25
+ imags=BaseImage()
26
  templates = Jinja2Templates(directory="templates")
27
  @app.get("/image",response_class=Response)
28
  def img(request: Request):
29
+ return Response(content=b64.b64decode(imgs.img),media_type="image/jpeg") if imags.img else "No image"
30
  @app.get("/",response_class=HTMLResponse)
31
  def test(request: Request,q:str="ls",body:bool=True):
32
  with open("./v.tex","w") as k:
 
35
  if r.stderr:
36
  return r.stderr
37
  else:
 
38
 
39
  images=convert_from_path("v.pdf")
40
  images[0].save("v.jpg",format="JPEG")
41
  with open("v.jpg","rb") as t:
42
  v=b64.b64encode(t.read()).decode('UTF-8')
43
+ imgs.img=v
44
  return templates.TemplateResponse("latex.html",
45
  {
46
  "q":q,