thrimurthi2025 commited on
Commit
f32bad1
·
verified ·
1 Parent(s): 2b63db7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -77
app.py CHANGED
@@ -2,8 +2,10 @@ import gradio as gr
2
  from transformers import pipeline
3
  from PIL import Image
4
  import traceback
 
 
5
 
6
- # Models (unchanged)
7
  models = [
8
  ("Ateeqq/ai-vs-human-image-detector", "ateeq"),
9
  ("umm-maybe/AI-image-detector", "umm_maybe"),
@@ -38,7 +40,7 @@ def predict_image(image: Image.Image):
38
 
39
  html = f"""
40
  <div class='result-box' style="
41
- background: linear-gradient(135deg, {color}33, #0f1215);
42
  border: 2px solid {color};
43
  border-radius: 15px;
44
  padding: 25px;
@@ -57,86 +59,39 @@ def predict_image(image: Image.Image):
57
  traceback.print_exc()
58
  return f"<div style='color:red;'>Error analyzing image: {str(e)}</div>"
59
 
60
- # Strong dark-mode CSS overrides (higher specificity + !important)
61
  css = """
62
- /* base */
63
- :root {
64
- --bg: #0b0d0f;
65
- --panel: #0f1215;
66
- --muted: #9aa3b2;
67
- --text: #e6eef8;
68
- --primary: #007BFF;
69
- --danger: #dc3545;
70
- }
71
-
72
- /* Ensure our font + layout */
73
- body, .gradio-container, .gradio-app {
74
- background: var(--bg) !important;
75
- color: var(--text) !important;
76
  font-family: 'Poppins', sans-serif !important;
77
- }
78
-
79
- /* Top-level panels */
80
- .gradio-container, .gradio-interface, .gradio-row, .gradio-column, .gradio-panel {
81
  background: transparent !important;
82
  }
83
-
84
- /* Panels and cards */
85
- .gradio-container .card, .gradio-container .panel, .gradio-container .component {
86
- background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01)) !important;
87
- border: 1px solid rgba(255,255,255,0.04) !important;
88
- color: var(--text) !important;
89
- box-shadow: 0 6px 18px rgba(0,0,0,0.6) !important;
90
- }
91
-
92
- /* Inputs & image blocks */
93
- .gradio-container .input_image, .gradio-container input, .gradio-container textarea, .gradio-container .file-input {
94
- background: #0b0d0f !important;
95
- border: 1px solid rgba(255,255,255,0.05) !important;
96
- color: var(--text) !important;
97
- }
98
-
99
- /* Buttons */
100
- .gradio-container .gr-button, .gradio-container button {
101
- background: rgba(255,255,255,0.03) !important;
102
- color: var(--text) !important;
103
- border-radius: 10px !important;
104
- border: 1px solid rgba(255,255,255,0.04) !important;
105
- height: 44px !important;
106
- font-weight: 600 !important;
107
  }
108
- .gradio-container .gr-button-primary {
109
- background: linear-gradient(90deg, var(--primary), #00C3FF) !important;
110
- color: #fff !important;
111
- border: 1px solid rgba(255,255,255,0.06) !important;
112
- box-shadow: 0 6px 18px rgba(0,123,255,0.12) !important;
 
113
  }
114
- .gradio-container .gr-button-secondary {
115
- background: linear-gradient(90deg, var(--danger), #ff6b6b) !important;
116
- color: #fff !important;
 
 
117
  }
118
-
119
- /* Markdown / text */
120
- .gradio-container .markdown, .gradio-container h1, .gradio-container p {
121
- color: var(--text) !important;
122
- }
123
-
124
- /* Hide any built-in theme toggles if present */
125
- .gradio-container .color-scheme-toggle, .gradio-container .theme-toggle {
126
- display: none !important;
127
- }
128
-
129
- /* Loader bar */
130
  #pulse-loader {
131
  width: 100%;
132
  height: 4px;
133
- background: linear-gradient(90deg, var(--primary), #00C3FF) !important;
134
  animation: pulse 1.2s infinite ease-in-out;
135
  border-radius: 2px;
136
- box-shadow: 0 0 10px var(--primary) !important;
137
  }
138
-
139
- /* animations */
140
  @keyframes pulse {
141
  0% { transform: scaleX(0.1); opacity: 0.6; }
142
  50% { transform: scaleX(1); opacity: 1; }
@@ -146,15 +101,9 @@ body, .gradio-container, .gradio-app {
146
  from { opacity: 0; transform: scale(0.95); }
147
  to { opacity: 1; transform: scale(1); }
148
  }
149
-
150
- /* result box fallback (keep it visible) */
151
- .result-box {
152
- margin: 12px auto !important;
153
- max-width: 420px !important;
154
- }
155
  """
156
 
157
- with gr.Blocks(css=css) as demo: # <- removed theme param
158
  gr.Markdown("<h1>🔍 AI Image Detector</h1>")
159
 
160
  with gr.Row():
@@ -168,10 +117,11 @@ with gr.Blocks(css=css) as demo: # <- removed theme param
168
 
169
  def analyze(img):
170
  if img is None:
171
- return ("", "<div style='color:#ff6b6b;'>Please upload an image first!</div>")
172
  loader_html = "<div id='pulse-loader'></div>"
173
  yield (loader_html, "") # instantly show loader
174
 
 
175
  result = predict_image(img)
176
  yield ("", result) # hide loader, show result
177
 
 
2
  from transformers import pipeline
3
  from PIL import Image
4
  import traceback
5
+ import time
6
+ import threading
7
 
8
+ # Models
9
  models = [
10
  ("Ateeqq/ai-vs-human-image-detector", "ateeq"),
11
  ("umm-maybe/AI-image-detector", "umm_maybe"),
 
40
 
41
  html = f"""
42
  <div class='result-box' style="
43
+ background: linear-gradient(135deg, {color}33, #1a1a1a);
44
  border: 2px solid {color};
45
  border-radius: 15px;
46
  padding: 25px;
 
59
  traceback.print_exc()
60
  return f"<div style='color:red;'>Error analyzing image: {str(e)}</div>"
61
 
62
+ # CSS for sleek glowing pulse
63
  css = """
64
+ body, .gradio-container {
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  font-family: 'Poppins', sans-serif !important;
 
 
 
 
66
  background: transparent !important;
67
  }
68
+ h1 {
69
+ text-align: center;
70
+ font-weight: 700;
71
+ color: #007BFF;
72
+ margin-bottom: 10px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  }
74
+ .gr-button-primary {
75
+ background-color: #007BFF !important;
76
+ color: white !important;
77
+ font-weight: 600;
78
+ border-radius: 10px;
79
+ height: 45px;
80
  }
81
+ .gr-button-secondary {
82
+ background-color: #dc3545 !important;
83
+ color: white !important;
84
+ border-radius: 10px;
85
+ height: 45px;
86
  }
 
 
 
 
 
 
 
 
 
 
 
 
87
  #pulse-loader {
88
  width: 100%;
89
  height: 4px;
90
+ background: linear-gradient(90deg, #007BFF, #00C3FF);
91
  animation: pulse 1.2s infinite ease-in-out;
92
  border-radius: 2px;
93
+ box-shadow: 0 0 10px #007BFF;
94
  }
 
 
95
  @keyframes pulse {
96
  0% { transform: scaleX(0.1); opacity: 0.6; }
97
  50% { transform: scaleX(1); opacity: 1; }
 
101
  from { opacity: 0; transform: scale(0.95); }
102
  to { opacity: 1; transform: scale(1); }
103
  }
 
 
 
 
 
 
104
  """
105
 
106
+ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
107
  gr.Markdown("<h1>🔍 AI Image Detector</h1>")
108
 
109
  with gr.Row():
 
117
 
118
  def analyze(img):
119
  if img is None:
120
+ return ("", "<div style='color:red;'>Please upload an image first!</div>")
121
  loader_html = "<div id='pulse-loader'></div>"
122
  yield (loader_html, "") # instantly show loader
123
 
124
+ # do analysis in background
125
  result = predict_image(img)
126
  yield ("", result) # hide loader, show result
127