B4A Library 🚀 Gemini Lib – Now with AI Image Generation + Text, Vision & PDF Support

? Discover Gemini Lib! ?

Welcome to the future of programming with Gemini Lib! This incredible library is crafted for bold developers who want to breathe life into their B4X projects (B4J, B4A, and B4i) with the power of Google's artificial intelligence.

With Gemini Lib, the might of Gemini is at your fingertips. It's as simple as a couple of lines of code! ?

Spectacular Features:

  1. ? Total Compatibility: Gemini Lib seamlessly fits into B4J, B4A, and B4i, giving you access to the most advanced AI tools in any project you choose.
  2. ?️ Easy Integration: No more technical headaches! Gemini Lib streamlines the integration of artificial intelligence into your B4X applications, so you can focus on what matters most: creating amazing experiences for your users!
  3. ? Complete Functionality: From natural language, Gemini Lib unlocks all of Gemini's API capabilities for your applications to reach their full potential.
  4. ⚡ Optimal Performance: Designed to shine even in the most demanding projects, Gemini Lib maximizes available resources to ensure exceptional performance at all times.
Excited to get started? Getting your API key is the first step towards creating incredible applications! ? Visit Visit this link to get your API key and unleash your creativity. to get your API key and unleash your creativity.

Please note: To acquire the library, registration is required before making the purchase.

Gemini Lib is more than just an artificial intelligence library. It's your ticket to take your B4X projects to the next level! ?

Don't wait any longer! Join the AI revolution with Gemini Lib today! ??✨

Download: https://b4xapp.com/item/germini-lib-

example:


Gemini Lib v5.0 Updated Example:
#Region  Project Attributes
#ApplicationLabel: ChatBot
#VersionCode: 1
#VersionName: 1.0
#SupportedOrientations: portrait
#CanInstallToExternalStorage: True
#End Region


#Region  Activity Attributes
#FullScreen: False
#IncludeTitle: False
#End Region


#BridgeLogger: True


Sub Process_Globals
Dim xui As XUI
End Sub


Sub Globals
Dim ia As Gemini_IA
End Sub


Sub Activity_Create(FirstTime As Boolean)




ia.Initialize(Me, "ia")

' IMPORTANT:
' Use a PAID API key if you want image generation
ia.setApiKey  = "AIzaxxxxxxxxxxxxxxxxx"



End Sub


' 🔹 TEXT EXAMPLE
Sub ButtonText_Click
ia.Ask("Write a story about a magic backpack")
End Sub


' 🔹 IMAGE GENERATION EXAMPLE
Sub ButtonImage_Click
ia.GenerateImage("a futuristic glowing magic backpack floating in space, cinematic lighting")
End Sub


' 🔹 Unified Response Event (v5)
Private Sub ia_Response(Result As GeminiResponse)




If Result.Success = False Then
    Log("Error receiving response")
    Return
End If

If Result.IsImage Then
    
    If Result.Image.IsInitialized Then
        Log("Image received successfully")
        ' Example:
        ' B4XImageView1.Bitmap = Result.Image
    Else
        Log("Image not initialized")
    End If
    
Else
    Log("Text received:")
    Log(Result.Text)
End If



End Sub


Private Sub ia_Error(Message As String)
Log("Gemini Error: " & Message)
End Sub
 

Attachments

  • example chat.zip
    388.2 KB · Views: 477
  • 1000252933.png
    1000252933.png
    205.9 KB · Views: 502
  • 1000252932.png
    1000252932.png
    231.3 KB · Views: 449
Last edited:

fernando1987

Active Member
Licensed User
Longtime User
? Introducing Gemini Lib 4.0! ?

Step into the next era of programming with Gemini Lib 4.0! Designed for visionary developers, this cutting-edge library supercharges your B4X projects (B4J, B4A, and B4i) with the power of Google's advanced AI.

With Gemini Lib 4.0, you now have the ability to not only leverage text-based queries but also to upload images and PDF documents for analysis by Gemini! The possibilities are endless, and the integration is seamless—just a few lines of code are all it takes. ?

This version introduces a whole new dimension to your AI-driven applications, making it easier than ever to extract insights and generate content from a variety of formats. Plus, the codebase has been further refined for better performance and usability.

Don’t miss out on the revolution! Join the AI-powered development world with Gemini Lib 4.0 today! ??✨

Example Usage:
Example pdf:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Dim gemini As Gemini_IA
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
End Sub

Sub Button1_Click
   
    gemini.Initialize(Me,"consult")
    gemini.ApiKey("AIzaxxxxxxxxxxxxxxxxxxxxxxxxx")
    gemini.temperature = 0
    gemini.HARM_CATEGORY_DANGEROUS_CONTENT = gemini.umbral.BLOCK_LOW_AND_ABOVE

    Dim s As String
    Dim f As FileChooser
    f.Initialize
    s = f.ShowOpen(MainForm)
    gemini.ConsultForPdf_IA("give me a summary of this document",s)

End Sub

Private Sub consult_success(x As String, success As Boolean)
Log(success)
    If success = True Then

        Log(x)

    Else

    End If
End Sub

Private Sub consult_error(error As String)
    Log(error)
End Sub

For existing users, log in to your user panel on our store using your credentials. In the "Recent Orders" section, find the option to download and access the latest Version 4.
 

fernando1987

Active Member
Licensed User
Longtime User
? Introducing Gemini Lib 4.1! ?

The next era of programming just got even better! We’re excited to announce the release of Gemini Lib 4.1—your go-to library for supercharging B4X projects (B4J, B4A, and B4i) with the power of Google's advanced AI.

In this update, we've squashed bugs and optimized the code, ensuring a smoother and more reliable experience. With Gemini Lib 4.1, you still have all the incredible features from 4.0—like the ability to analyze images and PDF documents alongside text-based queries—but now with enhanced stability and performance.

Don’t miss out on this upgrade! Elevate your AI-powered applications to new heights with Gemini Lib 4.1. ??✨

For existing users, log in to your user panel on our store using your credentials. In the "Recent Orders" section, find the option to download and access the latest Version 4.1
 

fernando1987

Active Member
Licensed User
Longtime User

Version 4.3 Now Available! 🎉

We’re excited to announce the release of Version 4.3 with significant code corrections and performance enhancements! 🚀

How to Download the Update:​

If you’ve already purchased a previous version, simply log in to your user panel on our store at b4xapp.com using your credentials.

  1. Navigate to the "Recent Orders" section.
  2. Locate your purchase of GeminiLib.
  3. Click the download option to get the latest version at no additional cost.
Enjoy the improvements and let us know what you think!


🎁 Limited-Time Offer!
Take advantage of 50% OFF on all codes and libraries in our store until January 5, 2025! Don't miss this opportunity to expand your toolkit at half the price.

Visit b4xapp.com now and save big! 🛒
 

fernando1987

Active Member
Licensed User
Longtime User
Version 4.5 Now Available! 🚀
We’re pleased to introduce Version 4.5 of GeminiLib, featuring updated and optimized code for even better performance and stability. 💡


🛠️ What’s New in 4.5:


  • Refactored and streamlined codebase
  • Improved execution speed and reliability
  • Cleaner architecture for easier integration

📥 How to Get the Update:
If you’ve already purchased a previous version, just log in to your user panel at b4xapp.com:


  1. Go to the "Recent Orders" section
  2. Find your purchase of GeminiLib
  3. Download the latest version — free of charge!

Thanks for your continued support, and we hope you enjoy the latest improvements!
 

fernando1987

Active Member
Licensed User
Longtime User
Gemini Library – Update with New Features 🚀


Hi everyone,


I’m happy to announce a new update of the Gemini Library 🎉.
This version comes with several improvements and new features to make integration with Google Gemini API easier and more flexible.


🔹 What’s new?​


  • Added Prompt support → now you can optionally configure an initial instruction (system prompt) that customizes how the AI responds (tone, language, level of detail, etc.).
    • ⚡ The library does not require a prompt to work, but this feature opens the door to building chat agents or specialized assistants.
  • Improved stability → refined error handling and response parsing.
  • Cleaner events → success, error, model_success, and model_error for better callback management.
  • Full support for Text, PDF and Image inputs → the library automatically adapts to different content types.
  • Compatibility → works with B4A, B4J, and B4i.

Example:
Dim Gemini As GeminiIA
Gemini.Initialize(Me, "Gemini")
Gemini.ApiKey("YOUR_API_KEY")

' Prompt is optional
Gemini.Prompt = "Answer in Spanish, with a friendly tone"

' Call Gemini
Gemini.Consult_IA("Explain how photosynthesis works")
 

fernando1987

Active Member
Licensed User
Longtime User

🚀 Gemini_IA v5.0 – Image Generation, PDF, Vision & Professional Architecture​


Hello everyone 👋


I'm excited to announce Gemini_IA version 5.0 for B4X.


This is a fully restructured version — more robust, cleaner internally, and production-ready.


Now supports:


  • ✅ Text generation
  • ✅ Image analysis
  • ✅ PDF analysis
  • ✅ Image generation
  • ✅ Unified network architecture
  • ✅ Robust error handling
  • ✅ B4A / B4i / B4J compatible



🔥 What’s New in Version 5.0​


🧠 Unified Network Engine​


All API communication now goes through a single internal pipeline:


  • No duplicated code
  • Cleaner architecture
  • Safer JSON parsing
  • Better error detection



🖼 Image Generation​


New function:


Generate Image Example:
Dim IA As Gemini_IA


IA.Initialize(Me, "IA")
IA.ApiKey = "YOUR_API_KEY"


IA.GenerateImage("a ninja cat eating ceviche on the beach of Guayaquil at sunset, cyberpunk style")


Private Sub IA_Response(Result As GeminiResponse)

    If Result.Success = False Then Return

    If Result.IsImage Then
        If Result.Image.IsInitialized Then
            B4XImageView1.Bitmap = Result.Image
            IA.SaveImage(Result.Image,File.DirApp,"gato.png")
        Else
            Log("Imagen no inicializada")
        End If
    Else
        Log("Texto recibido: " & Result.Text)
    End If

End Sub

1771813231668.png


Captura de pantalla 2026-02-22 212225.png


The function returns a B4XBitmap ready to use in:


  • B4XImageView
  • ImageView
  • Canvas
  • File saving



⚠ IMPORTANT – Paid API Key Required for Image Generation​


To generate images, a free API key is NOT enough.


You must have:


  • An API key linked to a project with billing enabled
  • Active quota for image models
  • Access to the corresponding image model

If you use a free-tier API key, you will receive:




Quota exceeded (429 error)
generate_content_free_tier_requests limit: 0



Text generation may work in free tier.
Image generation typically requires a paid plan.




📝 Basic Text Example​


Text Example:
Dim Gemini As Gemini_IA


Gemini.Initialize(Me, "Gemini")
Gemini.ApiKey = "YOUR_API_KEY"


Gemini.Ask("Explain how photosynthesis works")


Private Sub Gemini_Response(Result As GeminiResponse)




If Result.Success = False Then Return

If Result.IsImage Then
    Log("Unexpected image response")
Else
    Log(Result.Text)
End If



End Sub




🖼 Image Analysis Example​


Image Analysis Example:
Dim Gemini As Gemini_IA


Gemini.Initialize(Me, "Gemini")
Gemini.ApiKey  = "YOUR_API_KEY"


Gemini.AskWithImage("Describe this image:", File.Combine(File.DirApp, "photo.png"))


Private Sub Gemini_Response(Result As GeminiResponse)




If Result.Success = False Then Return

Log(Result.Text)



End Sub




📄 PDF Analysis Example​


PDF Example:
Dim Gemini As Gemini_IA


Gemini.Initialize(Me, "Gemini")
Gemini.ApiKey = "YOUR_API_KEY"


Gemini.AskWithPdf("Summarize this document:", File.Combine(File.DirApp, "document.pdf")


Private Sub Gemini_Response(Result As GeminiResponse)




If Result.Success = False Then Return

Log(Result.Text)



End Sub




🏗 New Structured Response Type​


Version 5 introduces a professional structured response:


Response Type:
Type GeminiResponse( _
Text As String, _
Image As B4XBitmap, _
IsImage As Boolean, _
Success As Boolean _
)


This makes the library:


  • Cleaner
  • Easier to extend
  • Future-proof (tokens, usage, finish reason, etc.)



🎯 Compatibility​


✔ B4A
✔ B4i
✔ B4J
✔ B4XPages
✔ XUI




📌 Production Recommendations​


For production usage:


  • Enable billing in Google Cloud
  • Verify model quotas
  • Confirm access to image models using GetModels



If anyone tests the library in different environments or models, feedback is very welcome 🙌


Hope you find it useful 🚀
 
Last edited:
Top