noumanjavaid commited on
Commit
1aa8799
Β·
verified Β·
1 Parent(s): 259b548

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +172 -122
app.py CHANGED
@@ -1,7 +1,42 @@
1
  import gradio as gr
 
 
2
 
3
- css = """
4
- /* Base styles */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  * {
6
  margin: 0;
7
  padding: 0;
@@ -14,7 +49,6 @@ body {
14
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
15
  }
16
 
17
- /* Header styles */
18
  .header {
19
  background: #ffffff;
20
  border-bottom: 1px solid #e5e5e5;
@@ -31,17 +65,12 @@ body {
31
  transition: transform 0.3s ease;
32
  }
33
 
34
- .logo:hover {
35
- transform: scale(1.05);
36
- }
37
-
38
  .header-title {
39
  color: #000000;
40
  font-size: 24px;
41
  font-weight: 600;
42
  }
43
 
44
- /* Main container */
45
  .container {
46
  max-width: 1400px;
47
  margin: 0 auto;
@@ -49,7 +78,6 @@ body {
49
  background: #ffffff;
50
  }
51
 
52
- /* Iframe container */
53
  .main-content {
54
  background: #ffffff;
55
  border-radius: 12px;
@@ -57,12 +85,6 @@ body {
57
  margin: 2rem 0;
58
  overflow: hidden;
59
  border: 1px solid #e5e5e5;
60
- transition: transform 0.3s ease, box-shadow 0.3s ease;
61
- }
62
-
63
- .main-content:hover {
64
- transform: translateY(-2px);
65
- box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
66
  }
67
 
68
  .iframe-container {
@@ -82,7 +104,6 @@ body {
82
  border: none;
83
  }
84
 
85
- /* Navigation grid */
86
  .nav-grid {
87
  display: grid;
88
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
@@ -90,124 +111,153 @@ body {
90
  margin-top: 2rem;
91
  }
92
 
93
- /* Navigation cards */
94
  .nav-card {
95
  background: #ffffff;
96
  border: 1px solid #e5e5e5;
97
  border-radius: 10px;
98
  padding: 1.5rem;
99
  transition: all 0.3s ease;
100
- position: relative;
101
- overflow: hidden;
102
- }
103
-
104
- .nav-card:hover {
105
- transform: translateY(-5px);
106
- box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
107
- border-color: #000000;
108
- }
109
-
110
- .nav-card a {
111
- color: #000000;
112
- text-decoration: none;
113
- font-weight: 500;
114
- font-size: 1.1rem;
115
- display: flex;
116
- align-items: center;
117
- gap: 0.8rem;
118
- }
119
-
120
- .nav-card a::after {
121
- content: 'β†’';
122
- opacity: 0;
123
- margin-left: auto;
124
- transition: opacity 0.3s ease;
125
- }
126
-
127
- .nav-card:hover a::after {
128
- opacity: 1;
129
- }
130
-
131
- /* Hide Gradio elements */
132
- footer {
133
- display: none !important;
134
  }
135
 
136
- .gradio-container {
137
- margin: 0 !important;
138
- padding: 0 !important;
 
139
  }
 
140
 
141
- /* Custom scrollbar */
142
- ::-webkit-scrollbar {
143
- width: 8px;
144
- }
145
-
146
- ::-webkit-scrollbar-track {
147
- background: #f1f1f1;
148
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
- ::-webkit-scrollbar-thumb {
151
- background: #888;
152
- border-radius: 4px;
153
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
- ::-webkit-scrollbar-thumb:hover {
156
- background: #555;
157
- }
158
- """
159
-
160
- with gr.Blocks(css=css, title="Centurion Analysis Platform") as demo:
161
- # Header
162
- with gr.Row(elem_classes=["header"]):
163
- gr.Image(
164
- "https://raw.githubusercontent.com/noumanjavaid96/ai-as-an-api/refs/heads/master/image%20(39).png",
165
- elem_classes=["logo"],
166
- show_label=False,
167
- container=False
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  )
169
- gr.Markdown("Centurion Analysis", elem_classes=["header-title"])
170
-
171
- # Main content
172
- with gr.Row(elem_classes=["container"]):
173
- with gr.Column(elem_classes=["main-content"]):
174
- gr.HTML('''
175
- <div class="iframe-container">
176
- <iframe src="https://noumanjavaid-centii.hf.space"></iframe>
177
- </div>
178
- ''')
179
 
180
- # Navigation cards
181
- with gr.Row(elem_classes=["nav-grid"]):
182
- gr.HTML('''
183
- <div class="nav-card">
184
- <a href="https://noumanjavaid-new-space.hf.space" target="_blank">
185
- πŸ” DeepFake Detection
186
- </a>
187
- </div>
188
-
189
- <div class="nav-card">
190
- <a href="https://noumanjavaid-centurionv2.hf.space" target="_blank">
191
- πŸ“„ Document Analysis
192
- </a>
193
- </div>
194
-
195
- <div class="nav-card">
196
- <a href="https://noumanjavaid-watermark-demo-video.hf.space" target="_blank">
197
- πŸŽ₯ Video Watermarking
198
- </a>
199
- </div>
 
 
 
 
200
 
201
- <div class="nav-card">
202
- <a href="https://noumanjavaid-centii.hf.space" target="_blank">
203
- πŸ” Image Authentication
204
- </a>
205
- </div>
206
- ''')
207
-
208
- if __name__ == "__main__":
209
- demo.launch(
210
- show_error=True,
211
- show_api=False,
212
- height=800,
213
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import logging
3
+ import traceback
4
 
5
+ # Logging configuration
6
+ logging.basicConfig(
7
+ level=logging.INFO,
8
+ format='%(asctime)s - %(levelname)s: %(message)s',
9
+ handlers=[
10
+ logging.FileHandler('centurion_platform.log'),
11
+ logging.StreamHandler()
12
+ ]
13
+ )
14
+ logger = logging.getLogger(__name__)
15
+
16
+ # CSS with validation
17
+ def validate_css(css):
18
+ """
19
+ Basic CSS validation
20
+ """
21
+ required_selectors = [
22
+ '.header',
23
+ '.logo',
24
+ '.header-title',
25
+ '.container',
26
+ '.main-content',
27
+ '.iframe-container',
28
+ '.nav-grid',
29
+ '.nav-card'
30
+ ]
31
+
32
+ for selector in required_selectors:
33
+ if selector not in css:
34
+ logger.warning(f"Missing CSS selector: {selector}")
35
+
36
+ return css
37
+
38
+ # CSS with enhanced validation
39
+ css = validate_css("""
40
  * {
41
  margin: 0;
42
  padding: 0;
 
49
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
50
  }
51
 
 
52
  .header {
53
  background: #ffffff;
54
  border-bottom: 1px solid #e5e5e5;
 
65
  transition: transform 0.3s ease;
66
  }
67
 
 
 
 
 
68
  .header-title {
69
  color: #000000;
70
  font-size: 24px;
71
  font-weight: 600;
72
  }
73
 
 
74
  .container {
75
  max-width: 1400px;
76
  margin: 0 auto;
 
78
  background: #ffffff;
79
  }
80
 
 
81
  .main-content {
82
  background: #ffffff;
83
  border-radius: 12px;
 
85
  margin: 2rem 0;
86
  overflow: hidden;
87
  border: 1px solid #e5e5e5;
 
 
 
 
 
 
88
  }
89
 
90
  .iframe-container {
 
104
  border: none;
105
  }
106
 
 
107
  .nav-grid {
108
  display: grid;
109
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
 
111
  margin-top: 2rem;
112
  }
113
 
 
114
  .nav-card {
115
  background: #ffffff;
116
  border: 1px solid #e5e5e5;
117
  border-radius: 10px;
118
  padding: 1.5rem;
119
  transition: all 0.3s ease;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  }
121
 
122
+ @media (max-width: 768px) {
123
+ .nav-grid {
124
+ grid-template-columns: 1fr;
125
+ }
126
  }
127
+ """)
128
 
129
+ # Configuration validation
130
+ def validate_configuration(demo_config):
131
+ """
132
+ Validate Gradio configuration
133
+ """
134
+ required_attributes = [
135
+ 'title',
136
+ 'css',
137
+ 'show_error',
138
+ 'show_api',
139
+ 'show_tips',
140
+ 'height',
141
+ 'analytics_enabled',
142
+ 'enable_queue'
143
+ ]
144
+
145
+ validation_results = {}
146
+ for attr in required_attributes:
147
+ try:
148
+ value = getattr(demo_config, attr, None)
149
+ validation_results[attr] = value is not None
150
+ except Exception as e:
151
+ logger.error(f"Error validating {attr}: {e}")
152
+ validation_results[attr] = False
153
+
154
+ return validation_results
155
 
156
+ # Navigation cards validation
157
+ def validate_navigation_cards(cards):
158
+ """
159
+ Validate navigation card configuration
160
+ """
161
+ required_keys = ['icon', 'title', 'url']
162
+ invalid_cards = []
163
+
164
+ for card in cards:
165
+ missing_keys = [key for key in required_keys if key not in card]
166
+ if missing_keys:
167
+ invalid_cards.append({
168
+ 'card': card,
169
+ 'missing_keys': missing_keys
170
+ })
171
+
172
+ return invalid_cards
173
 
174
+ def create_demo():
175
+ """
176
+ Create Gradio demo with comprehensive validation
177
+ """
178
+ try:
179
+ cards = [
180
+ {"icon": "πŸ”", "title": "DeepFake Detection", "url": "https://noumanjavaid-new-space.hf.space"},
181
+ {"icon": "πŸ“„", "title": "Document Analysis", "url": "https://noumanjavaid-centurionv2.hf.space"},
182
+ {"icon": "πŸŽ₯", "title": "Video Watermarking", "url": "https://noumanjavaid-watermark-demo-video.hf.space"},
183
+ {"icon": "πŸ”", "title": "Image Authentication", "url": "https://noumanjavaid-centii.hf.space"},
184
+ ]
185
+
186
+ # Validate navigation cards
187
+ invalid_cards = validate_navigation_cards(cards)
188
+ if invalid_cards:
189
+ logger.warning(f"Invalid navigation cards: {invalid_cards}")
190
+
191
+ # Generate HTML for navigation cards
192
+ html_cards = "".join(
193
+ f'''
194
+ <div class="nav-card" role="navigation" aria-label="{card['title']}">
195
+ <a href="{card['url']}" target="_blank">
196
+ {card['icon']} {card['title']}
197
+ </a>
198
+ </div>
199
+ ''' for card in cards
200
  )
 
 
 
 
 
 
 
 
 
 
201
 
202
+ # Create Gradio block
203
+ with gr.Blocks(css=css, title="Centurion Analysis Platform") as demo:
204
+ # Header
205
+ with gr.Row(elem_classes=["header"]):
206
+ gr.Image(
207
+ "https://raw.githubusercontent.com/noumanjavaid96/ai-as-an-api/refs/heads/master/image%20(39).png",
208
+ elem_classes=["logo"],
209
+ show_label=False,
210
+ container=False
211
+ )
212
+ gr.Markdown("Centurion Analysis", elem_classes=["header-title"])
213
+
214
+ # Main content
215
+ with gr.Row(elem_classes=["container"]):
216
+ with gr.Column(elem_classes=["main-content"]):
217
+ gr.HTML('''
218
+ <div class="iframe-container">
219
+ <iframe
220
+ src="https://noumanjavaid-centii.hf.space"
221
+ loading="lazy"
222
+ title="Centurion Main Platform"
223
+ ></iframe>
224
+ </div>
225
+ ''')
226
 
227
+ # Navigation grid
228
+ with gr.Row(elem_classes=["nav-grid"]):
229
+ gr.HTML(html_cards)
230
+
231
+ # Validate configuration
232
+ config_validation = validate_configuration(demo)
233
+ logger.info(f"Configuration Validation: {config_validation}")
234
+
235
+ return demo
236
+
237
+ except Exception as e:
238
+ logger.error(f"Demo creation error: {e}")
239
+ logger.error(traceback.format_exc())
240
+ return None
241
+
242
+ def main():
243
+ """
244
+ Main application launch with comprehensive error handling
245
+ """
246
+ try:
247
+ demo = create_demo()
248
+
249
+ if demo is None:
250
+ logger.critical("Failed to create Gradio demo")
251
+ return
252
+
253
+ demo.launch(
254
+ show_error=True,
255
+ show_api=False,
256
+ show_tips=False,
257
+ height=800,
258
+ analytics_enabled=False,
259
+ enable_queue=False
260
+ )
261
+
262
+ except Exception as e:
263
+ logger