Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
st.title("📁 File Uploader Demo")
|
| 6 |
+
|
| 7 |
+
st.write("Upload an image or audio file, and we'll display or play it for you!")
|
| 8 |
+
|
| 9 |
+
uploaded_file = st.file_uploader("Choose an image or audio file", type=["png", "jpg", "jpeg", "mp3", "wav"])
|
| 10 |
+
|
| 11 |
+
if uploaded_file is not None:
|
| 12 |
+
file_type = uploaded_file.type
|
| 13 |
+
|
| 14 |
+
with st.spinner("Processing..."):
|
| 15 |
+
time.sleep(2) # simulate processing time
|
| 16 |
+
|
| 17 |
+
if "image" in file_type:
|
| 18 |
+
st.write("### Uploaded Image:")
|
| 19 |
+
image = Image.open(uploaded_file)
|
| 20 |
+
st.image(image, caption="Your image", use_column_width=True)
|
| 21 |
+
|
| 22 |
+
elif "audio" in file_type:
|
| 23 |
+
st.write("### Uploaded Audio:")
|
| 24 |
+
st.audio(uploaded_file, format=file_type)
|
| 25 |
+
|
| 26 |
+
else:
|
| 27 |
+
st.write("Unsupported file type.")
|