File size: 14,075 Bytes
b58dcb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
import gradio as gr
import os
from datetime import datetime
import json

# Initialize with sponsor APIs (will be configured with environment variables)
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY", "")
ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY", "")

# Essential Dignities Tables
DOMICILE_RULERS = {
    "Aries": "Mars", "Taurus": "Venus", "Gemini": "Mercury",
    "Cancer": "Moon", "Leo": "Sun", "Virgo": "Mercury",
    "Libra": "Venus", "Scorpio": "Mars", "Sagittarius": "Jupiter",
    "Capricorn": "Saturn", "Aquarius": "Saturn", "Pisces": "Jupiter"
}

EXALTATIONS = {
    "Aries": "Sun", "Taurus": "Moon", "Gemini": None,
    "Cancer": "Jupiter", "Leo": None, "Virgo": "Mercury",
    "Libra": "Saturn", "Scorpio": None, "Sagittarius": None,
    "Capricorn": "Mars", "Aquarius": None, "Pisces": "Venus"
}

TRIPLICITIES = {
    "Fire": {"day": "Sun", "night": "Jupiter", "participating": "Saturn"},
    "Earth": {"day": "Venus", "night": "Moon", "participating": "Mars"},
    "Air": {"day": "Saturn", "night": "Mercury", "participating": "Jupiter"},
    "Water": {"day": "Venus", "night": "Mars", "participating": "Moon"}
}

SIGN_TRIPLICITIES = {
    "Aries": "Fire", "Leo": "Fire", "Sagittarius": "Fire",
    "Taurus": "Earth", "Virgo": "Earth", "Capricorn": "Earth",
    "Gemini": "Air", "Libra": "Air", "Aquarius": "Air",
    "Cancer": "Water", "Scorpio": "Water", "Pisces": "Water"
}

def calculate_profections(birth_year: int, target_year: int) -> dict:
    """Calculate annual profections from Ascendant"""
    age = target_year - birth_year
    profected_house = (age % 12) + 1
    
    return {
        "age": age,
        "profected_house": profected_house,
        "description": f"At age {age}, the profection is to the {profected_house}th house."
    }

def assess_planetary_dignity(planet: str, sign: str, is_day_chart: bool) -> dict:
    """Assess a planet's essential dignity in a given sign"""
    dignity_score = 0
    dignities = []
    
    # Check domicile (+5)
    if DOMICILE_RULERS.get(sign) == planet:
        dignity_score += 5
        dignities.append("Domicile (+5)")
    
    # Check exaltation (+4)
    if EXALTATIONS.get(sign) == planet:
        dignity_score += 4
        dignities.append("Exaltation (+4)")
    
    # Check triplicity (+3)
    triplicity = SIGN_TRIPLICITIES.get(sign)
    if triplicity:
        triplicity_rulers = TRIPLICITIES[triplicity]
        if is_day_chart and triplicity_rulers["day"] == planet:
            dignity_score += 3
            dignities.append("Triplicity Ruler - Day (+3)")
        elif not is_day_chart and triplicity_rulers["night"] == planet:
            dignity_score += 3
            dignities.append("Triplicity Ruler - Night (+3)")
        elif triplicity_rulers["participating"] == planet:
            dignity_score += 3
            dignities.append("Triplicity Ruler - Participating (+3)")
    
    condition = "Strong" if dignity_score >= 4 else "Moderate" if dignity_score > 0 else "Peregrine"
    
    return {
        "planet": planet,
        "sign": sign,
        "dignity_score": dignity_score,
        "dignities": dignities if dignities else ["None (Peregrine)"],
        "condition": condition,
        "sect_considered": "Day Chart" if is_day_chart else "Night Chart"
    }

def calculate_lots(asc_degree: float, sun_degree: float, moon_degree: float, is_day_chart: bool) -> dict:
    """Calculate traditional Hellenistic lots (Fortuna and Spirit)"""
    
    if is_day_chart:
        # Lot of Fortune (day): Asc + Moon - Sun
        fortune = (asc_degree + moon_degree - sun_degree) % 360
    else:
        # Lot of Fortune (night): Asc + Sun - Moon
        fortune = (asc_degree + sun_degree - moon_degree) % 360
    
    if is_day_chart:
        # Lot of Spirit (day): Asc + Sun - Moon
        spirit = (asc_degree + sun_degree - moon_degree) % 360
    else:
        # Lot of Spirit (night): Asc + Moon - Sun
        spirit = (asc_degree + moon_degree - sun_degree) % 360
    
    return {
        "Lot of Fortune": round(fortune, 2),
        "Lot of Spirit": round(spirit, 2),
        "chart_type": "Day Chart" if is_day_chart else "Night Chart"
    }

def research_hellenistic_topic(query: str) -> str:
    """Research assistant for Hellenistic astrology topics"""
    # This will integrate with OpenAI/Anthropic APIs
    # For now, return educational placeholder
    
    topics = {
        "sect": """Sect Theory (Hairesis)
        
According to Vettius Valens (Anthology, Book III), sect distinguishes between day and night charts:

**Day Chart (Diurnal)**: Sun above horizon at birth
- Benefics: Jupiter, Saturn (traditionally)
- Malefics: Mars more difficult than Saturn
- Solar sect planets: Sun, Jupiter, Saturn

**Night Chart (Nocturnal)**: Sun below horizon at birth  
- Benefics: Venus, Moon
- Malefics: Saturn more difficult than Mars
- Lunar sect planets: Moon, Venus, Mars

**Practical Application**:
Ptolemy (Tetrabiblos, Book III) emphasizes that planets in their proper sect are strengthened, while planets contrary to sect are weakened. A day chart with Jupiter angular is far more favorable than Saturn in the same position.

**Source Differences**:
- Valens: More emphasis on sect in time-lord systems
- Ptolemy: More theoretical, applies to natal interpretation
- Dorotheus: Less explicit about sect distinctions
""",
        "profections": """Annual Profections (Epembasis)

The technique advances one house per year of life from the Ascendant.

**Method** (from Valens, Anthology Book IV):
1. Count age in complete years
2. Each year = one house from Ascendant
3. The profected house's ruler becomes the "Lord of the Year"

**Example**:
- Age 0-11 months: 1st house
- Age 1: 2nd house  
- Age 12: Returns to 1st house (first return)
- Age 25: 2nd house (third time)

**Application**:
The Lord of the Year is activated. Transits to that planet are significant. The house profected to shows the area of life emphasis.

**Paulus Alexandrinus** adds that planets in the profected house are also activated that year.
""",
        "bounds": """Egyptian Bounds (Terms)

Each sign is divided into five unequal sections, each ruled by a planet.

**Ptolemy vs Egyptian System**:
Ptolemy (Tetrabiblos I.21) presents his own system, but most practitioners use the older Egyptian bounds found in Valens.

**Significance** (per Valens):
- Bounds = +2 dignity points
- Show more refined planet influence within a sign
- Used in time-lord distributions

**Example - Aries** (Egyptian):
- 0-6°: Jupiter
- 6-12°: Venus
- 12-20°: Mercury
- 20-25°: Mars
- 25-30°: Saturn
"""
    }
    
    # Simple keyword matching
    query_lower = query.lower()
    for keyword, content in topics.items():
        if keyword in query_lower:
            return content
    
    return f"""Research Query: "{query}"

This would integrate with OpenAI/Anthropic to search through:
- Vettius Valens (Anthology)
- Ptolemy (Tetrabiblos)  
- Dorotheus (Carmen Astrologicum)
- Modern synthesizers: Chris Brennan, Demetra George

Please implement API keys to enable full research capabilities.
"""

# Gradio Interface
def create_demo():
    with gr.Blocks(
        theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"),
        title="HERMES - Hellenistic Astrology Research Assistant"
    ) as demo:
        
        gr.Markdown("""
        # 🏛️ HERMES - Hellenistic Ephemeris Research & MCP Educational System
        
        **Ancient Wisdom Meets Modern AI**
        
        Research assistant for traditional Hellenistic astrology combining classical texts 
        (Valens, Ptolemy, Dorotheus) with modern AI agents and MCP architecture.
        
        Built for the MCP 1st Birthday Hackathon using OpenAI, Anthropic, ElevenLabs, and Modal.
        """)
        
        with gr.Tab("📊 Chart Analysis"):
            gr.Markdown("### Essential Dignity Calculator")
            
            with gr.Row():
                planet_input = gr.Dropdown(
                    choices=["Sun", "Moon", "Mercury", "Venus", "Mars", "Jupiter", "Saturn"],
                    label="Planet",
                    value="Sun"
                )
                sign_input = gr.Dropdown(
                    choices=list(DOMICILE_RULERS.keys()),
                    label="Sign",
                    value="Aries"
                )
                sect_input = gr.Checkbox(label="Day Chart (uncheck for Night Chart)", value=True)
            
            dignity_btn = gr.Button("Assess Planetary Condition", variant="primary")
            dignity_output = gr.JSON(label="Dignity Analysis")
            
            dignity_btn.click(
                fn=assess_planetary_dignity,
                inputs=[planet_input, sign_input, sect_input],
                outputs=dignity_output
            )
            
            gr.Markdown("### Lot Calculator")
            with gr.Row():
                asc_deg = gr.Number(label="Ascendant (degrees 0-360)", value=0)
                sun_deg = gr.Number(label="Sun (degrees 0-360)", value=45)
                moon_deg = gr.Number(label="Moon (degrees 0-360)", value=180)
            
            lot_sect = gr.Checkbox(label="Day Chart", value=True)
            lot_btn = gr.Button("Calculate Lots", variant="primary")
            lot_output = gr.JSON(label="Traditional Lots")
            
            lot_btn.click(
                fn=calculate_lots,
                inputs=[asc_deg, sun_deg, moon_deg, lot_sect],
                outputs=lot_output
            )
        
        with gr.Tab("📚 Source Research"):
            gr.Markdown("""
            ### Hellenistic Astrology Knowledge Base
            Ask about traditional techniques and get answers citing ancient sources.
            """)
            
            research_query = gr.Textbox(
                label="Research Question",
                placeholder="e.g., 'Explain sect theory' or 'What are profections?' or 'Describe Egyptian bounds'",
                lines=2
            )
            
            research_btn = gr.Button("Search Ancient Sources", variant="primary")
            research_output = gr.Textbox(label="Research Results", lines=20)
            
            research_btn.click(
                fn=research_hellenistic_topic,
                inputs=research_query,
                outputs=research_output
            )
            
            gr.Markdown("""
            **Sources Referenced:**
            - Vettius Valens (*Anthology*)
            - Ptolemy (*Tetrabiblos*)
            - Dorotheus of Sidon (*Carmen Astrologicum*)
            - Paulus Alexandrinus
            - Modern: Chris Brennan, Demetra George, Robert Schmidt
            """)
        
        with gr.Tab("⏱️ Time-Lord Systems"):
            gr.Markdown("### Annual Profections Calculator")
            
            with gr.Row():
                birth_year_input = gr.Number(label="Birth Year", value=1990)
                target_year_input = gr.Number(label="Target Year", value=2025)
            
            profection_btn = gr.Button("Calculate Profections", variant="primary")
            profection_output = gr.JSON(label="Profection Results")
            
            profection_btn.click(
                fn=calculate_profections,
                inputs=[birth_year_input, target_year_input],
                outputs=profection_output
            )
            
            gr.Markdown("""
            **About Annual Profections:**
            
            An ancient time-lord technique from Hellenistic astrology where each year of life 
            corresponds to a house counted from the Ascendant. The ruler of the profected house 
            becomes the "Lord of the Year."
            
            Used by Valens, Paulus Alexandrinus, and modern practitioners for annual forecasting.
            """)
        
        with gr.Tab("ℹ️ About"):
            gr.Markdown("""
            ## About HERMES
            
            **Hellenistic Ephemeris Research & MCP Educational System**
            
            ### Purpose
            HERMES is a research and teaching tool for traditional Hellenistic astrology, bridging 
            2000-year-old wisdom with modern AI technology.
            
            ### Technical Stack
            - **Agent Framework**: OpenAI GPT-4 + Anthropic Claude
            - **Voice**: ElevenLabs Conversational AI
            - **MCP Server**: Python + Modal (serverless)
            - **UI**: Gradio 6 on HuggingFace Spaces
            - **Compute**: Modal GPU credits
            
            ### Features
            - Essential dignity calculations (domicile, exaltation, triplicity, bounds)
            - Time-lord systems (profections, zodiacal releasing)
            - Traditional lot calculations (Fortune, Spirit)
            - Source research with citations to ancient texts
            - Voice-enabled teaching mode (coming soon)
            
            ### Educational Use Cases
            1. **Students**: Interactive learning of complex traditional techniques
            2. **Researchers**: Rapid comparison across source texts and translations
            3. **Practitioners**: Chart analysis using authentic Hellenistic methods
            
            ### Built For
            MCP 1st Birthday Hackathon (Nov 14-30, 2025)
            
            ### Author
            Created by an astrology author and strategy consultant
            
            ### Credits
            - Hackathon Sponsors: Anthropic, OpenAI, ElevenLabs, Modal, HuggingFace
            - Ancient Sources: Valens, Ptolemy, Dorotheus, Firmicus, Paulus
            - Modern Teachers: Chris Brennan, Demetra George, Robert Schmidt
            
            ---
            
            *Note: This is Phase 1 of development. Full MCP integration, voice agents, 
            and advanced chart calculations coming in subsequent phases.*
            """)
    
    return demo

# Launch the app
if __name__ == "__main__":
    demo = create_demo()
    demo.launch()