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