B4A Library πŸš€ Gemini Lib – Now with AI Image Generation + Text, Vision & PDF Support

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





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:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…