Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,8 +18,15 @@ def google_search_query(question, use_web_search):
|
|
| 18 |
config=GenerateContentConfig(tools=[google_search_tool]),
|
| 19 |
)
|
| 20 |
ai_response = response.text # AI response as plain text
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
else:
|
| 24 |
# Return response without web search
|
| 25 |
response = client.models.generate_content(
|
|
|
|
| 18 |
config=GenerateContentConfig(tools=[google_search_tool]),
|
| 19 |
)
|
| 20 |
ai_response = response.text # AI response as plain text
|
| 21 |
+
|
| 22 |
+
# Check if search results are available and extract them
|
| 23 |
+
if hasattr(response.candidates[0].grounding_metadata, 'search_entry_point'):
|
| 24 |
+
search_results = response.candidates[0].grounding_metadata.search_entry_point
|
| 25 |
+
links_html = "\n".join([f"<a href='{result.url}' target='_blank'>{result.title}</a>" for result in search_results.results])
|
| 26 |
+
else:
|
| 27 |
+
links_html = "No search results found."
|
| 28 |
+
|
| 29 |
+
return ai_response, links_html
|
| 30 |
else:
|
| 31 |
# Return response without web search
|
| 32 |
response = client.models.generate_content(
|