awacke1 commited on
Commit
4eb173a
·
1 Parent(s): 5484a40

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -47
app.py CHANGED
@@ -1,54 +1,27 @@
1
- import base64
2
- import graphviz as gv
3
  import streamlit as st
 
 
 
 
4
 
5
- # Define a function that renders the card using Graphviz
6
- def render_card(image_path, title, subtitle):
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
- # Define the file uploader
33
- uploaded_file = st.file_uploader('Upload an image', type=['jpg', 'jpeg', 'png'])
 
34
 
35
- # Define the card title and subtitle inputs
36
- title = st.text_input('Title')
37
- subtitle = st.text_input('Subtitle')
38
 
39
- # Render the card if an image has been uploaded and a title has been provided
40
- if uploaded_file and title:
41
- image_path = f'{uploaded_file.name}'
42
- with open(image_path, 'wb') as f:
43
- f.write(uploaded_file.getbuffer())
44
- card = render_card(image_path, title, subtitle)
45
- st.image(card, use_column_width=True)
46
 
47
- # Define the download button
48
- b64_card = base64.b64encode(card.encode()).decode()
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
- # Run the Streamlit app
53
- if __name__ == '__main__':
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)