yusiff commited on
Commit
04d67e0
·
verified ·
1 Parent(s): 6c56633

Update app4.py

Browse files
Files changed (1) hide show
  1. app4.py +70 -36
app4.py CHANGED
@@ -14,7 +14,13 @@ if 'name' not in st.session_state:
14
  if st.session_state.name is None:
15
  # صفحة إدخال الاسم
16
  st.title("🎬 Welcome to the Movie Recommender!")
17
- st.markdown("Please enter your name to continue.")
 
 
 
 
 
 
18
 
19
  name = st.text_input("Enter your name", "")
20
 
@@ -27,34 +33,35 @@ if st.session_state.name is None:
27
  else:
28
  st.error("Please enter a valid name.") # إذا لم يتم إدخال اسم
29
 
 
30
  else:
31
  # -------------------- تحسين تنسيق الشريط الجانبي باستخدام CSS --------------------
32
  st.markdown("""
33
- <style>
34
- .sidebar .sidebar-content {
35
- background-color: #2c3e50; /* خلفية دكناء */
36
- color: white;
37
- padding: 15px;
38
- border-radius: 10px;
39
- }
40
- .sidebar .sidebar-content h1, .sidebar .sidebar-content h2 {
41
- font-size: 20px;
42
- font-weight: bold;
43
- color: #ecf0f1; /* لون النص */
44
- }
45
- .sidebar .sidebar-content .stButton button {
46
- background-color: #3498db; /* زر لون أزرق */
47
- color: white;
48
- font-weight: bold;
49
- border-radius: 5px;
50
- width: 100%;
51
- padding: 10px;
52
- }
53
- .sidebar .sidebar-content .stButton button:hover {
54
- background-color: #2980b9;
55
- }
56
- </style>
57
- """, unsafe_allow_html=True)
58
 
59
  # -------------------- تحميل البيانات --------------------
60
  try:
@@ -144,12 +151,26 @@ else:
144
  with cols[i % 5]:
145
  st.image(poster_url, use_container_width=True)
146
  st.markdown(f"<div class='movie-title'>{title}</div>", unsafe_allow_html=True)
 
 
 
 
 
 
147
  if st.button("📄 Details", key=f"popular_details_{i}"):
148
- overview, rating, release_date, genres = fetch_movie_details(movie_id)
149
- st.markdown(f"**📅 Release Date:** {release_date}")
150
- st.markdown(f"**⭐ Rating:** {rating}")
151
- st.markdown(f"**🎭 Genres:** {genres}")
152
- st.markdown(f"**📝 Overview:** {overview}")
 
 
 
 
 
 
 
 
153
  else:
154
  st.warning("Could not fetch popular movies.")
155
 
@@ -193,11 +214,24 @@ else:
193
  index = movies[movies['title'] == selected_movie].index[0]
194
  movie_id = movies.iloc[index].movie_id
195
  overview, rating, release_date, genres = fetch_movie_details(movie_id)
196
- st.image(fetch_poster(movie_id), use_container_width=True)
197
- st.markdown(f"**📅 Release Date:** {release_date}")
198
- st.markdown(f"**⭐ Rating:** {rating}")
199
- st.markdown(f"**🎭 Genres:** {genres}")
200
- st.markdown(f"**📝 Overview:** {overview}")
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  # -------------------- Footer --------------------
202
  st.markdown("<hr>", unsafe_allow_html=True)
203
  st.markdown("<div class='footer'>© 2025 • by Youssef samy • Powered by TMDB API</div>", unsafe_allow_html=True)
 
14
  if st.session_state.name is None:
15
  # صفحة إدخال الاسم
16
  st.title("🎬 Welcome to the Movie Recommender!")
17
+
18
+ # عبارة الترحيب حسب الوقت
19
+ hour = datetime.now().hour
20
+ greeting_time = "Good Morning ☀️" if hour < 12 else "Good Afternoon 🌤️" if hour < 18 else "Good Evening 🌙"
21
+ st.markdown(f"### {greeting_time}")
22
+
23
+ #st.markdown("Please enter your name to continue.")
24
 
25
  name = st.text_input("Enter your name", "")
26
 
 
33
  else:
34
  st.error("Please enter a valid name.") # إذا لم يتم إدخال اسم
35
 
36
+
37
  else:
38
  # -------------------- تحسين تنسيق الشريط الجانبي باستخدام CSS --------------------
39
  st.markdown("""
40
+ <style>
41
+ .sidebar .sidebar-content {
42
+ background-color: #1c1c1c; /* خلفية داكنة جدًا */
43
+ color: white;
44
+ padding: 15px;
45
+ border-radius: 10px;
46
+ }
47
+ .sidebar .sidebar-content h1, .sidebar .sidebar-content h2 {
48
+ font-size: 20px;
49
+ font-weight: bold;
50
+ color: #ecf0f1; /* لون النص */
51
+ }
52
+ .sidebar .sidebar-content .stButton button {
53
+ background-color: #3498db; /* زر لون أزرق */
54
+ color: white;
55
+ font-weight: bold;
56
+ border-radius: 5px;
57
+ width: 100%;
58
+ padding: 10px;
59
+ }
60
+ .sidebar .sidebar-content .stButton button:hover {
61
+ background-color: #2980b9;
62
+ }
63
+ </style>
64
+ """, unsafe_allow_html=True)
65
 
66
  # -------------------- تحميل البيانات --------------------
67
  try:
 
151
  with cols[i % 5]:
152
  st.image(poster_url, use_container_width=True)
153
  st.markdown(f"<div class='movie-title'>{title}</div>", unsafe_allow_html=True)
154
+
155
+ # استخدام session_state لتخزين حالة زر التفاصيل (مفتوح أو مغلق)
156
+ if f"show_details_{i}" not in st.session_state:
157
+ st.session_state[f"show_details_{i}"] = False
158
+
159
+ # زر التفاصيل
160
  if st.button("📄 Details", key=f"popular_details_{i}"):
161
+ # تغيير حالة الزر عند الضغط عليه
162
+ st.session_state[f"show_details_{i}"] = not st.session_state[f"show_details_{i}"]
163
+
164
+ # عرض التفاصيل إذا كانت الحالة "مفتوحة"
165
+ if st.session_state[f"show_details_{i}"]:
166
+ overview, rating, release_date, genres = fetch_movie_details(movie_id)
167
+ st.markdown(f"**📅 Release Date:** {release_date}")
168
+ st.markdown(f"**⭐ Rating:** {rating}")
169
+ st.markdown(f"**🎭 Genres:** {genres}")
170
+ st.markdown(f"**📝 Overview:** {overview}")
171
+ else:
172
+ st.markdown("**Details Closed**")
173
+
174
  else:
175
  st.warning("Could not fetch popular movies.")
176
 
 
214
  index = movies[movies['title'] == selected_movie].index[0]
215
  movie_id = movies.iloc[index].movie_id
216
  overview, rating, release_date, genres = fetch_movie_details(movie_id)
217
+
218
+ # إضافة زر لفتح أو إغلاق التفاصيل
219
+ if selected_movie not in st.session_state.show_details:
220
+ st.session_state.show_details[selected_movie] = True # قيمة افتراضية للإخفاء
221
+
222
+ if st.button(f"📄 Show/Hide Details for {selected_movie}"):
223
+ st.session_state.show_details[selected_movie] = not st.session_state.show_details[selected_movie]
224
+
225
+ # عرض التفاصيل بناءً على حالة الزر
226
+ if st.session_state.show_details[selected_movie]:
227
+ st.image(fetch_poster(movie_id), use_container_width=True)
228
+ st.markdown(f"**📅 Release Date:** {release_date}")
229
+ st.markdown(f"**⭐ Rating:** {rating}")
230
+ st.markdown(f"**🎭 Genres:** {genres}")
231
+ st.markdown(f"**📝 Overview:** {overview}")
232
+ else:
233
+ st.markdown(f"Details for {selected_movie} are hidden. Click the button to view them.")
234
+
235
  # -------------------- Footer --------------------
236
  st.markdown("<hr>", unsafe_allow_html=True)
237
  st.markdown("<div class='footer'>© 2025 • by Youssef samy • Powered by TMDB API</div>", unsafe_allow_html=True)