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:15:29
2 452
214
20
Last update : 19/09/2024
Play Video
Sam Witteveen
0:14:47
3 154
187
15
Last update : 18/09/2024
Play Video
Sam Witteveen
0:27:18
8 664
320
32
Last update : 18/09/2024
Play Video
Sam Witteveen
0:19:22
6 779
326
39
Last update : 11/09/2024
Play Video
Sam Witteveen
0:12:34
4 404
198
23
Last update : 04/09/2024
Play Video
Sam Witteveen
0:17:24
12 389
261
49
Last update : 04/09/2024
Play Video
Sam Witteveen
0:14:32
12 502
361
27
Last update : 28/08/2024
Play Video
Sam Witteveen
0:22:49
6 518
239
31
Last update : 28/08/2024
Play Video
Sam Witteveen
0:16:04
6 791
257
28
Last update : 23/08/2024