Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,25 +5,30 @@ import os
|
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
import numpy as np
|
| 7 |
|
| 8 |
-
# --- 1. SETUP & MODEL LOADING
|
| 9 |
MODEL_REPO = "youkii-xr/hieroglyphic-detection"
|
| 10 |
MODEL_FILENAME = "best.pt"
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
try:
|
|
|
|
| 13 |
model_path = hf_hub_download(
|
| 14 |
repo_id=MODEL_REPO,
|
| 15 |
filename=MODEL_FILENAME,
|
| 16 |
token=os.environ.get("HF_TOKEN")
|
| 17 |
)
|
| 18 |
model = YOLO(model_path)
|
|
|
|
| 19 |
except Exception as e:
|
| 20 |
print(f"Error: {e}")
|
| 21 |
model = None
|
| 22 |
|
| 23 |
-
# --- 2. DETECTION LOGIC
|
| 24 |
def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
|
| 25 |
if image is None: return None, None
|
| 26 |
-
if model is None: return None,
|
| 27 |
|
| 28 |
try:
|
| 29 |
results = model.predict(source=image, conf=conf_threshold, iou=0.45, imgsz=640, verbose=False, device='cpu', max_det=300)
|
|
@@ -57,7 +62,6 @@ def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
|
|
| 57 |
|
| 58 |
# --- 3. UI/UX: THE EGYPTIAN NIGHT STYLE ---
|
| 59 |
|
| 60 |
-
# This CSS mimics the VoiceKit structure but swaps Purple/Indigo for Lapis/Gold
|
| 61 |
custom_css = """
|
| 62 |
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&display=swap');
|
| 63 |
|
|
@@ -71,7 +75,7 @@ custom_css = """
|
|
| 71 |
|
| 72 |
body, .gradio-container {
|
| 73 |
background: radial-gradient(circle at 50% 0%, #1a1f35 0%, #050510 100%) !important;
|
| 74 |
-
font-family: 'Cinzel', serif !important;
|
| 75 |
}
|
| 76 |
|
| 77 |
/* --- THE GLASS CARDS --- */
|
|
@@ -87,7 +91,7 @@ body, .gradio-container {
|
|
| 87 |
.card-title {
|
| 88 |
font-size: 18px;
|
| 89 |
font-weight: 700;
|
| 90 |
-
color: #d4af37;
|
| 91 |
text-transform: uppercase;
|
| 92 |
letter-spacing: 2px;
|
| 93 |
margin-bottom: 20px;
|
|
@@ -123,11 +127,10 @@ body, .gradio-container {
|
|
| 123 |
font-size: 13px;
|
| 124 |
line-height: 1.6;
|
| 125 |
}
|
| 126 |
-
.json-key { color: #7aa2f7; }
|
| 127 |
-
.json-string { color: #e0af68; }
|
| 128 |
|
| 129 |
/* --- BUTTONS --- */
|
| 130 |
-
/* The "Action" Button */
|
| 131 |
button.primary-btn {
|
| 132 |
background: linear-gradient(135deg, #b8860b 0%, #d4af37 100%) !important;
|
| 133 |
border: 1px solid #ffd700 !important;
|
|
@@ -144,8 +147,7 @@ button.primary-btn:hover {
|
|
| 144 |
box-shadow: 0 0 25px rgba(212, 175, 55, 0.6);
|
| 145 |
}
|
| 146 |
|
| 147 |
-
/* ---
|
| 148 |
-
/* Transparent backgrounds for images/json to blend into cards */
|
| 149 |
.gradio-image, .gradio-json {
|
| 150 |
background: transparent !important;
|
| 151 |
border: none !important;
|
|
@@ -172,7 +174,6 @@ header_html = """
|
|
| 172 |
</div>
|
| 173 |
"""
|
| 174 |
|
| 175 |
-
# HTML for the Claude Config "Terminal"
|
| 176 |
terminal_html = """
|
| 177 |
<div class="card">
|
| 178 |
<div class="card-title">โก CLAUDE DESKTOP CONFIG</div>
|
|
@@ -196,51 +197,49 @@ terminal_html = """
|
|
| 196 |
"""
|
| 197 |
|
| 198 |
# --- 4. APP ASSEMBLY ---
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
# 1. Header Injection
|
| 202 |
gr.HTML(header_html)
|
| 203 |
|
| 204 |
# 2. Top Row: Info & Config
|
| 205 |
with gr.Row():
|
| 206 |
-
# Left: The Model Info Card
|
| 207 |
with gr.Column(scale=1):
|
| 208 |
gr.HTML("""
|
| 209 |
<div class="card" style="height: 100%;">
|
| 210 |
<div class="card-title">๐ MISSION BRIEF</div>
|
| 211 |
<p style="color: #ccc; line-height: 1.6;">
|
| 212 |
-
This system utilizes the YOLOv8 architecture to detect and classify Gardiner codes
|
| 213 |
<br><br>
|
| 214 |
<span style="color: #d4af37;">> Model:</span> YOLOv8 Custom<br>
|
| 215 |
-
<span style="color: #d4af37;">> Weights:</span> Private (Secure)<br>
|
| 216 |
<span style="color: #d4af37;">> Security:</span> MCP Standard
|
| 217 |
</p>
|
| 218 |
</div>
|
| 219 |
""")
|
| 220 |
|
| 221 |
-
# Right: The Terminal Card
|
| 222 |
with gr.Column(scale=1):
|
| 223 |
gr.HTML(terminal_html)
|
| 224 |
|
| 225 |
-
# 3. Main Detector Area
|
| 226 |
-
gr.HTML("<br>")
|
| 227 |
|
| 228 |
with gr.Row():
|
| 229 |
with gr.Column():
|
| 230 |
-
# We wrap the input area in a HTML card wrapper logic
|
| 231 |
gr.HTML('<div class="card"> <div class="card-title">๐๏ธ INPUT SOURCE</div>')
|
| 232 |
img_input = gr.Image(type="pil", label="Upload Papyrus", sources=["upload", "clipboard", "webcam"], elem_classes="gradio-image")
|
| 233 |
conf_slider = gr.Slider(0.1, 1.0, 0.25, step=0.05, label="Detection Confidence")
|
| 234 |
-
|
| 235 |
-
# The Golden Button
|
| 236 |
analyze_btn = gr.Button("๐ฎ DECIPHER SYMBOLS", elem_classes="primary-btn")
|
| 237 |
-
gr.HTML('</div>')
|
| 238 |
|
| 239 |
with gr.Column():
|
| 240 |
gr.HTML('<div class="card"> <div class="card-title">๐ DECODED ARTIFACT</div>')
|
| 241 |
img_output = gr.Image(label="Annotated Result", interactive=False, elem_classes="gradio-image")
|
| 242 |
json_output = gr.JSON(label="Glyph Data", elem_classes="gradio-json")
|
| 243 |
-
gr.HTML('</div>')
|
| 244 |
|
| 245 |
# 4. Wiring
|
| 246 |
analyze_btn.click(
|
|
|
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
import numpy as np
|
| 7 |
|
| 8 |
+
# --- 1. SETUP & MODEL LOADING ---
|
| 9 |
MODEL_REPO = "youkii-xr/hieroglyphic-detection"
|
| 10 |
MODEL_FILENAME = "best.pt"
|
| 11 |
|
| 12 |
+
# Fix for the Ultralytics config warning in containers
|
| 13 |
+
os.environ["YOLO_CONFIG_DIR"] = "/tmp/Ultralytics"
|
| 14 |
+
|
| 15 |
try:
|
| 16 |
+
print("System: Downloading model weights...")
|
| 17 |
model_path = hf_hub_download(
|
| 18 |
repo_id=MODEL_REPO,
|
| 19 |
filename=MODEL_FILENAME,
|
| 20 |
token=os.environ.get("HF_TOKEN")
|
| 21 |
)
|
| 22 |
model = YOLO(model_path)
|
| 23 |
+
print("System: Model loaded successfully.")
|
| 24 |
except Exception as e:
|
| 25 |
print(f"Error: {e}")
|
| 26 |
model = None
|
| 27 |
|
| 28 |
+
# --- 2. DETECTION LOGIC ---
|
| 29 |
def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
|
| 30 |
if image is None: return None, None
|
| 31 |
+
if model is None: return None, {"error": "Model failed to load"}
|
| 32 |
|
| 33 |
try:
|
| 34 |
results = model.predict(source=image, conf=conf_threshold, iou=0.45, imgsz=640, verbose=False, device='cpu', max_det=300)
|
|
|
|
| 62 |
|
| 63 |
# --- 3. UI/UX: THE EGYPTIAN NIGHT STYLE ---
|
| 64 |
|
|
|
|
| 65 |
custom_css = """
|
| 66 |
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&display=swap');
|
| 67 |
|
|
|
|
| 75 |
|
| 76 |
body, .gradio-container {
|
| 77 |
background: radial-gradient(circle at 50% 0%, #1a1f35 0%, #050510 100%) !important;
|
| 78 |
+
font-family: 'Cinzel', serif !important;
|
| 79 |
}
|
| 80 |
|
| 81 |
/* --- THE GLASS CARDS --- */
|
|
|
|
| 91 |
.card-title {
|
| 92 |
font-size: 18px;
|
| 93 |
font-weight: 700;
|
| 94 |
+
color: #d4af37;
|
| 95 |
text-transform: uppercase;
|
| 96 |
letter-spacing: 2px;
|
| 97 |
margin-bottom: 20px;
|
|
|
|
| 127 |
font-size: 13px;
|
| 128 |
line-height: 1.6;
|
| 129 |
}
|
| 130 |
+
.json-key { color: #7aa2f7; }
|
| 131 |
+
.json-string { color: #e0af68; }
|
| 132 |
|
| 133 |
/* --- BUTTONS --- */
|
|
|
|
| 134 |
button.primary-btn {
|
| 135 |
background: linear-gradient(135deg, #b8860b 0%, #d4af37 100%) !important;
|
| 136 |
border: 1px solid #ffd700 !important;
|
|
|
|
| 147 |
box-shadow: 0 0 25px rgba(212, 175, 55, 0.6);
|
| 148 |
}
|
| 149 |
|
| 150 |
+
/* --- ELEMENT VISIBILITY --- */
|
|
|
|
| 151 |
.gradio-image, .gradio-json {
|
| 152 |
background: transparent !important;
|
| 153 |
border: none !important;
|
|
|
|
| 174 |
</div>
|
| 175 |
"""
|
| 176 |
|
|
|
|
| 177 |
terminal_html = """
|
| 178 |
<div class="card">
|
| 179 |
<div class="card-title">โก CLAUDE DESKTOP CONFIG</div>
|
|
|
|
| 197 |
"""
|
| 198 |
|
| 199 |
# --- 4. APP ASSEMBLY ---
|
| 200 |
+
# FIX: Removed 'css' argument here. We inject it via gr.HTML below.
|
| 201 |
+
with gr.Blocks(title="Horus Vision") as demo:
|
| 202 |
+
|
| 203 |
+
# FIX: Inject CSS directly into the HTML. This works on ALL Gradio versions.
|
| 204 |
+
gr.HTML(f"<style>{custom_css}</style>")
|
| 205 |
|
| 206 |
# 1. Header Injection
|
| 207 |
gr.HTML(header_html)
|
| 208 |
|
| 209 |
# 2. Top Row: Info & Config
|
| 210 |
with gr.Row():
|
|
|
|
| 211 |
with gr.Column(scale=1):
|
| 212 |
gr.HTML("""
|
| 213 |
<div class="card" style="height: 100%;">
|
| 214 |
<div class="card-title">๐ MISSION BRIEF</div>
|
| 215 |
<p style="color: #ccc; line-height: 1.6;">
|
| 216 |
+
This system utilizes the YOLOv8 architecture to detect and classify Gardiner codes.
|
| 217 |
<br><br>
|
| 218 |
<span style="color: #d4af37;">> Model:</span> YOLOv8 Custom<br>
|
|
|
|
| 219 |
<span style="color: #d4af37;">> Security:</span> MCP Standard
|
| 220 |
</p>
|
| 221 |
</div>
|
| 222 |
""")
|
| 223 |
|
|
|
|
| 224 |
with gr.Column(scale=1):
|
| 225 |
gr.HTML(terminal_html)
|
| 226 |
|
| 227 |
+
# 3. Main Detector Area
|
| 228 |
+
gr.HTML("<br>")
|
| 229 |
|
| 230 |
with gr.Row():
|
| 231 |
with gr.Column():
|
|
|
|
| 232 |
gr.HTML('<div class="card"> <div class="card-title">๐๏ธ INPUT SOURCE</div>')
|
| 233 |
img_input = gr.Image(type="pil", label="Upload Papyrus", sources=["upload", "clipboard", "webcam"], elem_classes="gradio-image")
|
| 234 |
conf_slider = gr.Slider(0.1, 1.0, 0.25, step=0.05, label="Detection Confidence")
|
|
|
|
|
|
|
| 235 |
analyze_btn = gr.Button("๐ฎ DECIPHER SYMBOLS", elem_classes="primary-btn")
|
| 236 |
+
gr.HTML('</div>')
|
| 237 |
|
| 238 |
with gr.Column():
|
| 239 |
gr.HTML('<div class="card"> <div class="card-title">๐ DECODED ARTIFACT</div>')
|
| 240 |
img_output = gr.Image(label="Annotated Result", interactive=False, elem_classes="gradio-image")
|
| 241 |
json_output = gr.JSON(label="Glyph Data", elem_classes="gradio-json")
|
| 242 |
+
gr.HTML('</div>')
|
| 243 |
|
| 244 |
# 4. Wiring
|
| 245 |
analyze_btn.click(
|