awacke1 commited on
Commit
510fdbb
·
1 Parent(s): 0331cab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  import pandas as pd
3
  from PIL import Image
 
4
 
5
  # Define the function signature
6
  def display_data(data: pd.DataFrame):
@@ -9,7 +10,7 @@ def display_data(data: pd.DataFrame):
9
  # Create the Streamlit app
10
  def main():
11
  st.title("Upload Files and Display Data in Function Signature")
12
-
13
  # Create an upload form for CSV files
14
  st.subheader("Upload CSV Files")
15
  csv_file = st.file_uploader("Choose a CSV file", type=["csv"])
@@ -17,15 +18,25 @@ def main():
17
  # Create an upload form for image files
18
  st.subheader("Upload Image Files")
19
  image_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
20
-
 
 
 
 
 
 
21
  # Check if files are uploaded and display data in function signature
22
  if csv_file is not None:
23
- data = pd.read_csv(csv_file)
 
 
24
  display_data(data)
25
-
26
  if image_file is not None:
27
- image = Image.open(image_file)
 
 
28
  st.image(image, caption="Uploaded Image")
29
-
30
  if __name__ == "__main__":
31
  main()
 
1
  import streamlit as st
2
  import pandas as pd
3
  from PIL import Image
4
+ import os
5
 
6
  # Define the function signature
7
  def display_data(data: pd.DataFrame):
 
10
  # Create the Streamlit app
11
  def main():
12
  st.title("Upload Files and Display Data in Function Signature")
13
+
14
  # Create an upload form for CSV files
15
  st.subheader("Upload CSV Files")
16
  csv_file = st.file_uploader("Choose a CSV file", type=["csv"])
 
18
  # Create an upload form for image files
19
  st.subheader("Upload Image Files")
20
  image_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
21
+
22
+ # Add OS file listing of uploaded files
23
+ st.subheader("Uploaded Files")
24
+ files = os.listdir("uploads")
25
+ for file in files:
26
+ st.markdown(f"[{file}]({os.path.join('uploads', file)})")
27
+
28
  # Check if files are uploaded and display data in function signature
29
  if csv_file is not None:
30
+ with open(os.path.join("uploads", csv_file.name), "wb") as f:
31
+ f.write(csv_file.getbuffer())
32
+ data = pd.read_csv(os.path.join("uploads", csv_file.name))
33
  display_data(data)
34
+
35
  if image_file is not None:
36
+ with open(os.path.join("uploads", image_file.name), "wb") as f:
37
+ f.write(image_file.getbuffer())
38
+ image = Image.open(os.path.join("uploads", image_file.name))
39
  st.image(image, caption="Uploaded Image")
40
+
41
  if __name__ == "__main__":
42
  main()