basantyahya commited on
Commit
e687876
Β·
verified Β·
1 Parent(s): a908793

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -5,19 +5,19 @@ from google.genai import types
5
  from google.genai.types import GenerateContentConfig, GoogleSearch, Tool
6
 
7
  # =========================================================
8
- # Gemini Setup (FIXED)
9
  # =========================================================
10
  API_KEY = os.getenv("Gemini_API_Key")
11
 
12
  if not API_KEY:
13
  raise RuntimeError(
14
  "❌ Gemini_API_Key is not set. "
15
- "Please add it in Hugging Face β†’ Settings β†’ Secrets."
16
  )
17
 
18
  client = genai.Client(api_key=API_KEY)
19
 
20
- # βœ… Use a VALID model
21
  MODEL_ID = "gemini-2.0-flash"
22
 
23
  # =========================================================
@@ -46,12 +46,13 @@ custom_js = """
46
  """
47
 
48
  # =========================================================
49
- # AI Function (LOGICALLY CORRECT)
50
  # =========================================================
51
  def google_search_query(question):
52
  try:
53
- # Normalize input (important for Gradio + JS)
54
- question =question
 
55
 
56
  if question == "":
57
  return "Please type a question above πŸ‘†", ""
@@ -73,7 +74,6 @@ def google_search_query(question):
73
 
74
  ai_response = response.text or "No AI response generated."
75
 
76
- # Safe grounding extraction
77
  search_results = ""
78
  if (
79
  response.candidates
@@ -101,7 +101,7 @@ with gr.Blocks(css=custom_css) as app:
101
  question = gr.Textbox(
102
  lines=2,
103
  label="Ask a Question",
104
- placeholder="e.g. Types of security jobs"
105
  )
106
 
107
  search_btn = gr.Button("πŸ” Search", elem_id="search-btn")
@@ -117,7 +117,7 @@ with gr.Blocks(css=custom_css) as app:
117
  js=custom_js
118
  )
119
 
120
- # Enter key submit (always reliable)
121
  question.submit(
122
  fn=google_search_query,
123
  inputs=[question],
 
5
  from google.genai.types import GenerateContentConfig, GoogleSearch, Tool
6
 
7
  # =========================================================
8
+ # Gemini Setup
9
  # =========================================================
10
  API_KEY = os.getenv("Gemini_API_Key")
11
 
12
  if not API_KEY:
13
  raise RuntimeError(
14
  "❌ Gemini_API_Key is not set. "
15
+ "Add it in Hugging Face β†’ Settings β†’ Secrets."
16
  )
17
 
18
  client = genai.Client(api_key=API_KEY)
19
 
20
+ # βœ… Valid model
21
  MODEL_ID = "gemini-2.0-flash"
22
 
23
  # =========================================================
 
46
  """
47
 
48
  # =========================================================
49
+ # AI Function (BULLETPROOF)
50
  # =========================================================
51
  def google_search_query(question):
52
  try:
53
+ # πŸ”’ Bulletproof input normalization
54
+ question = "" if question is None else str(question)
55
+ question = question.strip()
56
 
57
  if question == "":
58
  return "Please type a question above πŸ‘†", ""
 
74
 
75
  ai_response = response.text or "No AI response generated."
76
 
 
77
  search_results = ""
78
  if (
79
  response.candidates
 
101
  question = gr.Textbox(
102
  lines=2,
103
  label="Ask a Question",
104
+ placeholder="e.g. What are types of machine learning?"
105
  )
106
 
107
  search_btn = gr.Button("πŸ” Search", elem_id="search-btn")
 
117
  js=custom_js
118
  )
119
 
120
+ # Enter key submit
121
  question.submit(
122
  fn=google_search_query,
123
  inputs=[question],