Update app.py
Browse files
app.py
CHANGED
|
@@ -50,11 +50,16 @@ custom_js = """
|
|
| 50 |
# =========================================================
|
| 51 |
def google_search_query(question):
|
| 52 |
try:
|
| 53 |
-
#
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
question = question.strip()
|
| 56 |
|
| 57 |
-
|
|
|
|
| 58 |
return "Please type a question above π", ""
|
| 59 |
|
| 60 |
google_search_tool = Tool(google_search=GoogleSearch())
|
|
@@ -74,24 +79,24 @@ def google_search_query(question):
|
|
| 74 |
|
| 75 |
ai_response = response.text or "No AI response generated."
|
| 76 |
|
|
|
|
| 77 |
search_results = ""
|
| 78 |
-
|
| 79 |
-
response.candidates
|
| 80 |
-
and response.candidates[0].grounding_metadata
|
| 81 |
-
and response.candidates[0].grounding_metadata.search_entry_point
|
| 82 |
-
):
|
| 83 |
search_results = (
|
| 84 |
response.candidates[0]
|
| 85 |
.grounding_metadata
|
| 86 |
.search_entry_point
|
| 87 |
.rendered_content
|
| 88 |
)
|
|
|
|
|
|
|
| 89 |
|
| 90 |
return ai_response, search_results
|
| 91 |
|
| 92 |
except Exception as e:
|
| 93 |
return f"β Error: {str(e)}", ""
|
| 94 |
|
|
|
|
| 95 |
# =========================================================
|
| 96 |
# Gradio App
|
| 97 |
# =========================================================
|
|
|
|
| 50 |
# =========================================================
|
| 51 |
def google_search_query(question):
|
| 52 |
try:
|
| 53 |
+
# Force conversion to string safely
|
| 54 |
+
if question is None:
|
| 55 |
+
question = ""
|
| 56 |
+
else:
|
| 57 |
+
question = str(question)
|
| 58 |
+
|
| 59 |
question = question.strip()
|
| 60 |
|
| 61 |
+
# Only block if truly empty
|
| 62 |
+
if len(question) == 0:
|
| 63 |
return "Please type a question above π", ""
|
| 64 |
|
| 65 |
google_search_tool = Tool(google_search=GoogleSearch())
|
|
|
|
| 79 |
|
| 80 |
ai_response = response.text or "No AI response generated."
|
| 81 |
|
| 82 |
+
# Safe grounding extraction
|
| 83 |
search_results = ""
|
| 84 |
+
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
search_results = (
|
| 86 |
response.candidates[0]
|
| 87 |
.grounding_metadata
|
| 88 |
.search_entry_point
|
| 89 |
.rendered_content
|
| 90 |
)
|
| 91 |
+
except Exception:
|
| 92 |
+
search_results = ""
|
| 93 |
|
| 94 |
return ai_response, search_results
|
| 95 |
|
| 96 |
except Exception as e:
|
| 97 |
return f"β Error: {str(e)}", ""
|
| 98 |
|
| 99 |
+
|
| 100 |
# =========================================================
|
| 101 |
# Gradio App
|
| 102 |
# =========================================================
|