Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -54,7 +54,6 @@ def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
|
|
| 54 |
annotated_array = results[0].plot()
|
| 55 |
annotated_image = Image.fromarray(annotated_array[..., ::-1])
|
| 56 |
|
| 57 |
-
# Save for Download
|
| 58 |
temp_dir = tempfile.gettempdir()
|
| 59 |
save_path = os.path.join(temp_dir, "rosetta_decoded_result.jpg")
|
| 60 |
annotated_image.save(save_path)
|
|
@@ -83,21 +82,21 @@ def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
|
|
| 83 |
except Exception as e:
|
| 84 |
return None, {"error": str(e)}, f"System Failure: {str(e)}", None
|
| 85 |
|
| 86 |
-
# --- 3. UI STYLING
|
| 87 |
|
| 88 |
-
# SVG Cursor: Eye of Horus
|
| 89 |
cursor_url = "url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj4KICA8ZyBmaWxsPSJub25lIiBzdHJva2U9IiNkNGFmMzciIHN0cm9rZS13aWR0aD0iMS41Ij4KICAgIDxwYXRoIGQ9Ik0xNiw4IEM2LDIwIDI2LDIwIDE2LDggWiIgZmlsbD0icmdiYSgyMTIsIDE3NSwgNTUsIDAuMSkiLz4KICAgIDxjaXJjbGUgY3g9IjE2IiBjeT0iMTUiIHI9IjMiIGZpbGw9IiNkNGFmMzciLz4KICAgIDxwYXRoIGQ9Ik0xNiwyMiBMMTYsMjggTDEwLDI4Ii8+CiAgPC9nPgo8L3N2Zz4=')"
|
| 90 |
|
| 91 |
custom_css = f"""
|
| 92 |
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700&display=swap');
|
| 93 |
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap');
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
|
|
|
| 97 |
--bg-gradient: radial-gradient(circle at 50% 0%, #0a0a2e 0%, #000000 100%);
|
| 98 |
--card-bg: rgba(15, 15, 35, 0.7);
|
| 99 |
--text-primary: #e0e7ff;
|
| 100 |
-
--text-accent: #d4af37;
|
| 101 |
--border-color: #d4af37;
|
| 102 |
--btn-grad: linear-gradient(135deg, #b8860b 0%, #d4af37 100%);
|
| 103 |
--btn-text: #000;
|
|
@@ -106,21 +105,23 @@ custom_css = f"""
|
|
| 106 |
--glow-color: rgba(212, 175, 55, 0.4);
|
| 107 |
}}
|
| 108 |
|
| 109 |
-
/* --- LIGHT MODE OVERRIDE
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
--
|
| 113 |
-
--
|
| 114 |
-
--text-
|
| 115 |
-
--
|
| 116 |
-
--
|
| 117 |
-
--btn-
|
| 118 |
-
--
|
| 119 |
-
--info-
|
| 120 |
-
--
|
|
|
|
|
|
|
| 121 |
}}
|
| 122 |
|
| 123 |
-
/* --- GLOBAL
|
| 124 |
body, .gradio-container {{
|
| 125 |
background: var(--bg-gradient) !important;
|
| 126 |
font-family: 'Cairo', sans-serif !important;
|
|
@@ -134,7 +135,7 @@ button, a, .cursor-pointer {{
|
|
| 134 |
cursor: {cursor_url} 16 16, pointer !important;
|
| 135 |
}}
|
| 136 |
|
| 137 |
-
/* ---
|
| 138 |
.gold-dust {{
|
| 139 |
position: fixed;
|
| 140 |
width: 6px;
|
|
@@ -162,6 +163,7 @@ button, a, .cursor-pointer {{
|
|
| 162 |
backdrop-filter: blur(12px);
|
| 163 |
margin-bottom: 24px;
|
| 164 |
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
|
|
|
|
| 165 |
}}
|
| 166 |
|
| 167 |
.card:hover {{
|
|
@@ -187,7 +189,6 @@ button.primary-btn:hover {{
|
|
| 187 |
box-shadow: 0 0 25px var(--glow-color);
|
| 188 |
}}
|
| 189 |
|
| 190 |
-
/* Toggle Button */
|
| 191 |
button.toggle-btn {{
|
| 192 |
background: transparent !important;
|
| 193 |
border: 1px solid var(--border-color) !important;
|
|
@@ -199,53 +200,56 @@ button.toggle-btn:hover {{
|
|
| 199 |
background: var(--info-bg) !important;
|
| 200 |
}}
|
| 201 |
|
| 202 |
-
/* --- GUIDE BOXES --- */
|
| 203 |
.guide-step {{
|
| 204 |
-
background-color: var(--info-bg);
|
| 205 |
-
border-left: 4px solid var(--info-border);
|
| 206 |
padding: 16px;
|
| 207 |
margin: 12px 0;
|
| 208 |
border-radius: 0 8px 8px 0;
|
| 209 |
font-family: 'Space Mono', monospace;
|
| 210 |
font-size: 13px;
|
| 211 |
line-height: 1.6;
|
| 212 |
-
color: var(--text-primary);
|
| 213 |
}}
|
| 214 |
|
| 215 |
.step-number {{
|
| 216 |
-
color: var(--text-accent);
|
| 217 |
font-weight: bold;
|
| 218 |
text-transform: uppercase;
|
| 219 |
display: block;
|
| 220 |
margin-bottom: 6px;
|
| 221 |
font-size: 12px;
|
| 222 |
}}
|
|
|
|
| 223 |
.path-highlight {{
|
| 224 |
background: rgba(128,128,128,0.2);
|
| 225 |
padding: 3px 8px;
|
| 226 |
border-radius: 4px;
|
| 227 |
-
color: var(--text-accent);
|
| 228 |
font-weight: bold;
|
| 229 |
border: 1px solid var(--border-color);
|
| 230 |
}}
|
| 231 |
|
| 232 |
-
/* ---
|
| 233 |
.gradio-image, .gradio-json {{ background: transparent !important; border: none !important; }}
|
| 234 |
|
| 235 |
-
/*
|
| 236 |
-
body.light-mode .gradio-image button
|
| 237 |
-
|
|
|
|
| 238 |
border: 2px dashed var(--border-color) !important;
|
| 239 |
-
color: var(--text-primary) !important;
|
| 240 |
}}
|
| 241 |
|
| 242 |
.report-box textarea {{
|
| 243 |
background-color: rgba(0,0,0,0.2) !important;
|
| 244 |
border: 1px solid var(--border-color) !important;
|
| 245 |
font-family: 'Space Mono', monospace !important;
|
| 246 |
-
color: var(--text-primary) !important;
|
| 247 |
font-size: 14px !important;
|
| 248 |
}}
|
|
|
|
| 249 |
.block-title {{ color: var(--text-accent) !important; }}
|
| 250 |
span {{ color: var(--text-primary); }}
|
| 251 |
"""
|
|
@@ -337,7 +341,6 @@ claude_json_content = """{
|
|
| 337 |
|
| 338 |
# --- 4. MAIN APP ASSEMBLY ---
|
| 339 |
|
| 340 |
-
# Trail Script attached to body load
|
| 341 |
trail_script = """
|
| 342 |
<script>
|
| 343 |
document.addEventListener('DOMContentLoaded', () => {
|
|
@@ -364,7 +367,6 @@ with gr.Blocks(title="Rosetta Decoder") as demo:
|
|
| 364 |
with gr.Column(scale=4):
|
| 365 |
gr.HTML(header_html)
|
| 366 |
with gr.Column(scale=1):
|
| 367 |
-
# JS-based Toggle button
|
| 368 |
btn_toggle = gr.Button("๐ Day / Night", elem_classes="toggle-btn")
|
| 369 |
|
| 370 |
gr.HTML(mission_html)
|
|
@@ -400,7 +402,7 @@ with gr.Blocks(title="Rosetta Decoder") as demo:
|
|
| 400 |
gr.HTML("</div>")
|
| 401 |
|
| 402 |
# Wiring
|
| 403 |
-
#
|
| 404 |
btn_toggle.click(None, None, None, js="() => { document.body.classList.toggle('light-mode'); document.querySelector('.gradio-container').classList.toggle('light-mode'); }")
|
| 405 |
|
| 406 |
btn_upload.click(fn=detect_hieroglyphs, inputs=[img_upload, slider_upload], outputs=[out_image, out_json, out_report, btn_download])
|
|
|
|
| 54 |
annotated_array = results[0].plot()
|
| 55 |
annotated_image = Image.fromarray(annotated_array[..., ::-1])
|
| 56 |
|
|
|
|
| 57 |
temp_dir = tempfile.gettempdir()
|
| 58 |
save_path = os.path.join(temp_dir, "rosetta_decoded_result.jpg")
|
| 59 |
annotated_image.save(save_path)
|
|
|
|
| 82 |
except Exception as e:
|
| 83 |
return None, {"error": str(e)}, f"System Failure: {str(e)}", None
|
| 84 |
|
| 85 |
+
# --- 3. UI STYLING ---
|
| 86 |
|
|
|
|
| 87 |
cursor_url = "url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj4KICA8ZyBmaWxsPSJub25lIiBzdHJva2U9IiNkNGFmMzciIHN0cm9rZS13aWR0aD0iMS41Ij4KICAgIDxwYXRoIGQ9Ik0xNiw4IEM2LDIwIDI2LDIwIDE2LDggWiIgZmlsbD0icmdiYSgyMTIsIDE3NSwgNTUsIDAuMSkiLz4KICAgIDxjaXJjbGUgY3g9IjE2IiBjeT0iMTUiIHI9IjMiIGZpbGw9IiNkNGFmMzciLz4KICAgIDxwYXRoIGQ9Ik0xNiwyMiBMMTYsMjggTDEwLDI4Ii8+CiAgPC9nPgo8L3N2Zz4=')"
|
| 88 |
|
| 89 |
custom_css = f"""
|
| 90 |
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700&display=swap');
|
| 91 |
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap');
|
| 92 |
|
| 93 |
+
/* --- 1. DEFAULT (DARK/NIGHT MODE) --- */
|
| 94 |
+
/* This applies when the page first loads or when 'light-mode' is NOT active */
|
| 95 |
+
:root, .dark, body {{
|
| 96 |
--bg-gradient: radial-gradient(circle at 50% 0%, #0a0a2e 0%, #000000 100%);
|
| 97 |
--card-bg: rgba(15, 15, 35, 0.7);
|
| 98 |
--text-primary: #e0e7ff;
|
| 99 |
+
--text-accent: #d4af37;
|
| 100 |
--border-color: #d4af37;
|
| 101 |
--btn-grad: linear-gradient(135deg, #b8860b 0%, #d4af37 100%);
|
| 102 |
--btn-text: #000;
|
|
|
|
| 105 |
--glow-color: rgba(212, 175, 55, 0.4);
|
| 106 |
}}
|
| 107 |
|
| 108 |
+
/* --- 2. LIGHT MODE OVERRIDE (PAPYRUS) --- */
|
| 109 |
+
/* We use high specificity (.gradio-container.light-mode) to defeat the OS dark mode */
|
| 110 |
+
body.light-mode, .gradio-container.light-mode {{
|
| 111 |
+
--bg-gradient: linear-gradient(135deg, #f0e6d2 0%, #e6dcc3 100%) !important;
|
| 112 |
+
--card-bg: rgba(255, 255, 255, 0.6) !important;
|
| 113 |
+
--text-primary: #3d342b !important; /* Forces Dark Text */
|
| 114 |
+
--text-accent: #8b4513 !important; /* Forces Brown Accent */
|
| 115 |
+
--border-color: #8b4513 !important;
|
| 116 |
+
--btn-grad: linear-gradient(135deg, #cd853f 0%, #8b4513 100%) !important;
|
| 117 |
+
--btn-text: #fff !important;
|
| 118 |
+
--info-bg: rgba(139, 69, 19, 0.05) !important;
|
| 119 |
+
--info-border: #8b4513 !important;
|
| 120 |
+
--glow-color: rgba(139, 69, 19, 0.3) !important;
|
| 121 |
+
color: #3d342b !important; /* Force Body Text Dark */
|
| 122 |
}}
|
| 123 |
|
| 124 |
+
/* --- GLOBAL LAYOUT --- */
|
| 125 |
body, .gradio-container {{
|
| 126 |
background: var(--bg-gradient) !important;
|
| 127 |
font-family: 'Cairo', sans-serif !important;
|
|
|
|
| 135 |
cursor: {cursor_url} 16 16, pointer !important;
|
| 136 |
}}
|
| 137 |
|
| 138 |
+
/* --- TRAIL --- */
|
| 139 |
.gold-dust {{
|
| 140 |
position: fixed;
|
| 141 |
width: 6px;
|
|
|
|
| 163 |
backdrop-filter: blur(12px);
|
| 164 |
margin-bottom: 24px;
|
| 165 |
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
|
| 166 |
+
color: var(--text-primary) !important;
|
| 167 |
}}
|
| 168 |
|
| 169 |
.card:hover {{
|
|
|
|
| 189 |
box-shadow: 0 0 25px var(--glow-color);
|
| 190 |
}}
|
| 191 |
|
|
|
|
| 192 |
button.toggle-btn {{
|
| 193 |
background: transparent !important;
|
| 194 |
border: 1px solid var(--border-color) !important;
|
|
|
|
| 200 |
background: var(--info-bg) !important;
|
| 201 |
}}
|
| 202 |
|
| 203 |
+
/* --- GUIDE BOXES & TEXT COLORS --- */
|
| 204 |
.guide-step {{
|
| 205 |
+
background-color: var(--info-bg) !important;
|
| 206 |
+
border-left: 4px solid var(--info-border) !important;
|
| 207 |
padding: 16px;
|
| 208 |
margin: 12px 0;
|
| 209 |
border-radius: 0 8px 8px 0;
|
| 210 |
font-family: 'Space Mono', monospace;
|
| 211 |
font-size: 13px;
|
| 212 |
line-height: 1.6;
|
| 213 |
+
color: var(--text-primary) !important; /* STRICT COLOR ENFORCEMENT */
|
| 214 |
}}
|
| 215 |
|
| 216 |
.step-number {{
|
| 217 |
+
color: var(--text-accent) !important;
|
| 218 |
font-weight: bold;
|
| 219 |
text-transform: uppercase;
|
| 220 |
display: block;
|
| 221 |
margin-bottom: 6px;
|
| 222 |
font-size: 12px;
|
| 223 |
}}
|
| 224 |
+
|
| 225 |
.path-highlight {{
|
| 226 |
background: rgba(128,128,128,0.2);
|
| 227 |
padding: 3px 8px;
|
| 228 |
border-radius: 4px;
|
| 229 |
+
color: var(--text-accent) !important;
|
| 230 |
font-weight: bold;
|
| 231 |
border: 1px solid var(--border-color);
|
| 232 |
}}
|
| 233 |
|
| 234 |
+
/* --- FIXES --- */
|
| 235 |
.gradio-image, .gradio-json {{ background: transparent !important; border: none !important; }}
|
| 236 |
|
| 237 |
+
/* Fix Light Mode Upload Box Background */
|
| 238 |
+
body.light-mode .gradio-image button,
|
| 239 |
+
.gradio-container.light-mode .gradio-image button {{
|
| 240 |
+
background-color: rgba(255, 248, 240, 0.7) !important;
|
| 241 |
border: 2px dashed var(--border-color) !important;
|
| 242 |
+
color: var(--text-primary) !important;
|
| 243 |
}}
|
| 244 |
|
| 245 |
.report-box textarea {{
|
| 246 |
background-color: rgba(0,0,0,0.2) !important;
|
| 247 |
border: 1px solid var(--border-color) !important;
|
| 248 |
font-family: 'Space Mono', monospace !important;
|
| 249 |
+
color: var(--text-primary) !important; /* Ensure text matches theme */
|
| 250 |
font-size: 14px !important;
|
| 251 |
}}
|
| 252 |
+
|
| 253 |
.block-title {{ color: var(--text-accent) !important; }}
|
| 254 |
span {{ color: var(--text-primary); }}
|
| 255 |
"""
|
|
|
|
| 341 |
|
| 342 |
# --- 4. MAIN APP ASSEMBLY ---
|
| 343 |
|
|
|
|
| 344 |
trail_script = """
|
| 345 |
<script>
|
| 346 |
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
| 367 |
with gr.Column(scale=4):
|
| 368 |
gr.HTML(header_html)
|
| 369 |
with gr.Column(scale=1):
|
|
|
|
| 370 |
btn_toggle = gr.Button("๐ Day / Night", elem_classes="toggle-btn")
|
| 371 |
|
| 372 |
gr.HTML(mission_html)
|
|
|
|
| 402 |
gr.HTML("</div>")
|
| 403 |
|
| 404 |
# Wiring
|
| 405 |
+
# JS: Toggle 'light-mode' on body AND container to defeat OS dark mode
|
| 406 |
btn_toggle.click(None, None, None, js="() => { document.body.classList.toggle('light-mode'); document.querySelector('.gradio-container').classList.toggle('light-mode'); }")
|
| 407 |
|
| 408 |
btn_upload.click(fn=detect_hieroglyphs, inputs=[img_upload, slider_upload], outputs=[out_image, out_json, out_report, btn_download])
|