Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,7 +26,7 @@ except Exception as e:
|
|
| 26 |
# --- 2. LOGIC ---
|
| 27 |
def generate_human_report(detections, counts):
|
| 28 |
if not detections:
|
| 29 |
-
return "The
|
| 30 |
|
| 31 |
total = len(detections)
|
| 32 |
sorted_counts = sorted(counts.items(), key=lambda item: item[1], reverse=True)
|
|
@@ -80,55 +80,50 @@ def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
|
|
| 80 |
return None, {"error": str(e)}, f"Critical Error: {str(e)}"
|
| 81 |
|
| 82 |
# --- 3. THE MYSTICAL UI (CSS) ---
|
| 83 |
-
# We use CSS Variables (--name) to handle Light/Dark mode switching automatically.
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
cursor_url = "url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj4KICA8ZyBmaWxsPSJub25lIiBzdHJva2U9IiNkNGFmMzciIHN0cm9rZS13aWR0aD0iMiI+
|
| 87 |
|
| 88 |
custom_css = f"""
|
| 89 |
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&display=swap');
|
| 90 |
@import url('https://fonts.googleapis.com/css2?family=Courier+Prime&display=swap');
|
| 91 |
|
| 92 |
-
/* ---
|
| 93 |
:root {{
|
| 94 |
-
/*
|
| 95 |
--bg-gradient: linear-gradient(135deg, #fdf6e3 0%, #f5e6d3 100%);
|
| 96 |
--card-bg: rgba(255, 255, 255, 0.6);
|
| 97 |
-
--text-primary: #5c4033;
|
| 98 |
-
--text-accent: #b8860b;
|
| 99 |
--border-color: #d4af37;
|
| 100 |
-
--highlight-bg: rgba(212, 175, 55, 0.1);
|
| 101 |
--warning-bg: rgba(255, 0, 0, 0.05);
|
| 102 |
--warning-border: #cc0000;
|
| 103 |
}}
|
| 104 |
|
| 105 |
.dark {{
|
| 106 |
-
/*
|
| 107 |
--bg-gradient: radial-gradient(circle at 50% 0%, #1a1f35 0%, #050510 100%);
|
| 108 |
--card-bg: rgba(10, 15, 30, 0.7);
|
| 109 |
-
--text-primary: #e0e7ff;
|
| 110 |
-
--text-accent: #ffd700;
|
| 111 |
--border-color: #d4af37;
|
| 112 |
-
--highlight-bg: rgba(212, 175, 55, 0.1);
|
| 113 |
--warning-bg: rgba(255, 99, 71, 0.1);
|
| 114 |
--warning-border: #ff6b6b;
|
| 115 |
}}
|
| 116 |
|
| 117 |
-
/* ---
|
| 118 |
body, .gradio-container {{
|
| 119 |
background: var(--bg-gradient) !important;
|
| 120 |
font-family: 'Cinzel', serif !important;
|
| 121 |
color: var(--text-primary) !important;
|
| 122 |
-
/* MYSTICAL CURSOR */
|
| 123 |
cursor: {cursor_url} 16 16, auto !important;
|
| 124 |
}}
|
| 125 |
|
| 126 |
-
/* BUTTONS & LINKS CURSOR OVERRIDE */
|
| 127 |
button, a, .cursor-pointer {{
|
| 128 |
cursor: {cursor_url} 16 16, pointer !important;
|
| 129 |
}}
|
| 130 |
|
| 131 |
-
/* ---
|
| 132 |
.card {{
|
| 133 |
background: var(--card-bg) !important;
|
| 134 |
border: 1px solid rgba(212, 175, 55, 0.3) !important;
|
|
@@ -137,14 +132,14 @@ button, a, .cursor-pointer {{
|
|
| 137 |
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
| 138 |
backdrop-filter: blur(10px);
|
| 139 |
margin-bottom: 20px;
|
| 140 |
-
transition: all 0.4s ease;
|
| 141 |
}}
|
| 142 |
|
| 143 |
-
/* HOVER
|
| 144 |
.card:hover {{
|
| 145 |
transform: translateY(-5px);
|
| 146 |
border-color: var(--border-color) !important;
|
| 147 |
-
box-shadow: 0 0
|
| 148 |
}}
|
| 149 |
|
| 150 |
.card-title {{
|
|
@@ -158,7 +153,7 @@ button, a, .cursor-pointer {{
|
|
| 158 |
margin-bottom: 15px;
|
| 159 |
}}
|
| 160 |
|
| 161 |
-
/* ---
|
| 162 |
button.primary-btn {{
|
| 163 |
background: linear-gradient(135deg, #b8860b 0%, #d4af37 100%) !important;
|
| 164 |
border: 1px solid #ffd700 !important;
|
|
@@ -171,56 +166,52 @@ button.primary-btn {{
|
|
| 171 |
}}
|
| 172 |
|
| 173 |
button.primary-btn:hover {{
|
| 174 |
-
transform: scale(1.
|
| 175 |
-
box-shadow: 0 0
|
| 176 |
}}
|
| 177 |
|
| 178 |
-
/* ---
|
| 179 |
.warning-box {{
|
| 180 |
background-color: var(--warning-bg);
|
| 181 |
border-left: 5px solid var(--warning-border);
|
| 182 |
padding: 15px;
|
| 183 |
margin: 10px 0;
|
| 184 |
border-radius: 0 10px 10px 0;
|
| 185 |
-
font-family: 'Courier Prime', monospace;
|
| 186 |
font-size: 13px;
|
| 187 |
}}
|
| 188 |
|
| 189 |
-
.
|
| 190 |
-
background
|
| 191 |
-
border: 1px dashed var(--border-color);
|
| 192 |
padding: 2px 6px;
|
| 193 |
border-radius: 4px;
|
| 194 |
-
color: var(--text-accent);
|
| 195 |
font-weight: bold;
|
|
|
|
| 196 |
}}
|
| 197 |
|
| 198 |
-
/*
|
|
|
|
| 199 |
.report-box textarea {{
|
| 200 |
background-color: rgba(0,0,0,0.2) !important;
|
| 201 |
border: 1px solid var(--border-color) !important;
|
| 202 |
font-family: 'Courier Prime', monospace !important;
|
| 203 |
color: var(--text-accent) !important;
|
| 204 |
}}
|
| 205 |
-
|
| 206 |
-
/* REMOVE DEFAULT GRADIO BORDERS */
|
| 207 |
-
.gradio-image, .gradio-json {{ background: transparent !important; border: none !important; }}
|
| 208 |
"""
|
| 209 |
|
| 210 |
-
# HTML HEADER
|
| 211 |
header_html = """
|
| 212 |
<div style="display: flex; align-items: center; gap: 20px; padding: 20px 0;">
|
| 213 |
-
<div style="font-size:
|
| 214 |
<div>
|
| 215 |
<h1 style="margin: 0; font-size: 32px; color: var(--text-accent);">HORUS VISION</h1>
|
| 216 |
-
<p style="margin: 0;
|
| 217 |
</div>
|
| 218 |
</div>
|
| 219 |
"""
|
| 220 |
|
| 221 |
mission_html = """
|
| 222 |
<div class="card">
|
| 223 |
-
<div class="card-title">π
|
| 224 |
<p style="opacity: 0.9; font-size: 14px; line-height: 1.6;">
|
| 225 |
<b>To preserve the past is to save the future.</b><br>
|
| 226 |
This tool uses AI to digitize Ancient Egyptian inscriptions.
|
|
@@ -229,33 +220,27 @@ mission_html = """
|
|
| 229 |
</div>
|
| 230 |
"""
|
| 231 |
|
| 232 |
-
# NEW DETAILED INSTRUCTIONS HTML
|
| 233 |
guide_instructions_html = """
|
| 234 |
<div class="card" style="border-color: var(--warning-border) !important;">
|
| 235 |
-
<div class="card-title" style="color: var(--warning-border);">π€ CLAUDE DESKTOP
|
| 236 |
|
| 237 |
<div class="warning-box">
|
| 238 |
-
<strong style="font-size:14px; display:block; margin-bottom:5px;">β οΈ
|
| 239 |
-
Claude Desktop cannot see your
|
| 240 |
-
1.
|
| 241 |
-
2.
|
| 242 |
-
3.
|
| 243 |
-
<i>"Analyze the image at C:\\Claude_Work\\papyrus.jpg"</i>
|
| 244 |
</div>
|
| 245 |
|
| 246 |
<div class="warning-box" style="border-color: var(--text-accent);">
|
| 247 |
-
<strong style="font-size:14px; display:block; margin-bottom:5px;">π
|
| 248 |
-
The
|
| 249 |
-
If
|
| 250 |
-
<
|
| 251 |
-
<b>Action:</b> If the path is different, copy the path from CMD and replace it in the JSON below.
|
| 252 |
</div>
|
| 253 |
|
| 254 |
-
<div style="margin-top: 15px; opacity: 0.9;">
|
| 255 |
-
<b>
|
| 256 |
-
1. Open your Config file: <code>%APPDATA%\\Claude\\claude_desktop_config.json</code><br>
|
| 257 |
-
2. Paste the code block below.<br>
|
| 258 |
-
3. <b>Fully Quit</b> Claude (Right-click Icon in Tray -> Quit) and restart.
|
| 259 |
</div>
|
| 260 |
"""
|
| 261 |
|
|
@@ -284,7 +269,9 @@ claude_json_content = """{
|
|
| 284 |
}"""
|
| 285 |
|
| 286 |
# --- 4. MAIN APP ---
|
| 287 |
-
|
|
|
|
|
|
|
| 288 |
# Inject CSS
|
| 289 |
gr.HTML(f"<style>{custom_css}</style>")
|
| 290 |
|
|
@@ -316,7 +303,7 @@ with gr.Blocks(title="Horus Vision", theme=gr.themes.Default()) as demo:
|
|
| 316 |
out_json = gr.JSON(label="JSON Data")
|
| 317 |
gr.HTML('</div>')
|
| 318 |
|
| 319 |
-
# Config Section
|
| 320 |
gr.HTML(guide_instructions_html)
|
| 321 |
gr.Code(value=claude_json_content, language="json", label="claude_desktop_config.json", interactive=False, lines=15)
|
| 322 |
gr.HTML("</div>")
|
|
|
|
| 26 |
# --- 2. LOGIC ---
|
| 27 |
def generate_human_report(detections, counts):
|
| 28 |
if not detections:
|
| 29 |
+
return "The system detects no intelligible glyphs in this image."
|
| 30 |
|
| 31 |
total = len(detections)
|
| 32 |
sorted_counts = sorted(counts.items(), key=lambda item: item[1], reverse=True)
|
|
|
|
| 80 |
return None, {"error": str(e)}, f"Critical Error: {str(e)}"
|
| 81 |
|
| 82 |
# --- 3. THE MYSTICAL UI (CSS) ---
|
|
|
|
| 83 |
|
| 84 |
+
# Eye of Horus Cursor (SVG Base64)
|
| 85 |
+
cursor_url = "url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgdmlld0JveD0iMCAwIDMyIDMyIj4KICA8ZyBmaWxsPSJub25lIiBzdHJva2U9IiNkNGFmMzciIHN0cm9rZS13aWR0aD0iMiI+CiAgICA8cGF0aCBkPSZNMTYsOCBDNiwyMCAyNiwyMCAxNiw4IFoiIGZpbGw9InJnYmEoMjEyLCAxNzUsIDU1LCAwLjEpIi8+CiAgICA8cGF0aCBkPSZNMTYsMjIgTDEwLDI4IEwyMiwyOCIvPgogICAgPGNpcmNsZSBjeD0iMTYiIGN5PSIxNSIgcj0iMyIgZmlsbD0iI2Q0YWYzNyIvPgogIDwvZz4KPC9zdmc+')"
|
| 86 |
|
| 87 |
custom_css = f"""
|
| 88 |
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&display=swap');
|
| 89 |
@import url('https://fonts.googleapis.com/css2?family=Courier+Prime&display=swap');
|
| 90 |
|
| 91 |
+
/* --- THEME VARIABLES (DAY vs NIGHT) --- */
|
| 92 |
:root {{
|
| 93 |
+
/* DAY MODE (PAPYRUS) */
|
| 94 |
--bg-gradient: linear-gradient(135deg, #fdf6e3 0%, #f5e6d3 100%);
|
| 95 |
--card-bg: rgba(255, 255, 255, 0.6);
|
| 96 |
+
--text-primary: #5c4033;
|
| 97 |
+
--text-accent: #b8860b;
|
| 98 |
--border-color: #d4af37;
|
|
|
|
| 99 |
--warning-bg: rgba(255, 0, 0, 0.05);
|
| 100 |
--warning-border: #cc0000;
|
| 101 |
}}
|
| 102 |
|
| 103 |
.dark {{
|
| 104 |
+
/* NIGHT MODE (LAPIS) */
|
| 105 |
--bg-gradient: radial-gradient(circle at 50% 0%, #1a1f35 0%, #050510 100%);
|
| 106 |
--card-bg: rgba(10, 15, 30, 0.7);
|
| 107 |
+
--text-primary: #e0e7ff;
|
| 108 |
+
--text-accent: #ffd700;
|
| 109 |
--border-color: #d4af37;
|
|
|
|
| 110 |
--warning-bg: rgba(255, 99, 71, 0.1);
|
| 111 |
--warning-border: #ff6b6b;
|
| 112 |
}}
|
| 113 |
|
| 114 |
+
/* --- GLOBAL --- */
|
| 115 |
body, .gradio-container {{
|
| 116 |
background: var(--bg-gradient) !important;
|
| 117 |
font-family: 'Cinzel', serif !important;
|
| 118 |
color: var(--text-primary) !important;
|
|
|
|
| 119 |
cursor: {cursor_url} 16 16, auto !important;
|
| 120 |
}}
|
| 121 |
|
|
|
|
| 122 |
button, a, .cursor-pointer {{
|
| 123 |
cursor: {cursor_url} 16 16, pointer !important;
|
| 124 |
}}
|
| 125 |
|
| 126 |
+
/* --- CARDS & ANIMATIONS --- */
|
| 127 |
.card {{
|
| 128 |
background: var(--card-bg) !important;
|
| 129 |
border: 1px solid rgba(212, 175, 55, 0.3) !important;
|
|
|
|
| 132 |
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
| 133 |
backdrop-filter: blur(10px);
|
| 134 |
margin-bottom: 20px;
|
| 135 |
+
transition: all 0.4s ease;
|
| 136 |
}}
|
| 137 |
|
| 138 |
+
/* HOVER EFFECT: Pulse */
|
| 139 |
.card:hover {{
|
| 140 |
transform: translateY(-5px);
|
| 141 |
border-color: var(--border-color) !important;
|
| 142 |
+
box-shadow: 0 0 25px rgba(212, 175, 55, 0.3);
|
| 143 |
}}
|
| 144 |
|
| 145 |
.card-title {{
|
|
|
|
| 153 |
margin-bottom: 15px;
|
| 154 |
}}
|
| 155 |
|
| 156 |
+
/* --- BUTTONS --- */
|
| 157 |
button.primary-btn {{
|
| 158 |
background: linear-gradient(135deg, #b8860b 0%, #d4af37 100%) !important;
|
| 159 |
border: 1px solid #ffd700 !important;
|
|
|
|
| 166 |
}}
|
| 167 |
|
| 168 |
button.primary-btn:hover {{
|
| 169 |
+
transform: scale(1.05);
|
| 170 |
+
box-shadow: 0 0 30px rgba(212, 175, 55, 0.8);
|
| 171 |
}}
|
| 172 |
|
| 173 |
+
/* --- WARNING BOXES --- */
|
| 174 |
.warning-box {{
|
| 175 |
background-color: var(--warning-bg);
|
| 176 |
border-left: 5px solid var(--warning-border);
|
| 177 |
padding: 15px;
|
| 178 |
margin: 10px 0;
|
| 179 |
border-radius: 0 10px 10px 0;
|
| 180 |
+
font-family: 'Courier Prime', monospace;
|
| 181 |
font-size: 13px;
|
| 182 |
}}
|
| 183 |
|
| 184 |
+
.path-box {{
|
| 185 |
+
background: rgba(128, 128, 128, 0.2);
|
|
|
|
| 186 |
padding: 2px 6px;
|
| 187 |
border-radius: 4px;
|
|
|
|
| 188 |
font-weight: bold;
|
| 189 |
+
color: var(--text-accent);
|
| 190 |
}}
|
| 191 |
|
| 192 |
+
/* UI CLEANUP */
|
| 193 |
+
.gradio-image, .gradio-json {{ background: transparent !important; border: none !important; }}
|
| 194 |
.report-box textarea {{
|
| 195 |
background-color: rgba(0,0,0,0.2) !important;
|
| 196 |
border: 1px solid var(--border-color) !important;
|
| 197 |
font-family: 'Courier Prime', monospace !important;
|
| 198 |
color: var(--text-accent) !important;
|
| 199 |
}}
|
|
|
|
|
|
|
|
|
|
| 200 |
"""
|
| 201 |
|
|
|
|
| 202 |
header_html = """
|
| 203 |
<div style="display: flex; align-items: center; gap: 20px; padding: 20px 0;">
|
| 204 |
+
<div style="font-size: 40px;">ποΈ</div>
|
| 205 |
<div>
|
| 206 |
<h1 style="margin: 0; font-size: 32px; color: var(--text-accent);">HORUS VISION</h1>
|
| 207 |
+
<p style="margin: 0; font-size: 12px; letter-spacing: 2px; opacity: 0.8;">HIEROGLYPHIC TRANSLATION & PRESERVATION</p>
|
| 208 |
</div>
|
| 209 |
</div>
|
| 210 |
"""
|
| 211 |
|
| 212 |
mission_html = """
|
| 213 |
<div class="card">
|
| 214 |
+
<div class="card-title">π MISSION BRIEF</div>
|
| 215 |
<p style="opacity: 0.9; font-size: 14px; line-height: 1.6;">
|
| 216 |
<b>To preserve the past is to save the future.</b><br>
|
| 217 |
This tool uses AI to digitize Ancient Egyptian inscriptions.
|
|
|
|
| 220 |
</div>
|
| 221 |
"""
|
| 222 |
|
|
|
|
| 223 |
guide_instructions_html = """
|
| 224 |
<div class="card" style="border-color: var(--warning-border) !important;">
|
| 225 |
+
<div class="card-title" style="color: var(--warning-border);">π€ CLAUDE DESKTOP CONFIGURATION</div>
|
| 226 |
|
| 227 |
<div class="warning-box">
|
| 228 |
+
<strong style="font-size:14px; display:block; margin-bottom:5px; color: var(--warning-border);">β οΈ STEP 1: IMAGE FOLDER (CRITICAL)</strong>
|
| 229 |
+
Claude Desktop is "sandboxed" (isolated). It cannot see your Desktop or Downloads.<br><br>
|
| 230 |
+
1. Create this EXACT folder: <span class="path-box">C:\\Claude_Work</span><br>
|
| 231 |
+
2. Put your images INSIDE it.<br>
|
| 232 |
+
3. <b>Prompting:</b> "Analyze the image at C:\\Claude_Work\\my_image.jpg"
|
|
|
|
| 233 |
</div>
|
| 234 |
|
| 235 |
<div class="warning-box" style="border-color: var(--text-accent);">
|
| 236 |
+
<strong style="font-size:14px; display:block; margin-bottom:5px; color: var(--text-accent);">π STEP 2: PYTHON PATH</strong>
|
| 237 |
+
The code below assumes Python is at <code>C:\\Python313\\python.exe</code>.<br>
|
| 238 |
+
If your Python is installed elsewhere, you must change this line in the JSON.<br>
|
| 239 |
+
<i>(Run <code>where python</code> in CMD to find your real path).</i>
|
|
|
|
| 240 |
</div>
|
| 241 |
|
| 242 |
+
<div style="margin-top: 15px; opacity: 0.9; font-size: 13px;">
|
| 243 |
+
<b>FINAL STEP:</b> Copy the JSON below into <code>%APPDATA%\\Claude\\claude_desktop_config.json</code> and RESTART Claude.
|
|
|
|
|
|
|
|
|
|
| 244 |
</div>
|
| 245 |
"""
|
| 246 |
|
|
|
|
| 269 |
}"""
|
| 270 |
|
| 271 |
# --- 4. MAIN APP ---
|
| 272 |
+
# NOTE: removed 'theme' argument to prevent errors. Styling is handled by custom_css.
|
| 273 |
+
with gr.Blocks(title="Horus Vision") as demo:
|
| 274 |
+
|
| 275 |
# Inject CSS
|
| 276 |
gr.HTML(f"<style>{custom_css}</style>")
|
| 277 |
|
|
|
|
| 303 |
out_json = gr.JSON(label="JSON Data")
|
| 304 |
gr.HTML('</div>')
|
| 305 |
|
| 306 |
+
# Config Section (Footer)
|
| 307 |
gr.HTML(guide_instructions_html)
|
| 308 |
gr.Code(value=claude_json_content, language="json", label="claude_desktop_config.json", interactive=False, lines=15)
|
| 309 |
gr.HTML("</div>")
|