Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,27 @@
|
|
1 |
-
import base64
|
2 |
-
import graphviz as gv
|
3 |
import streamlit as st
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
# Define the Graphviz graph
|
8 |
-
g = gv.Graph(format='png')
|
9 |
-
g.attr(bgcolor='white', margin='0')
|
10 |
-
|
11 |
-
# Add the background image to the graph
|
12 |
-
with open(image_path, 'rb') as f:
|
13 |
-
data = f.read()
|
14 |
-
b64_image = base64.b64encode(data).decode()
|
15 |
-
g.node('background', image=f'data:image/png;base64,{b64_image}', shape='box', width='3.5', height='5')
|
16 |
-
|
17 |
-
# Add the title and subtitle to the graph
|
18 |
-
g.node('title', label=title, fontname='Arial', fontsize='16', shape='none', width='2')
|
19 |
-
g.node('subtitle', label=subtitle, fontname='Arial', fontsize='12', shape='none', width='2')
|
20 |
-
|
21 |
-
# Add edges between the nodes
|
22 |
-
g.edge('background', 'title', color='white', style='invis')
|
23 |
-
g.edge('background', 'subtitle', color='white', style='invis')
|
24 |
-
|
25 |
-
# Render the graph and return the PNG data
|
26 |
-
return g.pipe().decode('utf-8')
|
27 |
-
|
28 |
-
# Define the Streamlit app
|
29 |
-
def app():
|
30 |
-
st.title('Card Builder Evolver')
|
31 |
|
32 |
-
|
33 |
-
|
|
|
34 |
|
35 |
-
#
|
36 |
-
|
37 |
-
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
f.write(uploaded_file.getbuffer())
|
44 |
-
card = render_card(image_path, title, subtitle)
|
45 |
-
st.image(card, use_column_width=True)
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
href = f'<a href="data:image/png;base64,{b64_card}" download="card.png">Download card</a>'
|
50 |
-
st.markdown(href, unsafe_allow_html=True)
|
51 |
|
52 |
-
#
|
53 |
-
|
54 |
-
app()
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from io import StringIO
|
4 |
+
from PIL import Image
|
5 |
+
import graphviz as gv
|
6 |
|
7 |
+
uploaded_files = st.file_uploader("Choose an image file", accept_multiple_files=True, type=["jpg", "jpeg", "png"])
|
8 |
+
images = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
for uploaded_file in uploaded_files:
|
11 |
+
# To read file as bytes:
|
12 |
+
bytes_data = uploaded_file.getvalue()
|
13 |
|
14 |
+
# To convert to a PIL image:
|
15 |
+
image = Image.open(uploaded_file)
|
16 |
+
images.append(image)
|
17 |
|
18 |
+
# Create the Graphviz model using the uploaded images
|
19 |
+
dot = gv.Digraph()
|
20 |
+
for i, image in enumerate(images):
|
21 |
+
dot.node(str(i), image=image)
|
|
|
|
|
|
|
22 |
|
23 |
+
for i in range(len(images) - 1):
|
24 |
+
dot.edge(str(i), str(i+1))
|
|
|
|
|
25 |
|
26 |
+
# Render the Graphviz model using the Streamlit framework
|
27 |
+
st.graphviz_chart(dot.source)
|
|