Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
|
4 |
+
|
5 |
+
# Configure OpenAI API
|
6 |
+
openai.api_key = getenv("GROQ_API_KEY")
|
7 |
+
openai.api_base = "https://api.groq.com/openai/v1"
|
8 |
+
|
9 |
+
# Function to get AI-generated astrology response
|
10 |
+
def get_groq_response(name, dob, time_of_birth, place_of_birth, zodiac_sign, query):
|
11 |
+
try:
|
12 |
+
# Construct the message
|
13 |
+
messages = [
|
14 |
+
{"role": "system", "content": """
|
15 |
+
You are a mystical astrologer. Provide detailed insights about zodiac signs, planetary alignments,
|
16 |
+
and astrological predictions based on the user's inputs. Use a mystical and engaging tone.
|
17 |
+
"""},
|
18 |
+
{"role": "user", "content": f"""
|
19 |
+
Name: {name}
|
20 |
+
Date of Birth: {dob}
|
21 |
+
Time of Birth: {time_of_birth}
|
22 |
+
Place of Birth: {place_of_birth}
|
23 |
+
Zodiac Sign: {zodiac_sign}
|
24 |
+
Query: {query}
|
25 |
+
"""}
|
26 |
+
]
|
27 |
+
# Generate response from the AI
|
28 |
+
response = openai.ChatCompletion.create(
|
29 |
+
model="llama-3.3-70b-versatile",
|
30 |
+
messages=messages
|
31 |
+
)
|
32 |
+
return response.choices[0].message["content"]
|
33 |
+
except Exception as e:
|
34 |
+
return f"Error: {str(e)}"
|
35 |
+
|
36 |
+
# Chatbot function to handle user input and history
|
37 |
+
def chatbot(name, dob, time_of_birth, place_of_birth, zodiac_sign, query, history=[]):
|
38 |
+
# Get the response from the AI
|
39 |
+
bot_response = get_groq_response(name, dob, time_of_birth, place_of_birth, zodiac_sign, query)
|
40 |
+
# Append the conversation to history
|
41 |
+
history.append((f"You: {query}", f"Astrologer: {bot_response}"))
|
42 |
+
return history, history
|
43 |
+
|
44 |
+
# Define Gradio interface
|
45 |
+
chat_interface = gr.Interface(
|
46 |
+
fn=chatbot, # Function to call for interaction
|
47 |
+
inputs=[
|
48 |
+
gr.Textbox(label="Your Name"), # Name input
|
49 |
+
gr.Textbox(label="Date of Birth (e.g., 01-01-2000)"), # DOB input
|
50 |
+
gr.Textbox(label="Time of Birth (e.g., 10:30 AM)"), # Time of Birth input
|
51 |
+
gr.Textbox(label="Place of Birth"), # Place of Birth input
|
52 |
+
gr.Dropdown(
|
53 |
+
label="Your Zodiac Sign",
|
54 |
+
choices=[
|
55 |
+
"Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo",
|
56 |
+
"Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"
|
57 |
+
]
|
58 |
+
), # Dropdown for zodiac sign
|
59 |
+
gr.Textbox(label="Your Question for the Astrologer"), # Query input
|
60 |
+
gr.State(), # State for chat history
|
61 |
+
],
|
62 |
+
outputs=[
|
63 |
+
gr.Chatbot(label="Astrology Chat"), # Chatbot interface for responses
|
64 |
+
gr.State(), # State to maintain chat history
|
65 |
+
],
|
66 |
+
title="Astrology AI Assistant 🌌",
|
67 |
+
description=(
|
68 |
+
"Welcome to your personal Astrology AI Assistant! "
|
69 |
+
"Ask questions about your zodiac sign, horoscope, and planetary alignments. "
|
70 |
+
"Enter your details and let the stars guide you. ✨"
|
71 |
+
),
|
72 |
+
theme="dark" # Optional: Gradio theme customization
|
73 |
+
)
|
74 |
+
|
75 |
+
# Launch the Gradio app
|
76 |
+
if __name__ == "__main__":
|
77 |
+
chat_interface.launch()
|