Skip to content
Sam Witteveen
0:10:44
3 117
119
19
Last update : 23/08/2024

πŸš€ Mastering Gemini: Your Guide to Extracting JSON from Text & Images πŸͺ„

πŸ—οΈ Why This Matters:

This isn’t just about code; it’s about unlocking a new way to interact with information πŸ”“. Imagine effortlessly extracting key details from articles πŸ“° or even images 🏞️ and using them to power your apps, analyses, and more!

🧲 Gemini’s JSON Superpower: Two Ways to Wield It

1️⃣ The Universal Approach (Works with Flash & Pro):

  • Headline: Tell Gemini what you want upfront!
  • Explanation: Specify response_mime_type='application/json' in your generation config.
  • Example: Ask for a list of cookie recipes in JSON format, and voila! πŸͺ
  • Pro Tip: Remember, you’ll get a JSON string back. Use json.loads() to turn it into a usable dictionary.

2️⃣ The Pro Exclusive (Gemini 1.5 Pro Only):

  • Headline: Level up with Pydantic! πŸ’ͺ
  • Explanation: Define your desired data structure using Pydantic classes for cleaner, more organized output.
  • Example: Create a Pydantic class for “Recipe” with “name” and “ingredients” attributes. Pass this structure to Gemini using response_schema.
  • Gotcha: For complex, nested structures, convert your Pydantic class to a JSON string first!

πŸ“° Extracting Insights from Articles:

  • Headline: Turn articles into actionable data goldmines! ⛏️
  • Explanation: Combine the power of web scraping (using libraries like newspaper3k) with Gemini’s JSON output.
  • Example: Extract names of people, organizations, and product types from news articles.
  • Power Tip: Use Pydantic classes to neatly store the extracted information, making it easy to analyze and use later.

🏞️ Unlocking the Magic of Multimodal JSON:

  • Headline: It’s not just about text! Gemini can extract JSON from images too. 🀯
  • Explanation: Pass an image to Gemini along with your prompt, specifying the JSON structure you desire.
  • Example: Analyze a flight timetable image and get a JSON output containing flight times and destinations. ✈️
  • Pro Tip: Both Gemini Pro and Flash can handle image-to-JSON extraction, but Flash is faster and more cost-effective!

🧰 Your Gemini Toolkit:

  1. Google AI Studio: Experiment with Gemini and access its powerful capabilities. (https://drp.li/AnNMu)
  2. Building LLM Agents Form: Interested in taking your Gemini skills further? Fill out this form: (https://drp.li/dIMes)
  3. Langchain Tutorials Github: Explore advanced techniques and use cases for working with Gemini. (https://github.com/samwit/langchain-tutorials)
  4. LLM Tutorials Github: Dive deeper into the world of LLMs and their applications. (https://github.com/samwit/llm-tutorials)
  5. Newspaper3k: A Python library for extracting articles from websites. (https://pypi.org/project/newspaper3k/)
  6. Pydantic: Define data structures with ease and validation. (https://pydantic-docs.helpmanual.io/)

✨ The Future is Multimodal:

We’ve only scratched the surface! Imagine extracting insights from audio, video, and more in the near future. Start experimenting with Gemini’s JSON superpowers and see what amazing applications you can build! πŸš€

Other videos of

Play Video
Sam Witteveen
0:12:23
748
80
8
Last update : 12/04/2025
Play Video
Sam Witteveen
0:06:43
442
60
6
Last update : 10/04/2025
Play Video
Sam Witteveen
0:16:03
1 066
90
21
Last update : 07/04/2025
Play Video
Sam Witteveen
0:07:33
830
55
22
Last update : 01/04/2025
Play Video
Sam Witteveen
0:17:58
474
54
16
Last update : 29/03/2025
Play Video
Sam Witteveen
0:21:00
444
38
9
Last update : 26/03/2025
Play Video
Sam Witteveen
0:12:16
694
46
10
Last update : 20/03/2025
Play Video
Sam Witteveen
0:08:17
878
77
11
Last update : 20/03/2025
Play Video
Sam Witteveen
0:15:59
353
33
1
Last update : 20/03/2025