youkii-xr commited on
Commit
f6fedbb
ยท
verified ยท
1 Parent(s): d3ab695

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +136 -29
app.py CHANGED
@@ -5,8 +5,7 @@ import os
5
  from huggingface_hub import hf_hub_download
6
  import numpy as np
7
 
8
- # --- 1. SETUP & MODEL LOADING ---
9
- # Replace with your actual private repo ID
10
  MODEL_REPO = "youkii-xr/hieroglyphic-detection"
11
  MODEL_FILENAME = "best.pt"
12
 
@@ -14,9 +13,6 @@ print(f"Server Status: Public MCP Endpoint Active")
14
  print(f"Security: Model weights are protected (private repo)")
15
 
16
  try:
17
- # ๐Ÿ”’ SECURE DOWNLOAD:
18
- # This uses the 'HF_TOKEN' Secret from Space Settings to authenticate.
19
- # Users of the Space CANNOT see this token or the downloaded file.
20
  model_path = hf_hub_download(
21
  repo_id=MODEL_REPO,
22
  filename=MODEL_FILENAME,
@@ -28,17 +24,10 @@ except Exception as e:
28
  print(f"CRITICAL ERROR: Could not load model. Check HF_TOKEN in Settings. {e}")
29
  model = None
30
 
31
- # --- 2. DETECTION LOGIC ---
32
  def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
33
  """
34
  Analyzes an image to find Egyptian hieroglyphs.
35
-
36
- Args:
37
- image: The image to analyze.
38
- conf_threshold: Confidence level (0.1 to 1.0). Default is 0.25.
39
-
40
- Returns:
41
- A tuple containing the annotated image and a JSON summary of findings.
42
  """
43
  if image is None:
44
  return None, {"error": "No image provided"}
@@ -95,25 +84,143 @@ def detect_hieroglyphs(image: Image.Image, conf_threshold: float = 0.25):
95
  print(f"Inference Error: {e}")
96
  return None, {"error": str(e)}
97
 
98
- # --- 3. INTERFACE ---
99
- demo = gr.Interface(
100
- fn=detect_hieroglyphs,
101
- inputs=[
102
- gr.Image(type="pil", label="Upload Image"),
103
- gr.Number(value=0.25, label="Confidence")
104
- ],
105
- outputs=[
106
- gr.Image(label="Annotated Result"),
107
- gr.JSON(label="Detection Data")
108
- ],
109
- title="Egyptian Hieroglyph MCP Server",
110
- description="Public MCP Endpoint for Hieroglyph Detection. (Model Weights are Private)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  )
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  if __name__ == "__main__":
114
- # Settings to ensure Public access works without 403 errors:
115
- # ssr_mode=False: Disables Server-Side Rendering (helps with API proxies)
116
- # allowed_paths: Grants permission to read temp files uploaded by MCP
117
  demo.launch(
118
  mcp_server=True,
119
  ssr_mode=False,
 
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
 
 
13
  print(f"Security: Model weights are protected (private repo)")
14
 
15
  try:
 
 
 
16
  model_path = hf_hub_download(
17
  repo_id=MODEL_REPO,
18
  filename=MODEL_FILENAME,
 
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"}
 
84
  print(f"Inference Error: {e}")
85
  return None, {"error": str(e)}
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 */
104
+ @keyframes goldenPulse {
105
+ 0% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.7); transform: scale(1); }
106
+ 50% { box-shadow: 0 0 0 10px rgba(212, 175, 55, 0); transform: scale(1.02); }
107
+ 100% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0); transform: scale(1); }
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;
117
+ animation: goldenPulse 2s infinite;
118
+ transition: all 0.3s ease;
119
+ }
120
+
121
+ #magic-btn:hover {
122
+ animation: none;
123
+ transform: translateY(-2px);
124
+ box-shadow: 0 5px 15px rgba(139, 69, 19, 0.4);
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": {
150
+ "hieroglyph-detector": {
151
+ "command": "uv",
152
+ "args": [
153
+ "python",
154
+ "client.py"
155
+ ],
156
+ "env": {
157
+ "GRADIO_SERVER_URL": "YOUR_SPACE_URL_HERE"
158
+ }
159
+ }
160
+ }
161
+ }
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__":
 
 
 
224
  demo.launch(
225
  mcp_server=True,
226
  ssr_mode=False,