File size: 3,114 Bytes
6ce6f34
 
3470e6b
6ce6f34
3886dff
0b0f0e2
6ce6f34
 
 
 
 
3886dff
 
 
 
 
 
 
 
6ce6f34
3886dff
6ce6f34
3886dff
6ce6f34
3886dff
 
 
 
6ce6f34
 
 
3886dff
6ce6f34
3886dff
 
 
 
 
 
6ce6f34
3886dff
 
 
 
 
6ce6f34
3886dff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ce6f34
 
3886dff
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
import gradio as gr
import openai
import os

# Configure OpenAI API for Groq
openai.api_key = os.getenv("API_KEY")
openai.api_base = "https://api.groq.com/openai/v1"

def get_groq_response(name, dob, time_of_birth, place_of_birth, zodiac_sign, query):
    try:
        messages = [
            {"role": "system", "content": f"""
                You are a professional astrologer with mystical wisdom. Analyze the birth chart for {name} born on {dob} 
                at {time_of_birth} in {place_of_birth}. Consider their {zodiac_sign} sun sign and current planetary 
                transits. Provide detailed, personalized insights in a mystical yet clear tone. Include:
                - Key planetary aspects
                - Strengths and challenges
                - Career and relationship guidance
                - Personalized recommendations
            """},
            {"role": "user", "content": query}
        ]
        
        response = openai.ChatCompletion.create(
            model="llama3-70b-8192",  # Corrected Groq model name
            messages=messages,
            temperature=0.7,
            max_tokens=500
        )
        return response.choices[0].message["content"]
    except Exception as e:
        return f"๐Ÿ”ฎ An error occurred: {str(e)} Please try again."

def chatbot(name, dob, time_of_birth, place_of_birth, zodiac_sign, query, chat_history):
    # Initialize chat history if None
    if chat_history is None:
        chat_history = []
    
    # Get AI response
    bot_response = get_groq_response(name, dob, time_of_birth, place_of_birth, zodiac_sign, query)
    
    # Update chat history
    chat_history.append((f"{query}", f"{bot_response}"))
    
    return chat_history, chat_history

# Create Gradio components
with gr.Blocks(theme=gr.themes.Soft(), title="MysticAI Astrologer ๐Ÿ”ฎ") as demo:
    gr.Markdown("# ๐ŸŒŒ MysticAI Astrologer")
    gr.Markdown("Discover your cosmic blueprint with AI-powered astrology insights")
    
    with gr.Row():
        with gr.Column(scale=1):
            name = gr.Textbox(label="Full Name")
            dob = gr.Textbox(label="Date of Birth (DD-MM-YYYY)")
            time_of_birth = gr.Textbox(label="Exact Birth Time (HH:MM AM/PM)")
            place_of_birth = gr.Textbox(label="Birth Place (City, Country)")
            zodiac = gr.Dropdown(
                choices=["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo",
                        "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"],
                label="Sun Sign"
            )
        
        with gr.Column(scale=2):
            chatbot = gr.Chatbot(height=500)
            query = gr.Textbox(label="Your Astrological Question", placeholder="Ask about your career, relationships, or upcoming transits...")
            state = gr.State()
            submit_btn = gr.Button("Consult the Stars โœจ", variant="primary")
    
    submit_btn.click(
        chatbot,
        inputs=[name, dob, time_of_birth, place_of_birth, zodiac, query, state],
        outputs=[chatbot, state]
    )

if __name__ == "__main__":
    demo.launch()