tarrasyed19472007 commited on
Commit
42d0d42
·
verified ·
1 Parent(s): 6cafcf6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
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/v1beta/models/gemini-1.5-flash-latest:generateContent?key={GEMINI_API_KEY}"
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
- "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
- "candidateCount": 1
 
 
 
 
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
- candidates = result.get("candidates", [])
52
- if candidates:
53
- generated_text = candidates[0].get("output", "")
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