On this tutorial, we display how you can mix the ability of SerpAPI’s Google search capabilities with Google’s Gemini-1.5-Flash mannequin to create a complicated, end-to-end analysis and evaluation workflow inside a Google Colab pocket book. By defining an AdvancedSerpAPI Python class, customers acquire entry to enhanced search strategies that cowl normal net outcomes, information articles, and pictures, whereas additionally leveraging Gemini to carry out in-depth analyses of these outcomes. The code supplies specialised utilities for concentrating on Marktechpost tutorials, aggregating content material throughout classes like LangChain, ChatGPT, and MLOps, after which synthesizing actionable insights utilizing a rigorously constructed immediate.
!pip set up google-search-results langchain-community langchain-core google-generativeai -q
import os
import json
from serpapi import GoogleSearch
import google.generativeai as genai
from datetime import datetime
We set up the required Python packages for SerpAPI searches, LangChain utilities, and Google’s Gemini SDK. The following imports usher in customary modules (os, json, datetime) for atmosphere configuration, JSON dealing with, and timestamps, in addition to SerpAPI’s GoogleSearch class for making API calls and genai for interacting with the Gemini mannequin.
SERPAPI_API_KEY = "Use Your API Key Right here"
GEMINI_API_KEY = "Use Your API Key Right here"
os.environ("SERPAPI_API_KEY") = SERPAPI_API_KEY
genai.configure(api_key=GEMINI_API_KEY)
We assign placeholder strings in your SerpAPI and Gemini API keys, then set the SerpAPI key as an atmosphere variable (so SerpAPI calls authenticate robotically) and configure the Gemini consumer with its API key so you possibly can invoke the Gemini mannequin.
class AdvancedSerpAPI:
def __init__(self, serpapi_key, gemini_key):
self.serpapi_key = serpapi_key
self.gemini_model = genai.GenerativeModel('gemini-1.5-flash')
def search_google(self, question, num_results=5, location="United States"):
"""Enhanced Google search with a number of parameters"""
params = {
"engine": "google",
"q": question,
"api_key": self.serpapi_key,
"num": num_results,
"location": location,
"hl": "en",
"gl": "us"
}
search = GoogleSearch(params)
outcomes = search.get_dict()
return self.extract_search_results(outcomes)
def search_news(self, question, days_back=7):
"""Seek for latest information articles"""
params = {
"engine": "google_news",
"q": question,
"api_key": self.serpapi_key,
"gl": "us",
"hl": "en"
}
search = GoogleSearch(params)
outcomes = search.get_dict()
return self.extract_news_results(outcomes)
def search_images(self, question, num_images=10):
"""Seek for photos with metadata"""
params = {
"engine": "google_images",
"q": question,
"api_key": self.serpapi_key,
"num": num_images
}
search = GoogleSearch(params)
outcomes = search.get_dict()
return self.extract_image_results(outcomes)
def extract_search_results(self, outcomes):
"""Extract and clear search outcomes"""
cleaned_results = ()
if 'organic_results' in outcomes:
for end in outcomes('organic_results'):
cleaned_results.append({
'title': outcome.get('title', ''),
'hyperlink': outcome.get('hyperlink', ''),
'snippet': outcome.get('snippet', ''),
'place': outcome.get('place', 0)
})
return cleaned_results
def extract_news_results(self, outcomes):
"""Extract information articles with timestamps"""
news_results = ()
if 'news_results' in outcomes:
for article in outcomes('news_results'):
news_results.append({
'title': article.get('title', ''),
'hyperlink': article.get('hyperlink', ''),
'snippet': article.get('snippet', ''),
'date': article.get('date', ''),
'supply': article.get('supply', '')
})
return news_results
def extract_image_results(self, outcomes):
"""Extract picture outcomes with metadata"""
image_results = ()
if 'images_results' in outcomes:
for img in outcomes('images_results'):
image_results.append({
'title': img.get('title', ''),
'authentic': img.get('authentic', ''),
'thumbnail': img.get('thumbnail', ''),
'supply': img.get('supply', '')
})
return image_results
def analyze_with_gemini(self, search_results, analysis_prompt):
"""Use Gemini Flash to investigate search outcomes"""
results_text = json.dumps(search_results, indent=2)
full_prompt = f"""
{analysis_prompt}
Search Outcomes Information:
{results_text}
Please present a complete evaluation primarily based on the search outcomes.
"""
attempt:
response = self.gemini_model.generate_content(full_prompt)
return response.textual content
besides Exception as e:
return f"Gemini evaluation failed: {str(e)}"
def search_marktechpost_tutorials(self, subject="", num_results=10):
"""Search particularly for trending tutorials from Marktechpost"""
queries = (
f"website:marktechpost.com {subject} tutorial information how-to 2024 2025",
f"website:marktechpost.com trending {subject} tutorial",
f"website:marktechpost.com prime {subject} books frameworks"
)
all_results = ()
for question in queries:
params = {
"engine": "google",
"q": question,
"api_key": self.serpapi_key,
"num": num_results // len(queries),
"hl": "en",
"gl": "us"
}
search = GoogleSearch(params)
outcomes = search.get_dict()
extracted = self.extract_search_results(outcomes)
all_results.prolong(extracted)
unique_results = ()
seen_links = set()
for end in all_results:
if outcome('hyperlink') not in seen_links:
unique_results.append(outcome)
seen_links.add(outcome('hyperlink'))
return unique_results(:num_results)
def get_trending_marktechpost_content(self, classes=None):
"""Get trending content material from Marktechpost throughout completely different classes"""
if classes is None:
classes = ("AI", "LLM", "Machine Studying", "Python", "Tutorial", "Framework")
trending_content = {}
for class in classes:
print(f"🔍 Looking for trending {class} content material...")
outcomes = self.search_marktechpost_tutorials(class, num_results=5)
trending_content(class) = outcomes
print(f"✅ Discovered {len(outcomes)} {class} tutorials")
return trending_content
def smart_research(self, subject, research_depth="medium", focus_marktechpost=True):
"""Clever analysis combining a number of search sorts with Marktechpost focus"""
print(f"🔍 Beginning good analysis on: {subject}")
if focus_marktechpost:
marktechpost_results = self.search_marktechpost_tutorials(subject, num_results=8)
print(f"✅ Discovered {len(marktechpost_results)} Marktechpost tutorials")
web_results = self.search_google(f"{subject} tutorial information", num_results=3)
print(f"✅ Discovered {len(web_results)} extra net outcomes")
all_web_results = marktechpost_results + web_results
else:
all_web_results = self.search_google(f"{subject} overview information", num_results=5)
print(f"✅ Discovered {len(all_web_results)} net outcomes")
news_results = self.search_news(subject)
print(f"✅ Discovered {len(news_results)} information articles")
analysis_prompt = f"""
Analyze the search outcomes about '{subject}' with give attention to Marktechpost content material and supply:
1. Key tutorials and guides accessible
2. Trending matters and frameworks
3. Studying sources and books talked about
4. Current developments and updates
5. Sensible implementation guides
6. Really useful studying path
Concentrate on actionable insights and studying sources.
"""
all_results = {
"marktechpost_results": marktechpost_results if focus_marktechpost else (),
"web_results": all_web_results,
"news_results": news_results,
"search_topic": subject,
"timestamp": datetime.now().isoformat()
}
gemini_analysis = self.analyze_with_gemini(all_results, analysis_prompt)
return {
"subject": subject,
"marktechpost_tutorials": marktechpost_results if focus_marktechpost else (),
"web_results": all_web_results,
"news_results": news_results,
"ai_analysis": gemini_analysis,
"total_sources": len(all_web_results) + len(news_results)
}
This class, AdvancedSerpAPI, encapsulates SerpAPI-based search strategies (net, information, and pictures) and helper capabilities to wash the ensuing JSON information. It additionally integrates a Gemini-1.5-Flash mannequin, by way of analyze_with_gemini, to generate an AI-driven abstract of any collected search information. Extra utilities embody specialised Marktechpost tutorial lookups, a “get trending” routine throughout classes, and a mixed “good analysis” workflow that stitches collectively tutorials, net outcomes, information, and Gemini evaluation.
def demo_marktechpost_tutorials():
"""Demo particularly centered on Marktechpost tutorials"""
searcher = AdvancedSerpAPI(SERPAPI_API_KEY, GEMINI_API_KEY)
print("🚀 Marktechpost Trending Tutorials Finder")
print("=" * 50)
print("n📚 Demo 1: Trending Marktechpost Tutorials by Class")
trending_content = searcher.get_trending_marktechpost_content((
"LangChain", "ChatGPT", "Python", "AI", "MLOps"
))
for class, tutorials in trending_content.objects():
print(f"n🔥 Trending {class} Tutorials:")
for i, tutorial in enumerate(tutorials(:3), 1):
print(f" {i}. {tutorial('title')}")
print(f" 📎 {tutorial('hyperlink')}")
if tutorial('snippet'):
print(f" 📝 {tutorial('snippet')(:100)}...")
print("n🎯 Demo 2: Deep Dive - LangChain Tutorials")
langchain_research = searcher.smart_research("LangChain", focus_marktechpost=True)
print(f"n📊 Analysis Abstract:")
print(f"Matter: {langchain_research('subject')}")
print(f"Marktechpost Tutorials Discovered: {len(langchain_research('marktechpost_tutorials'))}")
print(f"Whole Sources: {langchain_research('total_sources')}")
print(f"n🤖 AI Evaluation Preview:")
print(langchain_research('ai_analysis')(:600) + "..." if len(langchain_research('ai_analysis')) > 600 else langchain_research('ai_analysis'))
print("n📰 Demo 3: Newest AI Tendencies from Marktechpost")
ai_trends = searcher.search_marktechpost_tutorials("AI traits 2024 2025", num_results=5)
print("Current AI development articles:")
for i, article in enumerate(ai_trends, 1):
print(f"{i}. {article('title')}")
print(f" 🔗 {article('hyperlink')}")
def demo_advanced_serpapi():
"""Complete demo of SerpAPI capabilities"""
searcher = AdvancedSerpAPI(SERPAPI_API_KEY, GEMINI_API_KEY)
print("🚀 Superior SerpAPI Tutorial with Gemini Flash")
print("=" * 50)
print("n📊 Demo 1: Good Analysis on AI Know-how")
research_results = searcher.smart_research("synthetic intelligence 2024 traits")
print(f"n🔍 Analysis Abstract:")
print(f"Matter: {research_results('subject')}")
print(f"Whole Sources: {research_results('total_sources')}")
print(f"n🤖 AI Evaluation Preview:")
print(research_results('ai_analysis')(:500) + "..." if len(research_results('ai_analysis')) > 500 else research_results('ai_analysis'))
print("n📰 Demo 2: Current Information Search")
tech_news = searcher.search_news("expertise breakthrough", days_back=7)
print(f"Discovered {len(tech_news)} latest tech information articles:")
for i, article in enumerate(tech_news(:3), 1):
print(f"{i}. {article('title')(:80)}...")
print(f" Supply: {article('supply')} | Date: {article('date')}")
print("n🖼️ Demo 3: Picture Search")
space_images = searcher.search_images("area exploration 2024", num_images=5)
print(f"Discovered {len(space_images)} space-related photos:")
for i, img in enumerate(space_images(:3), 1):
print(f"{i}. {img('title')(:60)}...")
print(f" Supply: {img('supply')}")
demo_marktechpost_tutorials() initializes the AdvancedSerpAPI class and prints trending tutorials from Marktechpost for a listing of classes (LangChain, ChatGPT, Python, AI, MLOps). It then performs a “deep dive” good analysis on “LangChain,” displaying counts of tutorials and a preview of Gemini’s AI evaluation. Lastly, it retrieves and lists the highest 5 latest “AI traits 2024–2025” articles from Marktechpost.
Additionally, demo_advanced_serpapi() creates an AdvancedSerpAPI occasion however focuses on a broader workflow: it runs good analysis on “synthetic intelligence 2024 traits” and prints the subject abstract and AI evaluation snippet. It then performs a information seek for “expertise breakthrough,” lists the primary three articles with sources and dates, and concludes by fetching and displaying a handful of “area exploration 2024” picture outcomes.
if __name__ == "__main__":
if SERPAPI_API_KEY == "your_serpapi_key_here" or GEMINI_API_KEY == "your_gemini_key_here":
print("⚠️ Please set your API keys earlier than operating the demo!")
print("1. Get SerpAPI key from: https://serpapi.com")
print("2. Get Gemini API key from: https://makersuite.google.com")
else:
print("🎯 Working Marktechpost-focused demo...")
demo_marktechpost_tutorials()
print("n" + "="*50)
print("🌟 Working normal demo...")
demo_advanced_serpapi()
def compare_search_engines(question, engines=('google', 'bing', 'duckduckgo')):
"""Examine outcomes throughout completely different search engines like google and yahoo"""
outcomes = {}
for engine in engines:
params = {
"engine": engine,
"q": question,
"api_key": SERPAPI_API_KEY
}
attempt:
search = GoogleSearch(params)
outcomes(engine) = search.get_dict()
besides Exception as e:
outcomes(engine) = {"error": str(e)}
return outcomes
def trending_searches(location="United States"):
"""Get trending searches"""
params = {
"engine": "google_trends_trending_now",
"api_key": SERPAPI_API_KEY,
"geo": location
}
search = GoogleSearch(params)
return search.get_dict()
print("✅ Superior SerpAPI Tutorial with Marktechpost Focus loaded efficiently!")
print("🔑 Keep in mind to set your API keys earlier than operating demos")
print("📚 New Capabilities: search_marktechpost_tutorials, get_trending_marktechpost_content")
print("🎯 Marktechpost-specific options: LangChain, ChatGPT, Python, AI, MLOps tutorials")
print("n🚀 Fast Begin Examples:")
print("searcher = AdvancedSerpAPI(SERPAPI_API_KEY, GEMINI_API_KEY)")
print("langchain_tutorials = searcher.search_marktechpost_tutorials('LangChain')")
print("trending_ai = searcher.get_trending_marktechpost_content(('AI', 'Python'))")
print("analysis = searcher.smart_research('ChatGPT', focus_marktechpost=True)")
Lastly, the part features a Python “foremost” guard that first verifies your SerpAPI and Gemini keys, prompting you to acquire them in the event that they’re nonetheless placeholders, and in any other case runs the Marktechpost‐centered and normal demos in sequence. It additionally defines two utility capabilities: compare_search_engines, which queries a number of search engines like google and yahoo (Google, Bing, DuckDuckGo) by way of SerpAPI and returns their uncooked JSON outcomes or errors, and trending_searches, which fetches at present’s trending matters utilizing the Google Tendencies endpoint. After these definitions, the script prints a quick standing message confirming that the tutorial loaded efficiently, reminds you to set your API keys, and highlights newly added strategies for fetching Marktechpost tutorials and trending content material.
In conclusion, by following this tutorial, customers can have a reusable, modular Python class that streamlines net analysis and evaluation, from performing keyword-driven searches to robotically summarizing findings utilizing Gemini-powered AI. The mix of SerpAPI’s dependable search endpoints and Gemini’s pure language understanding allows a seamless “research-to-insights” workflow, perfect for content material creators, builders, and technical groups who want to remain up-to-date with the most recent tutorials and trade traits.
Try the Pocket book right here. All credit score for this analysis goes to the researchers of this undertaking. Additionally, be at liberty to comply with us on Twitter and don’t overlook to affix our 95k+ ML SubReddit and Subscribe to our E-newsletter.

Asif Razzaq is the CEO of Marktechpost Media Inc.. As a visionary entrepreneur and engineer, Asif is dedicated to harnessing the potential of Synthetic Intelligence for social good. His most up-to-date endeavor is the launch of an Synthetic Intelligence Media Platform, Marktechpost, which stands out for its in-depth protection of machine studying and deep studying information that’s each technically sound and simply comprehensible by a large viewers. The platform boasts of over 2 million month-to-month views, illustrating its reputation amongst audiences.