Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,10 @@ import openai
|
|
3 |
import os
|
4 |
|
5 |
# Configure OpenAI API for Groq
|
6 |
-
openai.api_key = os.getenv("
|
7 |
openai.api_base = "https://api.groq.com/openai/v1"
|
8 |
|
|
|
9 |
def get_groq_response(name, dob, time_of_birth, place_of_birth, zodiac_sign, query):
|
10 |
try:
|
11 |
system_prompt = f"""You are Master Celestia, an AI astrologer. Analyze this birth chart:
|
@@ -36,7 +37,7 @@ def get_groq_response(name, dob, time_of_birth, place_of_birth, zodiac_sign, que
|
|
36 |
except Exception as e:
|
37 |
return f"Error: {str(e)}"
|
38 |
|
39 |
-
#
|
40 |
def handle_chat(name, dob, time_of_birth, place_of_birth, zodiac, query, chat_history):
|
41 |
chat_history = chat_history or []
|
42 |
|
@@ -47,6 +48,7 @@ def handle_chat(name, dob, time_of_birth, place_of_birth, zodiac, query, chat_hi
|
|
47 |
|
48 |
return chat_history, chat_history
|
49 |
|
|
|
50 |
with gr.Blocks(theme=gr.themes.Soft(), title="Astro Guide") as demo:
|
51 |
gr.Markdown("# π Astro Guide - AI Astrologer")
|
52 |
|
@@ -58,21 +60,20 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Astro Guide") as demo:
|
|
58 |
place_of_birth = gr.Textbox(label="Birth Place")
|
59 |
zodiac = gr.Dropdown(
|
60 |
choices=["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo",
|
61 |
-
|
62 |
label="Sun Sign"
|
63 |
)
|
64 |
|
65 |
with gr.Column(scale=2):
|
66 |
-
# Renamed chatbot component
|
67 |
chat_interface = gr.Chatbot(height=500)
|
68 |
query = gr.Textbox(label="Your Question")
|
69 |
state = gr.State()
|
70 |
submit_btn = gr.Button("Ask the Stars", variant="primary")
|
71 |
clear_btn = gr.Button("Clear")
|
72 |
|
73 |
-
#
|
74 |
submit_btn.click(
|
75 |
-
handle_chat,
|
76 |
inputs=[name, dob, time_of_birth, place_of_birth, zodiac, query, state],
|
77 |
outputs=[chat_interface, state]
|
78 |
)
|
|
|
3 |
import os
|
4 |
|
5 |
# Configure OpenAI API for Groq
|
6 |
+
openai.api_key = os.getenv("API_KEY") # Ensure the GROQ_API_KEY is set in the environment variables
|
7 |
openai.api_base = "https://api.groq.com/openai/v1"
|
8 |
|
9 |
+
# Function to fetch the AI's astrology response
|
10 |
def get_groq_response(name, dob, time_of_birth, place_of_birth, zodiac_sign, query):
|
11 |
try:
|
12 |
system_prompt = f"""You are Master Celestia, an AI astrologer. Analyze this birth chart:
|
|
|
37 |
except Exception as e:
|
38 |
return f"Error: {str(e)}"
|
39 |
|
40 |
+
# Function to handle chat interactions
|
41 |
def handle_chat(name, dob, time_of_birth, place_of_birth, zodiac, query, chat_history):
|
42 |
chat_history = chat_history or []
|
43 |
|
|
|
48 |
|
49 |
return chat_history, chat_history
|
50 |
|
51 |
+
# Gradio interface for the app
|
52 |
with gr.Blocks(theme=gr.themes.Soft(), title="Astro Guide") as demo:
|
53 |
gr.Markdown("# π Astro Guide - AI Astrologer")
|
54 |
|
|
|
60 |
place_of_birth = gr.Textbox(label="Birth Place")
|
61 |
zodiac = gr.Dropdown(
|
62 |
choices=["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo",
|
63 |
+
"Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"],
|
64 |
label="Sun Sign"
|
65 |
)
|
66 |
|
67 |
with gr.Column(scale=2):
|
|
|
68 |
chat_interface = gr.Chatbot(height=500)
|
69 |
query = gr.Textbox(label="Your Question")
|
70 |
state = gr.State()
|
71 |
submit_btn = gr.Button("Ask the Stars", variant="primary")
|
72 |
clear_btn = gr.Button("Clear")
|
73 |
|
74 |
+
# Handlers for buttons and text submissions
|
75 |
submit_btn.click(
|
76 |
+
handle_chat,
|
77 |
inputs=[name, dob, time_of_birth, place_of_birth, zodiac, query, state],
|
78 |
outputs=[chat_interface, state]
|
79 |
)
|