Spaces:
Build error
Build error
Create helper.py
Browse files
helper.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
def load_background_image(bg_image):
|
| 6 |
+
"""
|
| 7 |
+
Loads the background image from the uploaded file if provided.
|
| 8 |
+
|
| 9 |
+
Args:
|
| 10 |
+
bg_image: The file uploaded by the user for background.
|
| 11 |
+
|
| 12 |
+
Returns:
|
| 13 |
+
PIL Image object or None if no file is uploaded.
|
| 14 |
+
"""
|
| 15 |
+
return Image.open(bg_image) if bg_image else None
|
| 16 |
+
|
| 17 |
+
def display_canvas_data(canvas_result):
|
| 18 |
+
"""
|
| 19 |
+
Display the image data and JSON object data from the canvas result.
|
| 20 |
+
|
| 21 |
+
Args:
|
| 22 |
+
canvas_result: Result object returned by st_canvas.
|
| 23 |
+
"""
|
| 24 |
+
if canvas_result.image_data is not None:
|
| 25 |
+
st.image(canvas_result.image_data)
|
| 26 |
+
if canvas_result.json_data is not None:
|
| 27 |
+
objects = pd.json_normalize(canvas_result.json_data["objects"]) # Flatten JSON data
|
| 28 |
+
for col in objects.select_dtypes(include=['object']).columns:
|
| 29 |
+
objects[col] = objects[col].astype("str")
|
| 30 |
+
st.dataframe(objects)
|