File size: 3,032 Bytes
6ce6f34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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


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

# Function to get AI-generated astrology response
def get_groq_response(name, dob, time_of_birth, place_of_birth, zodiac_sign, query):
    try:
        # Construct the message
        messages = [
            {"role": "system", "content": """
                You are a mystical astrologer. Provide detailed insights about zodiac signs, planetary alignments, 
                and astrological predictions based on the user's inputs. Use a mystical and engaging tone.
            """},
            {"role": "user", "content": f"""
                Name: {name}
                Date of Birth: {dob}
                Time of Birth: {time_of_birth}
                Place of Birth: {place_of_birth}
                Zodiac Sign: {zodiac_sign}
                Query: {query}
            """}
        ]
        # Generate response from the AI
        response = openai.ChatCompletion.create(
            model="llama-3.3-70b-versatile",
            messages=messages
        )
        return response.choices[0].message["content"]
    except Exception as e:
        return f"Error: {str(e)}"

# Chatbot function to handle user input and history
def chatbot(name, dob, time_of_birth, place_of_birth, zodiac_sign, query, history=[]):
    # Get the response from the AI
    bot_response = get_groq_response(name, dob, time_of_birth, place_of_birth, zodiac_sign, query)
    # Append the conversation to history
    history.append((f"You: {query}", f"Astrologer: {bot_response}"))
    return history, history

# Define Gradio interface
chat_interface = gr.Interface(
    fn=chatbot,  # Function to call for interaction
    inputs=[
        gr.Textbox(label="Your Name"),  # Name input
        gr.Textbox(label="Date of Birth (e.g., 01-01-2000)"),  # DOB input
        gr.Textbox(label="Time of Birth (e.g., 10:30 AM)"),  # Time of Birth input
        gr.Textbox(label="Place of Birth"),  # Place of Birth input
        gr.Dropdown(
            label="Your Zodiac Sign",
            choices=[
                "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo",
                "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"
            ]
        ),  # Dropdown for zodiac sign
        gr.Textbox(label="Your Question for the Astrologer"),  # Query input
        gr.State(),  # State for chat history
    ],
    outputs=[
        gr.Chatbot(label="Astrology Chat"),  # Chatbot interface for responses
        gr.State(),  # State to maintain chat history
    ],
    title="Astrology AI Assistant 🌌",
    description=(
        "Welcome to your personal Astrology AI Assistant! "
        "Ask questions about your zodiac sign, horoscope, and planetary alignments. "
        "Enter your details and let the stars guide you. ✨"
    ),
    theme="dark"  # Optional: Gradio theme customization
)

# Launch the Gradio app
if __name__ == "__main__":
    chat_interface.launch()