sshenai commited on
Commit
2e52e6a
Β·
verified Β·
1 Parent(s): 0610666

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -65
app.py CHANGED
@@ -1,73 +1,30 @@
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")
 
1
  import streamlit as st
2
+ from PIL import Image
3
  import time
 
4
 
5
+ # App title
6
+ st.title("Streamlit Demo on Hugging Face")
 
 
 
 
7
 
8
+ # Write some text
9
+ st.write("Welcome to a demo app showcasing basic Streamlit components!")
10
 
11
+ # File uploader for image and audio
12
+ uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
13
+ uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav", "ogg"])
14
 
15
+ # Display image with spinner
16
+ if uploaded_image is not None:
17
+ with st.spinner("Loading image..."):
18
+ time.sleep(1) # Simulate a delay
19
+ image = Image.open(uploaded_image)
20
+ st.image(image, caption="Uploaded Image", use_column_width=True)
21
 
22
+ # Play audio with spinner
23
+ if uploaded_audio is not None:
24
+ with st.spinner("Loading audio..."):
25
+ time.sleep(1) # Simulate a delay
26
+ st.audio(uploaded_audio)
 
 
 
 
27
 
28
+ # Button interaction
29
+ if st.button("Click Me"):
30
+ st.write("πŸŽ‰ You clicked the button!")