lmgame commited on
Commit
93c11f0
ยท
verified ยท
1 Parent(s): a041920

Upload gallery_tab.py

Browse files
Files changed (1) hide show
  1. gallery_tab.py +270 -270
gallery_tab.py CHANGED
@@ -1,271 +1,271 @@
1
- import gradio as gr
2
- from datetime import datetime
3
- import json
4
-
5
- # Load video links and news data
6
- with open('assets/game_video_link.json', 'r') as f:
7
- VIDEO_LINKS = json.load(f)
8
-
9
- with open('assets/news.json', 'r') as f:
10
- NEWS_DATA = json.load(f)
11
-
12
- def create_video_gallery():
13
- """Create a custom HTML/JS component for video gallery"""
14
- # Extract video IDs
15
- mario_id = VIDEO_LINKS["super_mario"].split("?v=")[1]
16
- sokoban_id = VIDEO_LINKS["sokoban"].split("?v=")[1]
17
- game_2048_id = VIDEO_LINKS["2048"].split("?v=")[1]
18
- candy_id = VIDEO_LINKS["candy"].split("?v=")[1]
19
-
20
- # Get the latest video from news data
21
- latest_news = NEWS_DATA["news"][0] # First item is the latest
22
- latest_video_id = latest_news["video_link"].split("?v=")[1]
23
- latest_date = datetime.strptime(latest_news["date"], "%Y-%m-%d")
24
- formatted_latest_date = latest_date.strftime("%B %d, %Y")
25
-
26
- # Generate news HTML
27
- news_items = []
28
- for item in NEWS_DATA["news"]:
29
- video_id = item["video_link"].split("?v=")[1]
30
- date_obj = datetime.strptime(item["date"], "%Y-%m-%d")
31
- formatted_date = date_obj.strftime("%B %d, %Y")
32
- news_items.append(f'''
33
- <div class="news-item">
34
- <div class="news-date">{formatted_date}</div>
35
- <div class="news-content">
36
- <div class="news-video">
37
- <div class="video-wrapper">
38
- <iframe src="https://www.youtube.com/embed/{video_id}"></iframe>
39
- </div>
40
- </div>
41
- <div class="news-text">
42
- <a href="{item["twitter_link"]}" target="_blank" class="twitter-link">
43
- <span class="twitter-icon">๐Ÿ“ข</span>
44
- {item["twitter_text"]}
45
- </a>
46
- </div>
47
- </div>
48
- </div>
49
- ''')
50
-
51
- news_html = '\n'.join(news_items)
52
-
53
- gallery_html = f'''
54
- <div class="video-gallery-container">
55
- <style>
56
- .video-gallery-container {{
57
- width: 100%;
58
- max-width: 1400px;
59
- margin: 0 auto;
60
- padding: 20px;
61
- }}
62
- .highlight-section {{
63
- margin-bottom: 40px;
64
- }}
65
- .highlight-card {{
66
- background: #ffffff;
67
- border-radius: 10px;
68
- box-shadow: 0 4px 20px rgba(0,0,0,0.15);
69
- overflow: hidden;
70
- transition: transform 0.3s;
71
- border: 2px solid #2196F3;
72
- }}
73
- .highlight-card:hover {{
74
- transform: translateY(-5px);
75
- }}
76
- .highlight-header {{
77
- background: #2196F3;
78
- color: white;
79
- padding: 15px 20px;
80
- font-size: 1.2em;
81
- font-weight: bold;
82
- display: flex;
83
- align-items: center;
84
- gap: 10px;
85
- }}
86
- .highlight-date {{
87
- font-size: 0.9em;
88
- opacity: 0.9;
89
- }}
90
- .highlight-content {{
91
- padding: 20px;
92
- }}
93
- .video-grid {{
94
- display: grid;
95
- grid-template-columns: repeat(2, 1fr);
96
- gap: 20px;
97
- margin-top: 20px;
98
- margin-bottom: 40px;
99
- }}
100
- .video-card {{
101
- background: var(--card-bg, #ffffff);
102
- border-radius: 10px;
103
- box-shadow: 0 2px 10px rgba(0,0,0,0.1);
104
- overflow: hidden;
105
- transition: transform 0.2s;
106
- }}
107
- .video-card:hover {{
108
- transform: translateY(-5px);
109
- }}
110
- .video-wrapper {{
111
- position: relative;
112
- padding-bottom: 56.25%;
113
- height: 0;
114
- overflow: hidden;
115
- }}
116
- .video-wrapper iframe {{
117
- position: absolute;
118
- top: 0;
119
- left: 0;
120
- width: 100%;
121
- height: 100%;
122
- border: none;
123
- }}
124
- .video-title {{
125
- padding: 15px;
126
- font-size: 1.2em;
127
- font-weight: bold;
128
- color: var(--title-text, #2c3e50);
129
- text-align: center;
130
- background: var(--title-bg, #f8f9fa);
131
- border-top: 1px solid var(--border-color, #eee);
132
- }}
133
- .news-section {{
134
- margin-top: 40px;
135
- border-top: 2px solid #e9ecef;
136
- padding-top: 20px;
137
- }}
138
- .news-section-title {{
139
- font-size: 1.8em;
140
- font-weight: bold;
141
- color: #2c3e50;
142
- margin-bottom: 20px;
143
- text-align: center;
144
- }}
145
- .news-item {{
146
- background: #ffffff;
147
- border-radius: 10px;
148
- box-shadow: 0 2px 10px rgba(0,0,0,0.1);
149
- margin-bottom: 20px;
150
- overflow: hidden;
151
- }}
152
- .news-date {{
153
- padding: 10px 20px;
154
- background: #f8f9fa;
155
- color: #666;
156
- font-size: 0.9em;
157
- border-bottom: 1px solid #eee;
158
- }}
159
- .news-content {{
160
- display: flex;
161
- padding: 20px;
162
- align-items: center;
163
- gap: 30px;
164
- }}
165
- .news-video {{
166
- flex: 0 0 300px;
167
- }}
168
- .news-text {{
169
- flex: 1;
170
- display: flex;
171
- align-items: center;
172
- min-height: 169px;
173
- }}
174
- .twitter-link {{
175
- color: #2c3e50;
176
- text-decoration: none;
177
- display: flex;
178
- align-items: center;
179
- gap: 15px;
180
- font-size: 1.4em;
181
- font-weight: 600;
182
- line-height: 1.4;
183
- }}
184
- .twitter-link:hover {{
185
- color: #1da1f2;
186
- }}
187
- .twitter-icon {{
188
- font-size: 1.5em;
189
- color: #1da1f2;
190
- }}
191
-
192
- /* Dark mode specific styles */
193
- .dark .video-card {{
194
- --card-bg: #2d3748;
195
- --title-bg: #1a202c;
196
- --title-text: #e2e8f0;
197
- --border-color: #4a5568;
198
- }}
199
-
200
- /* Light mode specific styles */
201
- .light .video-card {{
202
- --card-bg: #ffffff;
203
- --title-bg: #f8f9fa;
204
- --title-text: #2c3e50;
205
- --border-color: #eee;
206
- }}
207
- </style>
208
-
209
- <!-- Highlight Section -->
210
- <div class="highlight-section">
211
- <div class="highlight-card">
212
- <div class="highlight-header">
213
- <span>๐ŸŒŸ Latest Update</span>
214
- <span class="highlight-date">{formatted_latest_date}</span>
215
- </div>
216
- <div class="highlight-content">
217
- <div class="video-wrapper">
218
- <iframe src="https://www.youtube.com/embed/{latest_video_id}"></iframe>
219
- </div>
220
- <div class="video-title">
221
- <a href="{latest_news["twitter_link"]}" target="_blank" class="twitter-link">
222
- <span class="twitter-icon">๐Ÿ“ข</span>
223
- {latest_news["twitter_text"]}
224
- </a>
225
- </div>
226
- </div>
227
- </div>
228
- </div>
229
-
230
- <!-- Regular Video Grid -->
231
- <div class="video-grid">
232
- <div class="video-card">
233
- <div class="video-wrapper">
234
- <iframe src="https://www.youtube.com/embed/{mario_id}"></iframe>
235
- </div>
236
- <div class="video-title">๐ŸŽฎ Super Mario Bros</div>
237
- </div>
238
- <div class="video-card">
239
- <div class="video-wrapper">
240
- <iframe src="https://www.youtube.com/embed/{sokoban_id}"></iframe>
241
- </div>
242
- <div class="video-title">๐Ÿ“ฆ Sokoban</div>
243
- </div>
244
- <div class="video-card">
245
- <div class="video-wrapper">
246
- <iframe src="https://www.youtube.com/embed/{game_2048_id}"></iframe>
247
- </div>
248
- <div class="video-title">๐Ÿ”ข 2048</div>
249
- </div>
250
- <div class="video-card">
251
- <div class="video-wrapper">
252
- <iframe src="https://www.youtube.com/embed/{candy_id}"></iframe>
253
- </div>
254
- <div class="video-title">๐Ÿฌ Candy Crash</div>
255
- </div>
256
- </div>
257
-
258
- <!-- News Section -->
259
- <div class="news-section">
260
- <div class="news-section-title">๐Ÿ“ฐ Latest News</div>
261
- {news_html}
262
- </div>
263
- </div>
264
- '''
265
- return gr.HTML(gallery_html)
266
-
267
- def create_gallery_tab():
268
- """Create and return the gallery tab component"""
269
- with gr.Tab("๐ŸŽฅ Gallery") as gallery_tab:
270
- video_gallery = create_video_gallery()
271
  return gallery_tab
 
1
+ import gradio as gr
2
+ from datetime import datetime
3
+ import json
4
+
5
+ # Load video links and news data
6
+ with open('assets/game_video_link.json', 'r') as f:
7
+ VIDEO_LINKS = json.load(f)
8
+
9
+ with open('assets/news.json', 'r') as f:
10
+ NEWS_DATA = json.load(f)
11
+
12
+ def create_video_gallery():
13
+ """Create a custom HTML/JS component for video gallery"""
14
+ # Extract video IDs
15
+ mario_id = VIDEO_LINKS["super_mario"].split("?v=")[1]
16
+ sokoban_id = VIDEO_LINKS["sokoban"].split("?v=")[1]
17
+ game_2048_id = VIDEO_LINKS["2048"].split("?v=")[1]
18
+ candy_id = VIDEO_LINKS["candy"].split("?v=")[1]
19
+
20
+ # Get the latest video from news data
21
+ latest_news = NEWS_DATA["news"][0] # First item is the latest
22
+ latest_video_id = latest_news["video_link"].split("?v=")[1]
23
+ latest_date = datetime.strptime(latest_news["date"], "%Y-%m-%d")
24
+ formatted_latest_date = latest_date.strftime("%B %d, %Y")
25
+
26
+ # Generate news HTML
27
+ news_items = []
28
+ for item in NEWS_DATA["news"]:
29
+ video_id = item["video_link"].split("?v=")[1]
30
+ date_obj = datetime.strptime(item["date"], "%Y-%m-%d")
31
+ formatted_date = date_obj.strftime("%B %d, %Y")
32
+ news_items.append(f'''
33
+ <div class="news-item">
34
+ <div class="news-date">{formatted_date}</div>
35
+ <div class="news-content">
36
+ <div class="news-video">
37
+ <div class="video-wrapper">
38
+ <iframe src="https://www.youtube.com/embed/{video_id}"></iframe>
39
+ </div>
40
+ </div>
41
+ <div class="news-text">
42
+ <a href="{item["twitter_link"]}" target="_blank" class="twitter-link">
43
+ <span class="twitter-icon">๐Ÿ“ข</span>
44
+ {item["twitter_text"]}
45
+ </a>
46
+ </div>
47
+ </div>
48
+ </div>
49
+ ''')
50
+
51
+ news_html = '\n'.join(news_items)
52
+
53
+ gallery_html = f'''
54
+ <div class="video-gallery-container">
55
+ <style>
56
+ .video-gallery-container {{
57
+ width: 100%;
58
+ max-width: 1400px;
59
+ margin: 0 auto;
60
+ padding: 20px;
61
+ }}
62
+ .highlight-section {{
63
+ margin-bottom: 40px;
64
+ }}
65
+ .highlight-card {{
66
+ background: #ffffff;
67
+ border-radius: 10px;
68
+ box-shadow: 0 4px 20px rgba(0,0,0,0.15);
69
+ overflow: hidden;
70
+ transition: transform 0.3s;
71
+ border: 2px solid #2196F3;
72
+ }}
73
+ .highlight-card:hover {{
74
+ transform: translateY(-5px);
75
+ }}
76
+ .highlight-header {{
77
+ background: #2196F3;
78
+ color: white;
79
+ padding: 15px 20px;
80
+ font-size: 1.2em;
81
+ font-weight: bold;
82
+ display: flex;
83
+ align-items: center;
84
+ gap: 10px;
85
+ }}
86
+ .highlight-date {{
87
+ font-size: 0.9em;
88
+ opacity: 0.9;
89
+ }}
90
+ .highlight-content {{
91
+ padding: 20px;
92
+ }}
93
+ .video-grid {{
94
+ display: grid;
95
+ grid-template-columns: repeat(2, 1fr);
96
+ gap: 20px;
97
+ margin-top: 20px;
98
+ margin-bottom: 40px;
99
+ }}
100
+ .video-card {{
101
+ background: var(--card-bg, #ffffff);
102
+ border-radius: 10px;
103
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
104
+ overflow: hidden;
105
+ transition: transform 0.2s;
106
+ }}
107
+ .video-card:hover {{
108
+ transform: translateY(-5px);
109
+ }}
110
+ .video-wrapper {{
111
+ position: relative;
112
+ padding-bottom: 56.25%;
113
+ height: 0;
114
+ overflow: hidden;
115
+ }}
116
+ .video-wrapper iframe {{
117
+ position: absolute;
118
+ top: 0;
119
+ left: 0;
120
+ width: 100%;
121
+ height: 100%;
122
+ border: none;
123
+ }}
124
+ .video-title {{
125
+ padding: 15px;
126
+ font-size: 1.2em;
127
+ font-weight: bold;
128
+ color: var(--title-text, #2c3e50);
129
+ text-align: center;
130
+ background: var(--title-bg, #f8f9fa);
131
+ border-top: 1px solid var(--border-color, #eee);
132
+ }}
133
+ .news-section {{
134
+ margin-top: 40px;
135
+ border-top: 2px solid #e9ecef;
136
+ padding-top: 20px;
137
+ }}
138
+ .news-section-title {{
139
+ font-size: 1.8em;
140
+ font-weight: bold;
141
+ color: #2c3e50;
142
+ margin-bottom: 20px;
143
+ text-align: center;
144
+ }}
145
+ .news-item {{
146
+ background: #ffffff;
147
+ border-radius: 10px;
148
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
149
+ margin-bottom: 20px;
150
+ overflow: hidden;
151
+ }}
152
+ .news-date {{
153
+ padding: 10px 20px;
154
+ background: #f8f9fa;
155
+ color: #666;
156
+ font-size: 0.9em;
157
+ border-bottom: 1px solid #eee;
158
+ }}
159
+ .news-content {{
160
+ display: flex;
161
+ padding: 20px;
162
+ align-items: center;
163
+ gap: 30px;
164
+ }}
165
+ .news-video {{
166
+ flex: 0 0 300px;
167
+ }}
168
+ .news-text {{
169
+ flex: 1;
170
+ display: flex;
171
+ align-items: center;
172
+ min-height: 169px;
173
+ }}
174
+ .twitter-link {{
175
+ color: #2c3e50;
176
+ text-decoration: none;
177
+ display: flex;
178
+ align-items: center;
179
+ gap: 15px;
180
+ font-size: 1.4em;
181
+ font-weight: 600;
182
+ line-height: 1.4;
183
+ }}
184
+ .twitter-link:hover {{
185
+ color: #1da1f2;
186
+ }}
187
+ .twitter-icon {{
188
+ font-size: 1.5em;
189
+ color: #1da1f2;
190
+ }}
191
+
192
+ /* Dark mode specific styles */
193
+ .dark .video-card {{
194
+ --card-bg: #2d3748;
195
+ --title-bg: #1a202c;
196
+ --title-text: #e2e8f0;
197
+ --border-color: #4a5568;
198
+ }}
199
+
200
+ /* Light mode specific styles */
201
+ .light .video-card {{
202
+ --card-bg: #ffffff;
203
+ --title-bg: #f8f9fa;
204
+ --title-text: #2c3e50;
205
+ --border-color: #eee;
206
+ }}
207
+ </style>
208
+
209
+ <!-- Highlight Section -->
210
+ <div class="highlight-section">
211
+ <div class="highlight-card">
212
+ <div class="highlight-header">
213
+ <span>๐ŸŒŸ Latest Update</span>
214
+ <span class="highlight-date">{formatted_latest_date}</span>
215
+ </div>
216
+ <div class="highlight-content">
217
+ <div class="video-wrapper">
218
+ <iframe src="https://www.youtube.com/embed/{latest_video_id}"></iframe>
219
+ </div>
220
+ <div class="video-title">
221
+ <a href="{latest_news["twitter_link"]}" target="_blank" class="twitter-link">
222
+ <span class="twitter-icon">๐Ÿ“ข</span>
223
+ {latest_news["twitter_text"]}
224
+ </a>
225
+ </div>
226
+ </div>
227
+ </div>
228
+ </div>
229
+
230
+ <!-- Regular Video Grid -->
231
+ <div class="video-grid">
232
+ <div class="video-card">
233
+ <div class="video-wrapper">
234
+ <iframe src="https://www.youtube.com/embed/{mario_id}"></iframe>
235
+ </div>
236
+ <div class="video-title">๐ŸŽฎ Super Mario Bros</div>
237
+ </div>
238
+ <div class="video-card">
239
+ <div class="video-wrapper">
240
+ <iframe src="https://www.youtube.com/embed/{sokoban_id}"></iframe>
241
+ </div>
242
+ <div class="video-title">๐Ÿ“ฆ Sokoban</div>
243
+ </div>
244
+ <div class="video-card">
245
+ <div class="video-wrapper">
246
+ <iframe src="https://www.youtube.com/embed/{game_2048_id}"></iframe>
247
+ </div>
248
+ <div class="video-title">๐Ÿ”ข 2048</div>
249
+ </div>
250
+ <div class="video-card">
251
+ <div class="video-wrapper">
252
+ <iframe src="https://www.youtube.com/embed/{candy_id}"></iframe>
253
+ </div>
254
+ <div class="video-title">๐Ÿฌ Candy Crash</div>
255
+ </div>
256
+ </div>
257
+
258
+ <!-- News Section -->
259
+ <div class="news-section">
260
+ <div class="news-section-title">๐Ÿ“ฐ Latest News</div>
261
+ {news_html}
262
+ </div>
263
+ </div>
264
+ '''
265
+ return gr.HTML(gallery_html)
266
+
267
+ def create_gallery_tab():
268
+ """Create and return the gallery tab component"""
269
+ with gr.Tab("๐ŸŽฅ Gallery") as gallery_tab:
270
+ video_gallery = create_video_gallery()
271
  return gallery_tab