{"id":15015403,"url":"https://github.com/simplejnius/sj-gemini-vertex-ai","last_synced_at":"2025-06-23T16:40:17.229Z","repository":{"id":252464793,"uuid":"840524057","full_name":"SimpleJnius/sj-gemini-vertex-ai","owner":"SimpleJnius","description":"Access Gemini Firebase Vertex AI Android SDK in Python","archived":false,"fork":false,"pushed_at":"2025-04-26T12:05:49.000Z","size":22,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-26T13:22:04.210Z","etag":null,"topics":["firebae","firebase-firestore","gemini-api","kivy","pyjnius","vertex-ai"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SimpleJnius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-09T23:08:40.000Z","updated_at":"2025-04-26T12:05:52.000Z","dependencies_parsed_at":"2024-08-10T00:26:23.275Z","dependency_job_id":"d6411fe1-ecd1-43c3-b65e-498b1e265f48","html_url":"https://github.com/SimpleJnius/sj-gemini-vertex-ai","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"9a1b616546e1e62d955a64a6c76e1d7d9b2e945b"},"previous_names":["simplejnius/sj-gemini-vertex-ai"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SimpleJnius/sj-gemini-vertex-ai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleJnius%2Fsj-gemini-vertex-ai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleJnius%2Fsj-gemini-vertex-ai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleJnius%2Fsj-gemini-vertex-ai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleJnius%2Fsj-gemini-vertex-ai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimpleJnius","download_url":"https://codeload.github.com/SimpleJnius/sj-gemini-vertex-ai/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimpleJnius%2Fsj-gemini-vertex-ai/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261514347,"owners_count":23170356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["firebae","firebase-firestore","gemini-api","kivy","pyjnius","vertex-ai"],"created_at":"2024-09-24T19:47:25.537Z","updated_at":"2025-06-23T16:40:17.220Z","avatar_url":"https://github.com/SimpleJnius.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gemini (Firebase-Vertex-AI)\n\nAccess Gemini Android SDK in Python \n\n\u003c!-- GitAds-Verify: 9U81VHQ4LFABYVNK6Q585J18H96UMN51 --\u003e\n## GitAds Sponsored\n[![Sponsored by GitAds](https://gitads.dev/v1/ad-serve?source=simplejnius/sj-gemini-vertex-ai@github)](https://gitads.dev/v1/ad-track?source=simplejnius/sj-gemini-vertex-ai@github)\n\n\n\n## Usage\n**Note: NO NEED FOR THREAD OR ASYNC.**\n\n### For autocompletion in IDE\n```shell\npip install sjgeminifvai\n```\n\n### Set up your firebase project for Android\nRead more [here](https://firebase.google.com/docs/vertex-ai/get-started?hl=en\u0026authuser=0\u0026platform=android#set-up-firebase)\n\n### Add SDK to buildozer.spec file\n```rpmspec\nrequirements=sjgeminifvai,simplejnius\n\nandroid.gradle_dependencies=com.google.guava:guava:32.0.1-android,\n  org.reactivestreams:reactive-streams:1.0.4,com.google.firebase:firebase-vertexai:16.0.0-beta04\n```\n\n### Interact with Vertex Gemini API Without Streaming\nWait for the entire result instead of streaming; \nthe result is only returned after the model completes the entire generation process.\n\n```python\nfrom sjgeminifvai.jclass import (\n    FirebaseVertexAI,\n    ContentBuilder,\n    GenerativeModelFutures\n)\nfrom simplejnius.guava.jclass import Futures\nfrom simplejnius.guava.jinterface import FutureCallback\nfrom kivy.app import App\nfrom kivy.uix.boxlayout import BoxLayout\nfrom kivy.uix.label import Label\nfrom kivy.uix.textinput import TextInput\n\n\nclass GeminiApp(App):\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)\n        self.future_callback = None\n        self.response = None\n        self.prompt = None\n        self.textinput = None\n        self.label = None\n\n        # Initialize the Vertex AI service and the generative model\n        # Specify a model that supports your use case\n        # Gemini 1.5 models are versatile and can be used with all API capabilities\n        vertex = FirebaseVertexAI.getInstance()\n        self.gm = vertex.generativeModel(\"gemini-1.5-flash\")\n\n        # Use the GenerativeModelFutures Java compatibility layer which offers\n        # support for ListenableFuture and Publisher APIs\n        self.model = GenerativeModelFutures.from_(self.gm)\n\n    def build(self):\n        self.label = Label()\n        self.textinput = TextInput(\n            size_hint_y=.1,\n            hint_text=\"Chat with gemini\",\n            on_text_validate=self.chat_gemini\n        )\n        box = BoxLayout(orientation=\"vertical\")\n        box.add_widget(self.label)\n        box.add_widget(self.textinput)\n        return box\n\n    def chat_gemini(self, instance):\n        # Provide a prompt that contains text\n        self.prompt = (\n            ContentBuilder()\n            .addText(instance.text)\n            .build()\n        )\n\n        # To generate text output, call generateContent with the text input\n        self.response = self.model.generateContentResponse(self.prompt)\n\n        self.future_callback = FutureCallback(\n            callback=dict(\n                on_success=self.get_gemin_reply,\n                on_failure=print\n            )\n        )\n        Futures.addCallback(self.response, self.future_callback)\n\n    def get_gemini_reply(self, result):\n        self.label.text = result.getText()\n\n\nif __name__ == \"__main__\":\n    GeminiApp().run()\n\n# report any bug or error if the above code does not work as expected\n```\n\n### Interact with Vertex Gemini API With Streaming\nYou can achieve faster interactions by not waiting for the entire result from the model generation, \nand instead use streaming to handle partial results.\n\nThis example shows how to use generateContentStream to stream \ngenerated text from a prompt request that includes only text:\n\n```python\nfrom sjgeminifvai.jclass import (\n    FirebaseVertexAI,\n    ContentBuilder,\n    GenerativeModelFutures\n)\nfrom simplejnius.reactivestreams.jinterface import Subscriber\nfrom kivy.app import App\nfrom kivy.uix.boxlayout import BoxLayout\nfrom kivy.uix.label import Label\nfrom kivy.uix.textinput import TextInput\nfrom kivy.clock import Clock\n\n\nclass GeminiApp(App):\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)\n        self.subscriber = None\n        self.gcr = None\n        self.streaming_response = None\n        self.prompt = None\n        self.textinput = None\n        self.label = None\n\n        # Initialize the Vertex AI service and the generative model\n        # Specify a model that supports your use case\n        # Gemini 1.5 models are versatile and can be used with all API capabilities\n        vertex = FirebaseVertexAI.getInstance()\n        self.gm = vertex.generativeModel(\"gemini-1.5-flash\")\n\n        # Use the GenerativeModelFutures Java compatibility layer which offers\n        # support for ListenableFuture and Publisher APIs\n        self.model = GenerativeModelFutures.from_(self.gm)\n\n    def build(self):\n        self.label = Label()\n        self.textinput = TextInput(\n            size_hint_y=.1,\n            hint_text=\"Chat with gemini\",\n            on_text_validate=self.chat_gemini\n        )\n        box = BoxLayout(orientation=\"vertical\")\n        box.add_widget(self.label)\n        box.add_widget(self.textinput)\n        return box\n\n    def chat_gemini(self, instance):\n        # Provide a prompt that contains text\n        self.prompt = (\n            ContentBuilder()\n            .addText(instance.text)\n            .build()\n        )\n\n        # To stream generated text output, call generateContentStream with the text input\n        self.streaming_response = self.model.generateContentStream(self.prompt)\n\n        self.subscriber = Subscriber(\n            callback=dict(\n                on_next=self.get_gemini_reply,\n                on_complete=lambda result: setattr(self.label, \"text\", result.getText()),\n                on_error=print,\n                on_subscribe=print\n            )\n        )\n        self.streaming_response.subscribe(self.subscriber)\n\n    def get_gemini_reply(self, result):\n        chunk = result.getText()\n\n        def add_chunk_to_label(_):\n            self.label.text += chunk\n\n        Clock.schedule_once(add_chunk_to_label)\n\n\nif __name__ == \"__main__\":\n    GeminiApp().run()\n\n# report any bug or error if the above code does not work as expected\n```\n\n# Examples to interact with images and videos coming soon \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplejnius%2Fsj-gemini-vertex-ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplejnius%2Fsj-gemini-vertex-ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplejnius%2Fsj-gemini-vertex-ai/lists"}