Rajesh Karra commited on
Commit
a2b4df5
·
verified ·
1 Parent(s): d3b1a4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -2,11 +2,11 @@ import gradio as gr
2
  import requests
3
  import os
4
 
5
- # Retrieve the API key from the environment variable
6
  GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
7
 
8
  def query_gemini(prompt):
9
- url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent"
10
  headers = {
11
  "Content-Type": "application/json"
12
  }
@@ -22,8 +22,9 @@ def query_gemini(prompt):
22
  }
23
  ]
24
  }
 
25
  response = requests.post(url, headers=headers, params=params, json=data)
26
-
27
  try:
28
  return response.json()['candidates'][0]['content']['parts'][0]['text']
29
  except Exception as e:
@@ -31,10 +32,10 @@ def query_gemini(prompt):
31
 
32
  iface = gr.Interface(
33
  fn=query_gemini,
34
- inputs=gr.Textbox(lines=4, placeholder="Ask something..."),
35
  outputs="text",
36
- title="Gemini 2.0 API with Gradio",
37
- description="A simple Hugging Face Space using Gemini 2.0 Flash API"
38
  )
39
 
40
  if __name__ == "__main__":
 
2
  import requests
3
  import os
4
 
5
+ # Load Gemini API key securely from Hugging Face Secrets
6
  GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
7
 
8
  def query_gemini(prompt):
9
+ url = "https://generativelanguage.googleapis.com/v1/models/gemini-1.5-flash-latest:generateContent"
10
  headers = {
11
  "Content-Type": "application/json"
12
  }
 
22
  }
23
  ]
24
  }
25
+
26
  response = requests.post(url, headers=headers, params=params, json=data)
27
+
28
  try:
29
  return response.json()['candidates'][0]['content']['parts'][0]['text']
30
  except Exception as e:
 
32
 
33
  iface = gr.Interface(
34
  fn=query_gemini,
35
+ inputs=gr.Textbox(lines=4, placeholder="Ask a question to Gemini..."),
36
  outputs="text",
37
+ title="Gemini 1.5 Flash API with Gradio",
38
+ description="Interact with Gemini 1.5 Flash through Hugging Face Space"
39
  )
40
 
41
  if __name__ == "__main__":