cxeep commited on
Commit
2885319
·
verified ·
1 Parent(s): 07dca08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import requests
3
 
4
- def check_key_gemini_availability(key):
5
  """
6
  Checks the availability of a Gemini API key.
7
  Args:
@@ -19,7 +19,10 @@ def check_key_gemini_availability(key):
19
  return False, f"Invalid key: 'models' field not found in response from list models endpoint."
20
 
21
  # Second, attempt to generate content to further validate the key
22
- url_generateContent = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key={key}"
 
 
 
23
  # headers = {'Content-Type': 'application/json'}
24
  data = {"contents": [{"parts": [{"text": "Say \"this is a test\""}]}]}
25
  rq = requests.post(url_generateContent, json=data) #headers=headers, data=json.dumps(data)
@@ -74,6 +77,7 @@ with gr.Blocks() as demo:
74
  with gr.Row():
75
  with gr.Column():
76
  keys = gr.TextArea(label="API Keys (by lines)")
 
77
  with gr.Row():
78
  clear_button = gr.Button("Clear")
79
  submit_button = gr.Button("Submit", variant="primary")
@@ -82,6 +86,6 @@ with gr.Blocks() as demo:
82
  errs = gr.TextArea(label="Invalid Keys-status code")
83
 
84
  clear_button.click(fn=clear_inputs, outputs=[keys])
85
- submit_button.click(fn=check_keys, inputs=[keys], outputs=[infos, errs], api_name="check_keys")
86
 
87
  demo.launch()
 
1
  import gradio as gr
2
  import requests
3
 
4
+ def check_key_gemini_availability(key, ai_model):
5
  """
6
  Checks the availability of a Gemini API key.
7
  Args:
 
19
  return False, f"Invalid key: 'models' field not found in response from list models endpoint."
20
 
21
  # Second, attempt to generate content to further validate the key
22
+ ai_model_ = ai_model.strip() or "gemini-1.5-flash"
23
+ if ai_model_ not in result['models']:
24
+ return False, f"Specified model is not in available 'models'."
25
+ url_generateContent = f"https://generativelanguage.googleapis.com/v1beta/models/{ai_model_}:generateContent?key={key}"
26
  # headers = {'Content-Type': 'application/json'}
27
  data = {"contents": [{"parts": [{"text": "Say \"this is a test\""}]}]}
28
  rq = requests.post(url_generateContent, json=data) #headers=headers, data=json.dumps(data)
 
77
  with gr.Row():
78
  with gr.Column():
79
  keys = gr.TextArea(label="API Keys (by lines)")
80
+ ai_model = ge.Textbox(label="gemini model")
81
  with gr.Row():
82
  clear_button = gr.Button("Clear")
83
  submit_button = gr.Button("Submit", variant="primary")
 
86
  errs = gr.TextArea(label="Invalid Keys-status code")
87
 
88
  clear_button.click(fn=clear_inputs, outputs=[keys])
89
+ submit_button.click(fn=check_keys, inputs=[keys,ai_model], outputs=[infos, errs], api_name="check_keys")
90
 
91
  demo.launch()