File size: 5,248 Bytes
c6be59e
20b5230
c6be59e
a977c80
ff38c47
20b5230
 
 
c6be59e
20b5230
 
 
 
c6be59e
20b5230
ab9a2de
20b5230
ab9a2de
20b5230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c6be59e
 
20b5230
 
 
 
 
 
 
 
 
 
 
 
 
c6be59e
6f3a92d
d18c9ce
 
 
 
 
f607560
d18c9ce
 
20b5230
 
c2eb641
c6be59e
20b5230
c6be59e
61cfe40
c6be59e
20b5230
61cfe40
 
 
 
c6be59e
61cfe40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a977c80
20b5230
da9b270
20b5230
c6be59e
61cfe40
 
 
6f3a92d
20b5230
 
 
ab9a2de
20b5230
 
8fe9248
20b5230
c2eb641
20b5230
a977c80
8fe9248
20b5230
a977c80
ff38c47
c2eb641
5fd4def
c6be59e
c2eb641
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
import streamlit as st
from kerykeion import AstrologicalSubject, KerykeionChartSVG, SynastryAspects
from kerykeion.report import Report
import sys
import os
import re
import google.generativeai as genai
from io import StringIO

# Function to clean text for Google GEMINI
def clean_text(text):
    cleaned_text = re.sub(r'[^a-zA-Z0-9\s]', '', text)
    return cleaned_text

# Function to generate response from Google GEMINI
def generate_response(cleaned_input, model):
    try:
        response = model.generate_content(cleaned_input, stream=True)
        full_response = ""
        for chunk in response:
            full_response += chunk.text
        return full_response
    except Exception as e:
        error_message = str(e)
        st.error(f"Error: {error_message}")
        return None

# Function to get user input for astrological charts, with unique keys
def get_user_input(key_suffix=""):
    name = st.text_input(f"Person's name {key_suffix}:", key=f"name{key_suffix}")
    year = st.number_input(f"Year of birth {key_suffix}:", min_value=1900, max_value=2099, key=f"year{key_suffix}")
    month = st.number_input(f"Month of birth {key_suffix} (1-12):", min_value=1, max_value=12, key=f"month{key_suffix}")
    day = st.number_input(f"Day of birth {key_suffix} (1-31):", min_value=1, max_value=31, key=f"day{key_suffix}")
    hour = st.number_input(f"Hour of birth {key_suffix} (0-23):", min_value=0, max_value=23, key=f"hour{key_suffix}")
    minute = st.number_input(f"Minute of birth {key_suffix} (0-59):", min_value=0, max_value=59, key=f"minute{key_suffix}")
    location = st.text_input(f"Place of birth {key_suffix}:", key=f"location{key_suffix}")
    zodiac_type = st.selectbox(f"Zodiac type {key_suffix}", ["Tropic", "Sidereal"], key=f"zodiac_type{key_suffix}").capitalize()
    return name, year, month, day, hour, minute, location, zodiac_type

class SynastryAspectsWithRelevant(SynastryAspects):
    @property
    def relevant_aspects(self):
        relevant_aspects_list = []
        
        # Add your logic to calculate relevant aspects here
        for aspect in self.all_aspects:
            # Customize this condition based on your criteria
            if aspect["orbit"] < 10:
                relevant_aspects_list.append(aspect)
        
        return relevant_aspects_list

def main():
    st.title("Astrological Chart Oracle")
    st.markdown(
    """
    
    **Author:** Cha0smagick the Technowizard
    **Created for the blog:** [El Rincon Paranormal](https://elrinconparanormal.blogspot.com)  
    **Project's main page:** [Cha0smagick's Astrological oracle](https://elrinconparanormal.blogspot.com/2023/12/Free%20Astrological%20Chart%20Generator%20Tool%20Online.html)
    """
)

    # Astrological chart generation
    st.write("Enter information for the first person:")
    name1, year1, month1, day1, hour1, minute1, location1, zodiac_type1 = get_user_input()
    person1 = AstrologicalSubject(name1, year1, month1, day1, hour1, minute1, location1, zodiac_type=zodiac_type1)
    
    chart_type = st.selectbox("Chart type", ["Natal", "Synastry", "Transit"]).capitalize()

    report_content = ""
    if chart_type in ["Synastry", "Transit"]:
        st.write("Enter information for the second person:")
        name2, year2, month2, day2, hour2, minute2, location2, zodiac_type2 = get_user_input(" - Person 2")
        person2 = AstrologicalSubject(name2, year2, month2, day2, hour2, minute2, location2, zodiac_type=zodiac_type2)

        if chart_type == "Synastry":
            synastry = SynastryAspectsWithRelevant(person1, person2)
            aspect_list = synastry.relevant_aspects
            report_content = "\n".join([str(aspect) for aspect in aspect_list])
        else:  # Transit
            # Display a message for the "Transit" option
            st.write("Feature in development")
    else:
        # Generate and capture the astrological report for person1
        old_stdout = sys.stdout
        sys.stdout = mystdout = StringIO()
        user_report = Report(person1)
        user_report.print_report()
        sys.stdout = old_stdout
        report_content = mystdout.getvalue()

    # Google GEMINI integration
    genai.configure(api_key='AIzaSyAkbU3CsZ-xmOhRF1XfdlVxasRtt9gdRMk')  # Replace with your Gemini API key
    model = genai.GenerativeModel('gemini-pro')

    # st.write("Context Information:")
    # st.write(report_content)

    st.write("Ask the Astrological Oracle using your astrological chart information as context")
    user_query = st.text_input("Your question:")
    if st.button("Get Astrological Insight"):
        cleaned_input = clean_text(report_content + " " + user_query)
        response = generate_response(cleaned_input, model)
        if response:
            st.success(response)

    # Display the astrological chart
    st.markdown("## Generated Astrological Chart")
    script_dir = os.path.dirname(os.path.abspath(__file__))
    svg_files = [f for f in os.listdir(script_dir) if f.endswith(".svg")]
    if svg_files:
        svg_file = svg_files[0]
        st.image(os.path.join(script_dir, svg_file), use_container_width=True)
    else:
        st.write("No SVG files found in the current directory.")

if __name__ == "__main__":
    main()