awacke1 commited on
Commit
53d73ab
·
1 Parent(s): cb9f2f7

Update backup-app.py

Browse files
Files changed (1) hide show
  1. backup-app.py +34 -7
backup-app.py CHANGED
@@ -1,15 +1,42 @@
1
  import streamlit as st
2
  import os
3
 
4
- def get_image_path(img):
5
- file_path = f"data/uploadedImages/{img.name}"
 
 
6
  os.makedirs(os.path.dirname(file_path), exist_ok=True)
7
  with open(file_path, "wb") as img_file:
8
  img_file.write(img.getbuffer())
9
  return file_path
10
 
11
- uploaded_file = st.file_uploader("**Upload Image**", type= ['png', 'jpg'] )
12
- if uploaded_file is not None:
13
- # Get actual image file
14
- bytes_data = get_image_path(uploaded_file)
15
- st.image(bytes_data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import os
3
 
4
+ uploaded_images = {'characters': {}, 'terrain': {}}
5
+
6
+ def get_image_path(img, name, image_type):
7
+ file_path = f"data/uploadedImages/{image_type}/{name}/{img.name}"
8
  os.makedirs(os.path.dirname(file_path), exist_ok=True)
9
  with open(file_path, "wb") as img_file:
10
  img_file.write(img.getbuffer())
11
  return file_path
12
 
13
+ image_type = st.selectbox('Choose image type:', options=['characters', 'terrain'])
14
+ name = st.text_input('Enter a name for the image:')
15
+ uploaded_files = st.file_uploader('Upload image(s)', type=['png', 'jpg'], accept_multiple_files=True)
16
+
17
+ for uploaded_file in uploaded_files:
18
+ if uploaded_file is not None:
19
+ # Get actual image file
20
+ bytes_data = get_image_path(uploaded_file, name, image_type)
21
+ uploaded_images[image_type].setdefault(name, [])
22
+ uploaded_images[image_type][name].append(bytes_data)
23
+ st.image(bytes_data, use_column_width=True)
24
+
25
+ # Display character images on the left and terrain images on the right
26
+ if uploaded_images['characters']:
27
+ st.sidebar.write('**Characters**')
28
+ for name, files in uploaded_images['characters'].items():
29
+ for file in files:
30
+ st.sidebar.image(file, width=100, caption=name)
31
+
32
+ if uploaded_images['terrain']:
33
+ st.write('**Terrain**')
34
+ row = []
35
+ for name, files in uploaded_images['terrain'].items():
36
+ for file in files:
37
+ row.append(file)
38
+ if len(row) == 3:
39
+ st.image(row, width=100 * 3)
40
+ row = []
41
+ if row:
42
+ st.image(row, width=100 * len(row)) # Last row, if not complete