sshenai commited on
Commit
bd207bb
ยท
verified ยท
1 Parent(s): 320bdd4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "import streamlit as st
2
+ import time
3
+ from PIL import Image # For better image handling
4
+
5
+ # Set page config (appears first)
6
+ st.set_page_config(
7
+ page_title=""Streamlit Components Demo"",
8
+ page_icon=""๐ŸŽˆ"",
9
+ layout=""wide""
10
+ )
11
+
12
+ # Set page title
13
+ st.title(""๐ŸŽˆ Streamlit Components Demo"")
14
+
15
+ # Display text with st.write
16
+ st.write(""""""
17
+
18
+ """""")
19
+
20
+ # File uploader in sidebar for better layout
21
+ with st.sidebar:
22
+ st.header(""Upload File"")
23
+ uploaded_file = st.file_uploader(
24
+ ""Choose an image (JPEG/PNG) or audio (MP3/WAV)"",
25
+ type=['jpg', 'jpeg', 'png', 'mp3', 'wav'],
26
+ accept_multiple_files=False,
27
+ key=""file_uploader""
28
+ )
29
+
30
+ # Main content area
31
+ if uploaded_file is not None:
32
+ # Check if the file is an image
33
+ if uploaded_file.type.startswith('image'):
34
+ st.subheader(""๐Ÿ–ผ๏ธ Image Preview"")
35
+
36
+ # Display image with st.image
37
+ try:
38
+ image = Image.open(uploaded_file)
39
+ st.image(image, caption=""Uploaded Image"", use_column_width=True)
40
+
41
+ # Show spinner while processing
42
+ with st.spinner(""Processing image...""):
43
+ time.sleep(2) # Simulate processing time
44
+ st.success(""โœ… Image processed successfully!"")
45
+ except Exception as e:
46
+ st.error(f""Error loading image: {e}"")
47
+
48
+ # Check if the file is audio
49
+ elif uploaded_file.type.startswith('audio'):
50
+ st.subheader(""๐Ÿ”Š Audio Player"")
51
+
52
+ # Display audio player with st.audio
53
+ st.audio(uploaded_file)
54
+
55
+ # Button to simulate action
56
+ if st.button(""โ–ถ๏ธ Play Audio"", type=""primary""):
57
+ with st.spinner(""Playing audio...""):
58
+ time.sleep(3) # Simulate playback time
59
+ st.success(""๐ŸŽต Audio playback complete!"")
60
+
61
+ else:
62
+ st.warning(""โš ๏ธ Unsupported file type"")
63
+
64
+ # Button outside of upload context
65
+ col1, col2, col3 = st.columns(3)
66
+ with col2:
67
+ if st.button(""๐ŸŽ Click me for a surprise!"", key=""surprise_button""):
68
+ st.balloons()
69
+ st.success(""๐ŸŽ‰ You got balloons! ๐ŸŽ‰"")
70
+
71
+ # Footer
72
+ st.markdown(""---"")
73
+ st.caption(""Built with Streamlit for Hugging Face Spaces"")"