Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 6 |
-
st.
|
| 7 |
-
page_title="Streamlit Components Demo",
|
| 8 |
-
page_icon="π",
|
| 9 |
-
layout="wide"
|
| 10 |
-
)
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
st.
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
st.
|
|
|
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
st.
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
type=['jpg', 'jpeg', 'png', 'mp3', 'wav'],
|
| 26 |
-
accept_multiple_files=False,
|
| 27 |
-
key="file_uploader"
|
| 28 |
-
)
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
if
|
| 32 |
-
|
| 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!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|