youkii-xr commited on
Commit
11743be
ยท
verified ยท
1 Parent(s): 4727fcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -58
app.py CHANGED
@@ -5,7 +5,7 @@ import os
5
  from huggingface_hub import hf_hub_download
6
  import numpy as np
7
 
8
- # --- 1. SETUP & MODEL LOADING (UNCHANGED) ---
9
  MODEL_REPO = "youkii-xr/hieroglyphic-detection"
10
  MODEL_FILENAME = "best.pt"
11
 
@@ -24,11 +24,8 @@ except Exception as e:
24
  print(f"CRITICAL ERROR: Could not load model. Check HF_TOKEN in Settings. {e}")
25
  model = None
26
 
27
- # --- 2. DETECTION LOGIC (UNCHANGED) ---
28
  def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
29
- """
30
- Analyzes an image to find Egyptian hieroglyphs.
31
- """
32
  if image is None:
33
  return None, {"error": "No image provided"}
34
 
@@ -36,7 +33,6 @@ def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
36
  return None, {"error": "Server Error: Model not loaded."}
37
 
38
  try:
39
- # Run Inference
40
  results = model.predict(
41
  source=image,
42
  conf=conf_threshold,
@@ -47,11 +43,9 @@ def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
47
  max_det=300
48
  )
49
 
50
- # 1. Generate Visual Output (RGB Image)
51
  annotated_array = results[0].plot()
52
  annotated_image = Image.fromarray(annotated_array[..., ::-1])
53
 
54
- # 2. Generate Data Output (JSON)
55
  detections = []
56
  gardiner_counts = {}
57
 
@@ -86,18 +80,17 @@ def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
86
 
87
  # --- 3. UI/UX CONFIGURATION ---
88
 
89
- # A. Custom CSS for Animations and Fonts
90
- # Imports 'Cinzel' font for that ancient feel and defines a pulsing gold button
91
  custom_css = """
92
  @import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&display=swap');
93
 
 
94
  body, .gradio-container {
95
- background-color: #fdf6e3; /* Light Papyrus */
96
  }
97
 
98
- h1, h2, h3 {
99
  font-family: 'Cinzel', serif !important;
100
- color: #8b4513 !important; /* SaddleBrown */
101
  }
102
 
103
  /* The Magic Button Animation */
@@ -108,9 +101,9 @@ h1, h2, h3 {
108
  }
109
 
110
  #magic-btn {
111
- background: linear-gradient(135deg, #b8860b 0%, #d4af37 100%); /* Gold Gradient */
112
  border: 1px solid #8b4513;
113
- color: white;
114
  font-family: 'Cinzel', serif;
115
  font-weight: bold;
116
  font-size: 1.2em;
@@ -125,25 +118,11 @@ h1, h2, h3 {
125
  }
126
 
127
  .json-output {
128
- background-color: #fff8dc; /* Cornsilk */
129
  border: 1px solid #d4af37;
130
  }
131
  """
132
 
133
- # B. Custom Theme (Sand, Gold, Lapis)
134
- theme = gr.themes.Soft(
135
- primary_hue="amber",
136
- secondary_hue="slate",
137
- neutral_hue="stone",
138
- ).set(
139
- body_background_fill="#fdf6e3",
140
- block_background_fill="#ffffff",
141
- block_border_color="#d4af37", # Gold borders
142
- button_primary_background_fill="#d4af37",
143
- button_primary_text_color="white",
144
- )
145
-
146
- # C. Claude Configuration JSON Generator
147
  claude_config_content = """
148
  {
149
  "mcpServers": {
@@ -162,62 +141,40 @@ claude_config_content = """
162
  """
163
 
164
  # --- 4. BUILD THE APP WITH BLOCKS ---
165
- with gr.Blocks(theme=theme, css=custom_css, title="Horus Vision") as demo:
 
166
 
167
- # Header Area
168
  with gr.Row():
169
  with gr.Column(scale=1):
170
  gr.Markdown("""
171
  # ๐Ÿ‘๏ธ Horus Vision
172
- ### AI Hieroglyphic Decoder & Classifier
173
  """)
174
  with gr.Column(scale=3):
175
  gr.Markdown("""
176
  > *"The eye sees all."* Upload an image of Egyptian text.
177
- > This AI identifies Gardiner codes using the YOLO architecture.
178
  """)
179
 
180
- # Main Tabs
181
  with gr.Tabs():
182
-
183
- # TAB 1: The Detector
184
  with gr.TabItem("๐Ÿ” Decoder"):
185
  with gr.Row():
186
- # Left Column: Inputs
187
  with gr.Column():
188
- img_input = gr.Image(type="pil", label="Upload Papyrus/Image", sources=["upload", "clipboard"])
189
- conf_slider = gr.Slider(minimum=0.1, maximum=1.0, value=0.25, step=0.05, label="Confidence Threshold")
190
-
191
- # The Animated Button
192
  analyze_btn = gr.Button("๐Ÿ”ฎ Decipher Symbols", elem_id="magic-btn", variant="primary")
193
-
194
- # Right Column: Outputs
195
  with gr.Column():
196
  img_output = gr.Image(label="Annotated Result", interactive=False)
197
  json_output = gr.JSON(label="Glyph Data", elem_classes="json-output")
198
 
199
- # Event Listener
200
  analyze_btn.click(
201
  fn=detect_hieroglyphs,
202
  inputs=[img_input, conf_slider],
203
  outputs=[img_output, json_output]
204
  )
205
 
206
- # TAB 2: Claude Desktop Config
207
  with gr.TabItem("๐Ÿค– Connect to Claude"):
208
  gr.Markdown("### MCP Server Configuration")
209
- gr.Markdown("Copy the JSON below into your Claude Desktop config file to use this model directly within Claude.")
210
-
211
- gr.Code(
212
- value=claude_config_content,
213
- language="json",
214
- label="claude_desktop_config.json",
215
- interactive=False
216
- )
217
-
218
- # Footer
219
- gr.Markdown("---")
220
- gr.Markdown(f"*Powered by YOLOv8 | Model: {MODEL_REPO} | Private Weights Active*")
221
 
222
  # --- 5. LAUNCH ---
223
  if __name__ == "__main__":
 
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
 
 
24
  print(f"CRITICAL ERROR: Could not load model. Check HF_TOKEN in Settings. {e}")
25
  model = None
26
 
27
+ # --- 2. DETECTION LOGIC ---
28
  def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
 
 
 
29
  if image is None:
30
  return None, {"error": "No image provided"}
31
 
 
33
  return None, {"error": "Server Error: Model not loaded."}
34
 
35
  try:
 
36
  results = model.predict(
37
  source=image,
38
  conf=conf_threshold,
 
43
  max_det=300
44
  )
45
 
 
46
  annotated_array = results[0].plot()
47
  annotated_image = Image.fromarray(annotated_array[..., ::-1])
48
 
 
49
  detections = []
50
  gardiner_counts = {}
51
 
 
80
 
81
  # --- 3. UI/UX CONFIGURATION ---
82
 
 
 
83
  custom_css = """
84
  @import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&display=swap');
85
 
86
+ /* Force background color via CSS since Theme is disabled */
87
  body, .gradio-container {
88
+ background-color: #fdf6e3 !important;
89
  }
90
 
91
+ h1, h2, h3, span {
92
  font-family: 'Cinzel', serif !important;
93
+ color: #8b4513 !important;
94
  }
95
 
96
  /* The Magic Button Animation */
 
101
  }
102
 
103
  #magic-btn {
104
+ background: linear-gradient(135deg, #b8860b 0%, #d4af37 100%);
105
  border: 1px solid #8b4513;
106
+ color: white !important;
107
  font-family: 'Cinzel', serif;
108
  font-weight: bold;
109
  font-size: 1.2em;
 
118
  }
119
 
120
  .json-output {
121
+ background-color: #fff8dc;
122
  border: 1px solid #d4af37;
123
  }
124
  """
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  claude_config_content = """
127
  {
128
  "mcpServers": {
 
141
  """
142
 
143
  # --- 4. BUILD THE APP WITH BLOCKS ---
144
+ # FIX: Removed 'theme' argument to prevent TypeError on older Gradio versions
145
+ with gr.Blocks(css=custom_css, title="Horus Vision") as demo:
146
 
 
147
  with gr.Row():
148
  with gr.Column(scale=1):
149
  gr.Markdown("""
150
  # ๐Ÿ‘๏ธ Horus Vision
151
+ ### AI Hieroglyphic Decoder
152
  """)
153
  with gr.Column(scale=3):
154
  gr.Markdown("""
155
  > *"The eye sees all."* Upload an image of Egyptian text.
 
156
  """)
157
 
 
158
  with gr.Tabs():
 
 
159
  with gr.TabItem("๐Ÿ” Decoder"):
160
  with gr.Row():
 
161
  with gr.Column():
162
+ img_input = gr.Image(type="pil", label="Upload Papyrus", sources=["upload", "clipboard"])
163
+ conf_slider = gr.Slider(minimum=0.1, maximum=1.0, value=0.25, label="Confidence")
 
 
164
  analyze_btn = gr.Button("๐Ÿ”ฎ Decipher Symbols", elem_id="magic-btn", variant="primary")
 
 
165
  with gr.Column():
166
  img_output = gr.Image(label="Annotated Result", interactive=False)
167
  json_output = gr.JSON(label="Glyph Data", elem_classes="json-output")
168
 
 
169
  analyze_btn.click(
170
  fn=detect_hieroglyphs,
171
  inputs=[img_input, conf_slider],
172
  outputs=[img_output, json_output]
173
  )
174
 
 
175
  with gr.TabItem("๐Ÿค– Connect to Claude"):
176
  gr.Markdown("### MCP Server Configuration")
177
+ gr.Code(value=claude_config_content, language="json", label="claude_desktop_config.json", interactive=False)
 
 
 
 
 
 
 
 
 
 
 
178
 
179
  # --- 5. LAUNCH ---
180
  if __name__ == "__main__":