Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,7 +23,7 @@ questions = [
|
|
23 |
# Function to query the Gemini API
|
24 |
def query_gemini_api(user_answers):
|
25 |
# Correct Gemini API endpoint (based on Google's Generative AI documentation)
|
26 |
-
url = f"https://generativelanguage.googleapis.com/
|
27 |
|
28 |
headers = {'Content-Type': 'application/json'}
|
29 |
|
@@ -32,11 +32,15 @@ def query_gemini_api(user_answers):
|
|
32 |
|
33 |
# Payload for the API
|
34 |
payload = {
|
35 |
-
"
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
|
42 |
try:
|
@@ -48,9 +52,9 @@ def query_gemini_api(user_answers):
|
|
48 |
result = response.json()
|
49 |
|
50 |
# Extract the generated text from the response
|
51 |
-
|
52 |
-
if
|
53 |
-
generated_text =
|
54 |
return generated_text
|
55 |
else:
|
56 |
return None
|
|
|
23 |
# Function to query the Gemini API
|
24 |
def query_gemini_api(user_answers):
|
25 |
# Correct Gemini API endpoint (based on Google's Generative AI documentation)
|
26 |
+
url = f"https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001:generateText?key={GEMINI_API_KEY}"
|
27 |
|
28 |
headers = {'Content-Type': 'application/json'}
|
29 |
|
|
|
32 |
|
33 |
# Payload for the API
|
34 |
payload = {
|
35 |
+
"instances": [
|
36 |
+
{
|
37 |
+
"content": f"Analyze the following mood based on these inputs: {input_text}. Provide suggestions to improve the mood."
|
38 |
+
}
|
39 |
+
],
|
40 |
+
"parameters": {
|
41 |
+
"temperature": 0.7,
|
42 |
+
"maxOutputTokens": 256
|
43 |
+
}
|
44 |
}
|
45 |
|
46 |
try:
|
|
|
52 |
result = response.json()
|
53 |
|
54 |
# Extract the generated text from the response
|
55 |
+
predictions = result.get("predictions", [])
|
56 |
+
if predictions:
|
57 |
+
generated_text = predictions[0].get("content", "")
|
58 |
return generated_text
|
59 |
else:
|
60 |
return None
|