m3g4p0p commited on
Commit
9c9e714
·
1 Parent(s): 86fc953

add buffer

Browse files
Files changed (1) hide show
  1. myapp/app.py +7 -7
myapp/app.py CHANGED
@@ -1,7 +1,6 @@
1
  import re
2
  from functools import partial
3
- from pathlib import Path
4
- from tempfile import NamedTemporaryFile
5
  from typing import Any
6
 
7
  import gradio as gr
@@ -63,20 +62,21 @@ with gr.Blocks() as demo:
63
 
64
  return f"#{r:x}{g:x}{b:x}".upper()
65
 
 
66
  qr_code = segno.make(data[text], error="h")
67
- suffix = Path(data[background]).suffix
68
 
69
- with NamedTemporaryFile(suffix=suffix) as temp_file:
70
  write_artistic(
71
  qr_code,
72
- target=temp_file,
73
- background=data[background],
 
74
  scale=data[scale],
75
  light=to_hex_format(data[color_light]),
76
  dark=to_hex_format(data[color_dark]),
77
  )
78
 
79
- return Image.open(temp_file.name)
80
 
81
  gr.on(
82
  [button.click, prompt.submit],
 
1
  import re
2
  from functools import partial
3
+ from io import BytesIO
 
4
  from typing import Any
5
 
6
  import gradio as gr
 
62
 
63
  return f"#{r:x}{g:x}{b:x}".upper()
64
 
65
+ image = Image.open(data[background])
66
  qr_code = segno.make(data[text], error="h")
 
67
 
68
+ with BytesIO() as buffer:
69
  write_artistic(
70
  qr_code,
71
+ target=buffer,
72
+ background=image.fp,
73
+ kind=image.format,
74
  scale=data[scale],
75
  light=to_hex_format(data[color_light]),
76
  dark=to_hex_format(data[color_dark]),
77
  )
78
 
79
+ return Image.open(buffer)
80
 
81
  gr.on(
82
  [button.click, prompt.submit],