awacke1 commited on
Commit
9c6079a
·
1 Parent(s): 1fd8395

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import streamlit as st
2
  import os
 
 
3
 
4
  uploaded_images = {'characters': {}, 'terrain': {}}
5
 
@@ -10,6 +12,31 @@ def get_image_path(img, name, image_type):
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)
@@ -21,6 +48,7 @@ for uploaded_file in uploaded_files:
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
  if image_type == 'characters':
26
  if uploaded_images['characters']:
@@ -40,3 +68,8 @@ else:
40
  row = []
41
  if row:
42
  st.image(row, width=100 * len(row)) # Last row, if not complete
 
 
 
 
 
 
1
  import streamlit as st
2
  import os
3
+ import csv
4
+ import time
5
 
6
  uploaded_images = {'characters': {}, 'terrain': {}}
7
 
 
12
  img_file.write(img.getbuffer())
13
  return file_path
14
 
15
+ def update_csv_file(uploaded_file, name, image_type):
16
+ csv_file_path = "Resources.csv"
17
+ with open(csv_file_path, mode='a', newline='') as csv_file:
18
+ csv_writer = csv.writer(csv_file)
19
+ csv_writer.writerow([name, uploaded_file.name, image_type])
20
+
21
+ def get_uploaded_files_info():
22
+ csv_file_path = "Resources.csv"
23
+ with open(csv_file_path, mode='r') as csv_file:
24
+ csv_reader = csv.reader(csv_file)
25
+ files_info = []
26
+ for row in csv_reader:
27
+ files_info.append(row)
28
+ return files_info
29
+
30
+ def display_images_from_csv():
31
+ files_info = get_uploaded_files_info()
32
+ for row in files_info:
33
+ if row[2] == 'characters':
34
+ img_path = f"data/uploadedImages/{row[2]}/{row[0]}/{row[1]}"
35
+ st.sidebar.image(img_path, width=100, caption=row[0])
36
+ else:
37
+ img_path = f"data/uploadedImages/{row[2]}/{row[0]}/{row[1]}"
38
+ st.image(img_path, width=100, caption=row[0])
39
+
40
  image_type = st.selectbox('Choose image type:', options=['characters', 'terrain'])
41
  name = st.text_input('Enter a name for the image:')
42
  uploaded_files = st.file_uploader('Upload image(s)', type=['png', 'jpg'], accept_multiple_files=True)
 
48
  uploaded_images[image_type].setdefault(name, [])
49
  uploaded_images[image_type][name].append(bytes_data)
50
  st.image(bytes_data, use_column_width=True)
51
+ update_csv_file(uploaded_file, name, image_type)
52
 
53
  if image_type == 'characters':
54
  if uploaded_images['characters']:
 
68
  row = []
69
  if row:
70
  st.image(row, width=100 * len(row)) # Last row, if not complete
71
+
72
+ while True:
73
+ time.sleep(20)
74
+ st.empty()
75
+ display_images_from_csv()