-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* hijack gradio for faster base64 conversion * Rename files (#15)
- Loading branch information
1 parent
a925976
commit d5b4483
Showing
3 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import numpy as np | ||
from cv2 import imencode | ||
import base64 | ||
import gradio as gr | ||
from lib_inpaint_difference.one_time_callable import one_time_callable | ||
|
||
|
||
@one_time_callable | ||
def hijack_encode_pil_to_base64(): | ||
# from https://github.com/gradio-app/gradio/issues/2635#issuecomment-1423531319 | ||
def encode_pil_to_base64_new(pil_image): | ||
image_arr = np.asarray(pil_image)[:,:,::-1] | ||
_, byte_data = imencode('.png', image_arr) | ||
base64_data = base64.b64encode(byte_data) | ||
base64_string_opencv = base64_data.decode("utf-8") | ||
return "data:image/png;base64," + base64_string_opencv | ||
|
||
gr.processing_utils.encode_pil_to_base64 = encode_pil_to_base64_new |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters