Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,8 +22,8 @@ questions = [
|
|
22 |
|
23 |
# Function to query the Gemini API
|
24 |
def query_gemini_api(user_answers):
|
25 |
-
# Correct Gemini API endpoint
|
26 |
-
url = f"https://generativelanguage.googleapis.com/
|
27 |
|
28 |
headers = {'Content-Type': 'application/json'}
|
29 |
|
@@ -32,15 +32,13 @@ def query_gemini_api(user_answers):
|
|
32 |
|
33 |
# Payload for the API
|
34 |
payload = {
|
35 |
-
"
|
36 |
-
{
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
"
|
41 |
-
|
42 |
-
"maxOutputTokens": 256
|
43 |
-
}
|
44 |
}
|
45 |
|
46 |
try:
|
@@ -52,12 +50,8 @@ def query_gemini_api(user_answers):
|
|
52 |
result = response.json()
|
53 |
|
54 |
# Extract the generated text from the response
|
55 |
-
|
56 |
-
|
57 |
-
generated_text = predictions[0].get("content", "")
|
58 |
-
return generated_text
|
59 |
-
else:
|
60 |
-
return None
|
61 |
else:
|
62 |
st.error(f"API Error {response.status_code}: {response.text}")
|
63 |
return None
|
|
|
22 |
|
23 |
# Function to query the Gemini API
|
24 |
def query_gemini_api(user_answers):
|
25 |
+
# Correct Gemini API endpoint
|
26 |
+
url = f"https://generativelanguage.googleapis.com/v1beta/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 |
+
"prompt": {
|
36 |
+
"text": f"Analyze the following mood based on these inputs: {input_text}. Provide suggestions to improve the mood."
|
37 |
+
},
|
38 |
+
"temperature": 0.7,
|
39 |
+
"maxOutputTokens": 256,
|
40 |
+
"topP": 0.8,
|
41 |
+
"topK": 40
|
|
|
|
|
42 |
}
|
43 |
|
44 |
try:
|
|
|
50 |
result = response.json()
|
51 |
|
52 |
# Extract the generated text from the response
|
53 |
+
generated_text = result.get("candidates", [{}])[0].get("output", "")
|
54 |
+
return generated_text
|
|
|
|
|
|
|
|
|
55 |
else:
|
56 |
st.error(f"API Error {response.status_code}: {response.text}")
|
57 |
return None
|