Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +15 -90
src/streamlit_app.py
CHANGED
|
@@ -1,96 +1,21 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
|
| 4 |
-
|
| 5 |
-
# This should be the first Streamlit command in your app
|
| 6 |
-
st.set_page_config(
|
| 7 |
-
page_title="Streamlit Basics",
|
| 8 |
-
page_icon="π",
|
| 9 |
-
layout="wide",
|
| 10 |
-
)
|
| 11 |
|
| 12 |
-
|
| 13 |
-
# You can add widgets to the sidebar using `st.sidebar.`
|
| 14 |
-
st.sidebar.title("App Controls")
|
| 15 |
-
st.sidebar.markdown("Use these widgets to see the app update!")
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
# WIDGET 2: Slider (Number)
|
| 21 |
-
number_of_items = st.sidebar.slider(
|
| 22 |
-
"How many items?",
|
| 23 |
-
min_value=1,
|
| 24 |
-
max_value=10,
|
| 25 |
-
value=5
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
# --- Main Page Content ---
|
| 29 |
-
st.title("Welcome to Streamlit Basics! π")
|
| 30 |
-
st.markdown(
|
| 31 |
-
"""
|
| 32 |
-
This is a super simple app to show you how Streamlit works.
|
| 33 |
-
Notice how the app reruns from top to bottom every time you
|
| 34 |
-
interact with a widget in the sidebar.
|
| 35 |
-
"""
|
| 36 |
-
)
|
| 37 |
-
st.divider()
|
| 38 |
-
|
| 39 |
-
# --- Section 1: Text Input ---
|
| 40 |
-
st.header("1. Text Input")
|
| 41 |
-
st.markdown("Whatever you type here is stored in a Python variable.")
|
| 42 |
-
|
| 43 |
-
# WIDGET 3: Text Input
|
| 44 |
-
user_name = st.text_input("What's your name?", "Streamlit User")
|
| 45 |
-
|
| 46 |
-
# The app's output reacts to the widget's current value
|
| 47 |
-
st.write(f"Hello, **{user_name}**!")
|
| 48 |
-
st.divider()
|
| 49 |
-
|
| 50 |
-
# --- Section 2: Using Widget Values ---
|
| 51 |
-
st.header("2. Using Widget Values")
|
| 52 |
-
st.markdown("Here, we use the values from the sidebar widgets.")
|
| 53 |
-
|
| 54 |
-
st.write(f"You've selected **{number_of_items}** items.")
|
| 55 |
-
|
| 56 |
-
# We can use standard Python `if` statements
|
| 57 |
-
if show_balloons:
|
| 58 |
-
st.write("The 'Show balloons' checkbox is **checked**! π")
|
| 59 |
-
else:
|
| 60 |
-
st.write("The 'Show balloons' checkbox is **unchecked**. π")
|
| 61 |
-
st.divider()
|
| 62 |
-
|
| 63 |
-
# --- Section 3: Buttons and State ---
|
| 64 |
-
st.header("3. Buttons")
|
| 65 |
-
st.markdown(
|
| 66 |
-
"""
|
| 67 |
-
Buttons are special. They are 'event' widgets.
|
| 68 |
-
They are only `True` for the *single rerun* right after they are clicked.
|
| 69 |
-
"""
|
| 70 |
-
)
|
| 71 |
-
|
| 72 |
-
# WIDGET 4: Button
|
| 73 |
-
if st.button("Click me!", type="primary"):
|
| 74 |
-
# This block of code only runs when the button is clicked
|
| 75 |
-
st.success(f"You clicked the button, {user_name}!")
|
| 76 |
-
|
| 77 |
-
# Let's use the checkbox value
|
| 78 |
-
if show_balloons:
|
| 79 |
-
st.balloons()
|
| 80 |
-
|
| 81 |
-
# Buttons can also trigger longer processes
|
| 82 |
-
st.write("Running a 'long' process...")
|
| 83 |
-
|
| 84 |
-
# A progress bar
|
| 85 |
-
progress_bar = st.progress(0, text="Starting...")
|
| 86 |
-
|
| 87 |
-
for i in range(100):
|
| 88 |
-
time.sleep(0.01) # Simulate some work
|
| 89 |
-
progress_bar.progress(i + 1, text=f"Processing item {i+1}")
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import yt_dlp
|
| 3 |
|
| 4 |
+
'Youtube Song Player'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
url = st.text_input('youtube','https://www.youtube.com/watch?v=9Zj0JOHJR-s')
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
ydl_opts = {
|
| 9 |
+
'format': 'bestaudio/best', # Select the best audio str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Tell yt-dlp to write the output to our in-memory buffer
|
| 12 |
+
'quiet': True,
|
| 13 |
+
'noprogress': True,
|
| 14 |
+
'nocheckcertificate': True
|
| 15 |
+
}
|
| 16 |
+
info = yt_dlp.YoutubeDL(ydl_opts).extract_info(url, download=False)
|
| 17 |
+
|
| 18 |
+
info['fulltitle'] , info['duration_string']
|
| 19 |
+
st.image(info['thumbnail'])
|
| 20 |
|
| 21 |
+
st.audio(info['url'])
|