admin08077 commited on
Commit
28f3f7c
·
verified ·
1 Parent(s): 13b4b26

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -1,7 +1,9 @@
1
  import streamlit as st
 
 
 
2
  from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageEnhance, ImageOps, ImageChops, ImageColor
3
  import numpy as np
4
- import io
5
  import os
6
  import json
7
  from rembg import remove
@@ -9,6 +11,22 @@ import requests
9
  from pathlib import Path
10
  from streamlit_drawable_canvas import st_canvas
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # ------------------------------
13
  # Utility Functions
14
  # ------------------------------
 
1
  import streamlit as st
2
+ from streamlit.elements import image as st_image
3
+ import base64
4
+ import io
5
  from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageEnhance, ImageOps, ImageChops, ImageColor
6
  import numpy as np
 
7
  import os
8
  import json
9
  from rembg import remove
 
11
  from pathlib import Path
12
  from streamlit_drawable_canvas import st_canvas
13
 
14
+ # ------------------------------
15
+ # Monkey-Patch to Add image_to_url
16
+ # ------------------------------
17
+
18
+ def image_to_url(image):
19
+ """
20
+ Converts a PIL Image to a data URL.
21
+ """
22
+ buffered = io.BytesIO()
23
+ image.save(buffered, format="PNG")
24
+ img_str = base64.b64encode(buffered.getvalue()).decode()
25
+ return f"data:image/png;base64,{img_str}"
26
+
27
+ # Monkey-patch the image_to_url method
28
+ st_image.image_to_url = image_to_url
29
+
30
  # ------------------------------
31
  # Utility Functions
32
  # ------------------------------