Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,55 +29,103 @@ categories = {
|
|
29 |
'Nonprofits & Activism' : 29
|
30 |
}
|
31 |
|
|
|
32 |
# Create the Streamlit web application
|
33 |
def main():
|
34 |
st.set_page_config(layout="wide")
|
35 |
-
st.
|
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 |
# Convert category to category ID
|
66 |
-
|
67 |
-
|
68 |
-
# Predict button
|
69 |
-
if st.button("Predict"):
|
70 |
-
# Perform prediction
|
71 |
-
prediction = predict_trend(title, duration, categoryId)
|
72 |
-
if prediction[0] == 1:
|
73 |
-
st.success("This video is predicted to be a trend!")
|
74 |
-
st.markdown("![Alt Text](https://media.tenor.com/Cyi2zT7wcmcAAAAj/pentol-gif-eak.gif)")
|
75 |
-
else:
|
76 |
-
st.info("This video is predicted not to be a trend.")
|
77 |
-
st.markdown("![Alt Text](https://media.tenor.com/VYKtkKnHaUcAAAAj/quby-cute.gif)")
|
78 |
-
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
|
83 |
def get_picture_from_url(url):
|
|
|
29 |
'Nonprofits & Activism' : 29
|
30 |
}
|
31 |
|
32 |
+
|
33 |
# Create the Streamlit web application
|
34 |
def main():
|
35 |
st.set_page_config(layout="wide")
|
36 |
+
st.markdown(
|
37 |
+
f"""
|
38 |
+
<style>
|
39 |
+
body{{
|
40 |
+
display: flex;
|
41 |
+
justify-content: center;
|
42 |
+
align-items: center;
|
43 |
+
text-align: center;
|
44 |
+
}}
|
45 |
+
h1{{
|
46 |
+
text-align: center;
|
47 |
+
color: #d72324;
|
48 |
+
}}
|
49 |
+
img{{
|
50 |
+
max-width: 100%;
|
51 |
+
max-height: 100%;
|
52 |
+
}}
|
53 |
+
.stButton > button {{
|
54 |
+
background-color: #d72324;
|
55 |
+
color:white;
|
56 |
+
font-weight: bold;
|
57 |
+
width: 500px;
|
58 |
+
height: 50px;
|
59 |
+
}}
|
60 |
+
.my-container {{
|
61 |
+
border: 2px solid #d72324;
|
62 |
+
padding: 10px;
|
63 |
+
}}
|
64 |
+
</style>
|
65 |
+
""",
|
66 |
+
unsafe_allow_html=True
|
67 |
+
)
|
68 |
+
st.markdown("<body><img style = 'max-width: 20%;max-height: 20%;text-align: center;' src=\"https://media.tenor.com/U7OFq772kIEAAAAj/sweet-dreams.gif\"></body>",unsafe_allow_html=True)
|
69 |
+
st.markdown("<h1>YouTube Trend Prediction</h1>", unsafe_allow_html=True)
|
70 |
+
#https://www.freepnglogos.com/uploads/youtube-play-red-logo-png-transparent-background-6.png
|
71 |
+
# st.write("Enter the video details below:")
|
72 |
|
73 |
+
tab1, tab2 = st.tabs(["Predict", "Test"])
|
74 |
+
# Input fields
|
75 |
+
with tab1:
|
76 |
+
with st.container():
|
77 |
+
col1, col2, col3 = st.columns(3)
|
78 |
+
getTitle, getDuration, getCategory = "", 0.00, 1
|
79 |
+
getThumbnailUrl = ""
|
80 |
+
with col1:
|
81 |
+
url = st.text_input("URL",placeholder="Enter a video url")
|
82 |
+
if url:
|
83 |
+
metadata = get_metadata(url)
|
84 |
+
if not metadata.empty:
|
85 |
+
getTitle = metadata['title'].iloc[0]
|
86 |
+
getDuration = metadata['duration'].iloc[0]
|
87 |
+
category_id = metadata['category_id'].iloc[0]
|
88 |
+
getThumbnailUrl = metadata['thumbnail_link'].iloc[0]
|
89 |
+
getCategory = int(category_id)
|
90 |
+
|
91 |
+
if getThumbnailUrl is not None:
|
92 |
+
picture = get_picture_from_url(getThumbnailUrl)
|
93 |
+
if picture:
|
94 |
+
st.image(picture, caption='Uploaded Picture', use_column_width=True)
|
95 |
+
with col2:
|
96 |
+
title = st.text_input("Title", placeholder="Enter a video title",value=getTitle)
|
97 |
+
duration = st.number_input("Duration (in minutes)", min_value=0.0, value=getDuration)
|
98 |
+
category = st.selectbox("Category", list(categories.keys()), index=list(categories.values()).index(getCategory))
|
99 |
+
|
100 |
+
with col3:
|
101 |
+
picture = st.file_uploader("Upload Picture", type=["jpg", "jpeg", "png"])
|
102 |
+
if picture is not None:
|
103 |
+
st.picture(picture, use_column_width=True)
|
104 |
# Convert category to category ID
|
105 |
+
categoryId = categories[category]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
+
|
108 |
+
if st.button("Predict"):
|
109 |
+
# Perform prediction
|
110 |
+
if title is None or title.strip() == "" and duration == 0:
|
111 |
+
st.warning("Please enter a title and duration.")
|
112 |
+
|
113 |
+
else:
|
114 |
+
if title is None or title.strip() == "":
|
115 |
+
st.warning("Please enter a title")
|
116 |
|
117 |
+
if duration == 0:
|
118 |
+
st.warning("Please enter a duration.")
|
119 |
+
|
120 |
+
else:
|
121 |
+
prediction = predict_trend(title, duration, categoryId)
|
122 |
+
if prediction[0] == 1:
|
123 |
+
st.success("This video is predicted to be a trend!")
|
124 |
+
st.markdown("![Alt Text](https://media.tenor.com/Cyi2zT7wcmcAAAAj/pentol-gif-eak.gif)")
|
125 |
+
else:
|
126 |
+
st.info("This video is predicted not to be a trend.")
|
127 |
+
st.markdown("![Alt Text](https://media.tenor.com/VYKtkKnHaUcAAAAj/quby-cute.gif)")
|
128 |
+
|
129 |
|
130 |
|
131 |
def get_picture_from_url(url):
|