├── .allstar └── binary_artifacts.yaml ├── .github ├── labeler.yml └── workflows │ ├── labeler.yml │ ├── notebooks.yaml │ └── stale.yml ├── .gitignore ├── CONTRIBUTING.md ├── CodeGemma ├── README.md ├── [CodeGemma_1]Common_use_cases.ipynb └── [CodeGemma_1]Finetune_with_SQL.ipynb ├── Demos ├── Gemma-on-Android │ ├── Android_App │ │ ├── .gitignore │ │ ├── app │ │ │ ├── .gitignore │ │ │ ├── build.gradle.kts │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ ├── androidTest │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── scigemma │ │ │ │ │ └── ExampleInstrumentedTest.kt │ │ │ │ ├── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── scigemma │ │ │ │ │ │ ├── ChatMessage.kt │ │ │ │ │ │ ├── ChatScreen.kt │ │ │ │ │ │ ├── ChatUiState.kt │ │ │ │ │ │ ├── ChatViewModel.kt │ │ │ │ │ │ ├── InferenceModel.kt │ │ │ │ │ │ ├── LoadingScreen.kt │ │ │ │ │ │ ├── MainActivity.kt │ │ │ │ │ │ └── ui │ │ │ │ │ │ └── theme │ │ │ │ │ │ ├── Color.kt │ │ │ │ │ │ ├── Theme.kt │ │ │ │ │ │ └── Type.kt │ │ │ │ └── res │ │ │ │ │ ├── drawable │ │ │ │ │ ├── ic_launcher_background.xml │ │ │ │ │ ├── ic_launcher_foreground.xml │ │ │ │ │ └── scigemmaicon.jpg │ │ │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ │ ├── ic_launcher.xml │ │ │ │ │ └── ic_launcher_round.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ └── ic_launcher_round.webp │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ └── ic_launcher_round.webp │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ └── ic_launcher_round.webp │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ └── ic_launcher_round.webp │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ └── ic_launcher_round.webp │ │ │ │ │ ├── values │ │ │ │ │ ├── colors.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── themes.xml │ │ │ │ │ └── xml │ │ │ │ │ ├── backup_rules.xml │ │ │ │ │ └── data_extraction_rules.xml │ │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── scigemma │ │ │ │ └── ExampleUnitTest.kt │ │ ├── build.gradle.kts │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ └── settings.gradle.kts │ ├── LICENSE │ ├── README.md │ └── assets │ │ ├── SciGemma.gif │ │ └── SciGemma_Pipeline.gif ├── Gemma-on-Cloudrun │ ├── Dockerfile │ ├── README.md │ ├── cloudbuild.yaml │ ├── code-examples │ │ ├── genai_examples.py │ │ ├── ollama_examples.py │ │ └── openai_examples.py │ ├── converter.go │ ├── converter_test.go │ ├── go.mod │ ├── proxy.go │ ├── proxy_test.go │ └── start_script.sh ├── PaliGemma-on-Android │ ├── Android_App │ │ └── PaliGemma │ │ │ ├── .gitignore │ │ │ ├── app │ │ │ ├── .gitignore │ │ │ ├── build.gradle.kts │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ ├── androidTest │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── paligemma │ │ │ │ │ └── ExampleInstrumentedTest.kt │ │ │ │ ├── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── paligemma │ │ │ │ │ │ ├── data │ │ │ │ │ │ ├── CoordinatesModel.kt │ │ │ │ │ │ ├── CoordinatesModelApi.kt │ │ │ │ │ │ ├── CoordinatesModelRepo.kt │ │ │ │ │ │ ├── CoordinatesModelRepoImpl.kt │ │ │ │ │ │ ├── InputStreamRequestBody.kt │ │ │ │ │ │ ├── RequestModel.kt │ │ │ │ │ │ └── Result.kt │ │ │ │ │ │ ├── presentation │ │ │ │ │ │ ├── CoordinatesModelViewModel.kt │ │ │ │ │ │ ├── MainActivity.kt │ │ │ │ │ │ └── UiState.kt │ │ │ │ │ │ └── ui │ │ │ │ │ │ └── theme │ │ │ │ │ │ ├── Color.kt │ │ │ │ │ │ ├── Theme.kt │ │ │ │ │ │ └── Type.kt │ │ │ │ └── res │ │ │ │ │ ├── drawable │ │ │ │ │ ├── ic_launcher_background.xml │ │ │ │ │ ├── ic_launcher_foreground.xml │ │ │ │ │ └── paligemma_icon.jpg │ │ │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ │ ├── ic_launcher.xml │ │ │ │ │ └── ic_launcher_round.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ └── ic_launcher_round.webp │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ └── ic_launcher_round.webp │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ └── ic_launcher_round.webp │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ └── ic_launcher_round.webp │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ ├── ic_launcher.webp │ │ │ │ │ └── ic_launcher_round.webp │ │ │ │ │ ├── values │ │ │ │ │ ├── colors.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ └── themes.xml │ │ │ │ │ └── xml │ │ │ │ │ ├── backup_rules.xml │ │ │ │ │ ├── data_extraction_rules.xml │ │ │ │ │ └── path_provider.xml │ │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── paligemma │ │ │ │ └── ExampleUnitTest.kt │ │ │ ├── build.gradle.kts │ │ │ ├── gradle.properties │ │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── gradlew │ │ │ ├── gradlew.bat │ │ │ ├── paligemma.apk │ │ │ └── settings.gradle.kts │ ├── Python_Server │ │ ├── README.md │ │ ├── apiserver │ │ │ ├── api │ │ │ │ ├── __init__.py │ │ │ │ ├── admin.py │ │ │ │ ├── apps.py │ │ │ │ ├── migrations │ │ │ │ │ ├── 0001_initial.py │ │ │ │ │ └── __init__.py │ │ │ │ ├── models.py │ │ │ │ ├── schemas.py │ │ │ │ ├── test.py │ │ │ │ ├── tests.py │ │ │ │ ├── urls.py │ │ │ │ └── views.py │ │ │ ├── apiserver │ │ │ │ ├── __init__.py │ │ │ │ ├── asgi.py │ │ │ │ ├── media │ │ │ │ │ └── images │ │ │ │ │ │ └── image.jpg │ │ │ │ ├── settings.py │ │ │ │ ├── urls.py │ │ │ │ └── wsgi.py │ │ │ └── manage.py │ │ └── requirements.txt │ ├── README.md │ └── assets │ │ ├── paligemma-android-hf1.gif │ │ ├── paligemma-android-hf2.gif │ │ ├── paligemma-android-segmentation.gif │ │ └── paligemma_android_hf_pipeline.png ├── PaliGemma2-on-Web │ ├── README.md │ ├── assets │ │ ├── paligemma2-onnx-output.gif │ │ └── paligemma2-onnx-pipeline.png │ ├── package.json │ ├── public │ │ ├── index.html │ │ ├── script.js │ │ └── style.css │ └── server.js ├── README.md ├── business-email-assistant │ ├── LICENSE │ ├── README.md │ ├── email-processing-webapp │ │ ├── app.py │ │ ├── data │ │ │ └── email-001.txt │ │ ├── models │ │ │ ├── __init__.py │ │ │ ├── gemini.py │ │ │ └── gemma.py │ │ ├── run_app.sh │ │ ├── static │ │ │ ├── css │ │ │ │ └── style.css │ │ │ └── js │ │ │ │ └── script.js │ │ ├── templates │ │ │ └── index.html │ │ ├── tests │ │ │ ├── gemma_generate.sh │ │ │ └── web_app_test.sh │ │ └── weights │ │ │ ├── gemma2-2b_inquiry_tuned.lora.h5 │ │ │ └── readme.txt │ ├── installation.sh │ ├── model-tuning │ │ ├── README.md │ │ ├── data │ │ │ ├── record_1.json │ │ │ ├── record_2.json │ │ │ ├── record_3.json │ │ │ ├── record_4.json │ │ │ ├── record_4_2.json │ │ │ ├── record_5.json │ │ │ ├── record_5_2.json │ │ │ ├── record_6.json │ │ │ └── record_7.json.removed │ │ ├── deploy_weights.sh │ │ ├── main.py │ │ ├── notebook │ │ │ └── bakery_inquiry_model_tuned_with_gemma.ipynb │ │ ├── test_model.sh │ │ ├── tune_model.sh │ │ └── weights │ │ │ └── tuning-output-readme.txt │ ├── requirements.txt │ └── setup_python.sh ├── personal-code-assistant │ ├── README.md │ ├── gemma-web-service │ │ ├── README.md │ │ ├── gemma_service │ │ │ ├── gemma_model.py │ │ │ └── gemma_service_main.py │ │ ├── installation.sh │ │ ├── requirements.txt │ │ ├── run_service.sh │ │ ├── setup_python.sh │ │ └── tests │ │ │ ├── test_generation.sh │ │ │ └── test_post.sh │ └── pipet-code-agent-2 │ │ ├── .eslintrc.json │ │ ├── README.md │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── src │ │ ├── comments.ts │ │ ├── extension.ts │ │ ├── models │ │ │ ├── gemini-api.ts │ │ │ └── gemma-service.ts │ │ ├── question.ts │ │ ├── review.ts │ │ └── utility │ │ │ └── commentChar.ts │ │ └── tsconfig.json └── spoken-language-tasks │ ├── LICENSE │ ├── installation.sh │ ├── k-gemma-it │ ├── README.md │ ├── deploy_weights.sh │ ├── main.py │ ├── spoken_language_tasks_with_gemma.ipynb │ ├── tune_model.sh │ └── weights │ │ └── tuning-output-readme.txt │ ├── k-mail-replier │ ├── README.md │ ├── k_mail_replier │ │ ├── __init__.py │ │ ├── app.py │ │ ├── data │ │ │ ├── email-001-ko.txt │ │ │ └── email-001.txt │ │ ├── models │ │ │ ├── __init__.py │ │ │ ├── gemini.py │ │ │ └── gemma.py │ │ ├── static │ │ │ ├── css │ │ │ │ └── style.css │ │ │ └── js │ │ │ │ └── script.js │ │ ├── templates │ │ │ └── index.html │ │ └── weights │ │ │ └── gemma2-2b_k-tuned.lora.h5 │ ├── run_flask_app.sh │ └── tests │ │ ├── __init__.py │ │ └── gemma_generate.sh │ ├── requirements.txt │ └── setup_python.sh ├── Gemma ├── README.md ├── [Gemma_1]Advanced_Prompting_Techniques.ipynb ├── [Gemma_1]Basics_with_HF.ipynb ├── [Gemma_1]Common_use_cases.ipynb ├── [Gemma_1]Finetune_distributed.ipynb ├── [Gemma_1]Finetune_with_LLaMA_Factory.ipynb ├── [Gemma_1]Finetune_with_XTuner.ipynb ├── [Gemma_1]Inference_on_TPU.ipynb ├── [Gemma_1]Minimal_RAG.ipynb ├── [Gemma_1]RAG_with_ChromaDB.ipynb ├── [Gemma_1]Using_with_Ollama.ipynb ├── [Gemma_1]Using_with_OneTwo.ipynb ├── [Gemma_1]data_parallel_inference_in_jax_tpu.ipynb ├── [Gemma_2]Agentic_AI.ipynb ├── [Gemma_2]Aligning_DPO.ipynb ├── [Gemma_2]Constrained_generation.ipynb ├── [Gemma_2]Custom_Vocabulary.ipynb ├── [Gemma_2]Deploy_in_Vertex_AI.ipynb ├── [Gemma_2]Deploy_with_vLLM.ipynb ├── [Gemma_2]Finetune_with_Axolotl.ipynb ├── [Gemma_2]Finetune_with_CALM.ipynb ├── [Gemma_2]Finetune_with_Function_Calling.ipynb ├── [Gemma_2]Finetune_with_JORA.ipynb ├── [Gemma_2]Finetune_with_LitGPT.ipynb ├── [Gemma_2]Finetune_with_Torch_XLA.ipynb ├── [Gemma_2]Finetune_with_Unsloth.ipynb ├── [Gemma_2]Function_Calling_with_Groq_Langchain.ipynb ├── [Gemma_2]Game_Design_Brainstorming.ipynb ├── [Gemma_2]Gradio_Chatbot.ipynb ├── [Gemma_2]Guess_the_word.ipynb ├── [Gemma_2]Keras_Quickstart.ipynb ├── [Gemma_2]Keras_Quickstart_Chat.ipynb ├── [Gemma_2]LangChain_chaining.ipynb ├── [Gemma_2]Prompt_chaining.ipynb ├── [Gemma_2]RAG_LlamaIndex.ipynb ├── [Gemma_2]RAG_PDF_Search_in_multiple_documents_on_Colab.ipynb ├── [Gemma_2]Synthetic_data_generation.ipynb ├── [Gemma_2]Translator_of_Old_Korean_Literature.ipynb ├── [Gemma_2]Using_Gemini_and_Gemma_with_RouteLLM.ipynb ├── [Gemma_2]Using_with_Elasticsearch_and_LangChain.ipynb ├── [Gemma_2]Using_with_Firebase_Genkit_and_Ollama.ipynb ├── [Gemma_2]Using_with_LLM_Comparator.ipynb ├── [Gemma_2]Using_with_LangChain.ipynb ├── [Gemma_2]Using_with_Langfun_and_LlamaCpp.ipynb ├── [Gemma_2]Using_with_Langfun_and_LlamaCpp_Python_Bindings.ipynb ├── [Gemma_2]Using_with_LlamaCpp.ipynb ├── [Gemma_2]Using_with_Llamafile.ipynb ├── [Gemma_2]Using_with_LocalGemma.ipynb ├── [Gemma_2]Using_with_Mesop.ipynb ├── [Gemma_2]Using_with_Ollama_Python.ipynb ├── [Gemma_2]Using_with_SGLang.ipynb ├── [Gemma_2]Using_with_Xinference.ipynb ├── [Gemma_2]Using_with_mistral_rs.ipynb ├── [Gemma_2]evaluation.ipynb ├── [Gemma_2]for_Japan_using_Transformers_and_PyTorch.ipynb ├── [Gemma_2]on_Groq.ipynb ├── [Gemma_3]Activation_Hacking.ipynb ├── [Gemma_3]Function_Calling_with_HF.ipynb ├── [Gemma_3]Function_Calling_with_HF_document_summarizer.ipynb ├── [Gemma_3]Inference_images_and_videos.ipynb ├── [Gemma_3]Local_Agentic_RAG.ipynb ├── [Gemma_3]Meme_Generator.ipynb ├── [Gemma_3]Using_with_Ollama_Python_Inference_with_Images.ipynb └── [Gemma_3]Using_with_Transformersjs.ipynb ├── LICENSE.txt ├── PaliGemma ├── README.md ├── [PaliGemma_1]Common_use_cases.ipynb ├── [PaliGemma_1]Finetune_with_Keras.ipynb ├── [PaliGemma_1]Finetune_with_image_captioning.ipynb ├── [PaliGemma_1]Finetune_with_image_description.ipynb ├── [PaliGemma_1]Finetune_with_object_detection.ipynb ├── [PaliGemma_1]Image_captioning.ipynb ├── [PaliGemma_1]Referring_expression_segmentation_in_images.ipynb ├── [PaliGemma_1]Referring_expression_segmentation_in_videos.ipynb ├── [PaliGemma_1]Using_with_Mesop.ipynb ├── [PaliGemma_1]Zero_shot_object_detection_in_images.ipynb ├── [PaliGemma_1]Zero_shot_object_detection_in_videos.ipynb ├── [PaliGemma_2]Convert_PaliGemma2_to_ONNX.ipynb ├── [PaliGemma_2]Finetune_with_JAX.ipynb ├── [PaliGemma_2]Finetune_with_Keras.ipynb ├── [PaliGemma_2]Inference_PaliGemma2_with_Transformers_js.ipynb ├── [PaliGemma_2]Keras_Quickstart.ipynb └── [PaliGemma_2]Using_with_Transformersjs.ipynb ├── README.md ├── TxGemma ├── README.md ├── [TxGemma]Agentic_Demo_with_Hugging_Face.ipynb ├── [TxGemma]Finetune_with_Hugging_Face.ipynb ├── [TxGemma]Quickstart_with_Hugging_Face.ipynb └── [TxGemma]Quickstart_with_Model_Garden.ipynb └── Workshops ├── README.md ├── Workshop_How_to_Fine_tuning_Gemma.ipynb ├── Workshop_How_to_Fine_tuning_Gemma_Transformers_Edition.ipynb ├── [Gemma_1]Self_extend.ipynb ├── [Gemma_2]control_vectors.ipynb └── jetson-nano.md /.allstar/binary_artifacts.yaml: -------------------------------------------------------------------------------- 1 | # Ignore reason: gradele jar file is used to build example Android app 2 | ignorePaths: 3 | - Demos/Gemma-on-Android/Android_App/gradle/wrapper/gradle-wrapper.jar 4 | - Demos/PaliGemma-on-Android/Android_App/PaliGemma/gradle/wrapper/gradle-wrapper.jar 5 | -------------------------------------------------------------------------------- /.github/labeler.yml: -------------------------------------------------------------------------------- 1 | 'status:awaiting review': 2 | - '**/*' -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | name: "PR Labeler" 2 | 3 | on: 4 | pull_request_target: 5 | types: ["opened", "reopened", "ready_for_review"] 6 | 7 | jobs: 8 | triage: 9 | permissions: 10 | contents: read 11 | pull-requests: write 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/labeler@v4 15 | if: ${{ github.event.pull_request.draft == false }} -------------------------------------------------------------------------------- /.github/workflows/notebooks.yaml: -------------------------------------------------------------------------------- 1 | # Notebook-related checks 2 | 3 | name: Notebooks 4 | 5 | on: 6 | # Relevant PRs 7 | pull_request: 8 | paths: 9 | - "**.ipynb" 10 | # Allow manual runs 11 | workflow_dispatch: 12 | 13 | jobs: 14 | # Format all notebooks. 15 | nbfmt: 16 | name: Notebook format 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: actions/checkout@v3 20 | - uses: actions/setup-python@v4 21 | - name: Install tensorflow-docs 22 | run: python3 -m pip install -U git+https://github.com/tensorflow/docs 23 | - name: Fetch main branch 24 | run: git fetch -u origin main:main 25 | - name: Check notebook formatting 26 | run: | 27 | if [ "${{ github.event_name }}" == "pull_request" ]; then 28 | # Only check notebooks modified in this pull request 29 | readarray -t changed_notebooks < <(git diff --name-only main --diff-filter="d" | grep '\.ipynb$' || true) 30 | else 31 | # Manual run, check everything 32 | readarray -t changed_notebooks < <(find -name '*.ipynb') 33 | fi 34 | if [[ ${#changed_notebooks[@]} == 0 ]]; then 35 | echo "No notebooks modified in this pull request." 36 | exit 0 37 | else 38 | echo "Check formatting with nbfmt:" 39 | python3 -m tensorflow_docs.tools.nbfmt --test "${changed_notebooks[@]}" 40 | fi 41 | 42 | nblint: 43 | name: Notebook lint 44 | runs-on: ubuntu-latest 45 | steps: 46 | - uses: actions/checkout@v3 47 | - uses: actions/setup-python@v4 48 | - name: Install tensorflow-docs 49 | run: python3 -m pip install -U git+https://github.com/tensorflow/docs 50 | - name: Fetch main branch 51 | run: git fetch -u origin main:main 52 | 53 | # Lint for all notebooks 54 | - name: Lint notebooks 55 | run: | 56 | if [ "${{ github.event_name }}" == "pull_request" ]; then 57 | # Only check notebooks modified in this pull request 58 | readarray -t changed_notebooks < <(git diff --name-only main --diff-filters="d" -- ":(exclude)TxGemma/" | grep '\.ipynb$' || true) 59 | else 60 | # Manual run, check everything 61 | readarray -t changed_notebooks < <(find . -name '*.ipynb') 62 | fi 63 | if [[ ${#changed_notebooks[@]} == 0 ]]; then 64 | echo "No website notebooks modified in this pull request." 65 | exit 0 66 | else 67 | echo "WARNING: If the button_colab check fails for you, make sure you have " 68 | echo "Lint check with nblint:" 69 | python3 -m tensorflow_docs.tools.nblint \ 70 | --styles=google,tensorflow \ 71 | --arg=repo:google-gemini/gemma-cookbook \ 72 | --arg=branch:main \ 73 | --exclude_lint=tensorflow::button_download \ 74 | --exclude_lint=tensorflow::button_website \ 75 | --arg=base_url:https://ai.google.dev/ \ 76 | --exclude_lint=tensorflow::button_github \ 77 | --exclude_lint=google::second_person \ 78 | "${changed_notebooks[@]}" 79 | fi 80 | 81 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | # This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time. 2 | # 3 | # You can adjust the behavior by modifying this file. 4 | # For more information, see: 5 | # https://github.com/actions/stale 6 | name: Mark stale issues and pull requests 7 | 8 | on: 9 | schedule: 10 | # Scheduled to run at 1.30 UTC everyday 11 | - cron: '30 1 * * *' 12 | 13 | jobs: 14 | stale: 15 | 16 | runs-on: ubuntu-latest 17 | permissions: 18 | issues: write 19 | pull-requests: write 20 | 21 | steps: 22 | - uses: actions/stale@v5 23 | with: 24 | repo-token: ${{ secrets.GITHUB_TOKEN }} 25 | days-before-issue-stale: 14 26 | days-before-issue-close: 14 27 | stale-issue-label: "status:stale" 28 | close-issue-reason: not_planned 29 | any-of-labels: "status:awaiting user response,status:more data needed" 30 | stale-issue-message: > 31 | Marking this issue as stale since it has been open for 14 days with no activity. 32 | This issue will be closed if no further activity occurs. 33 | close-issue-message: > 34 | This issue was closed because it has been inactive for 28 days. 35 | Please post a new issue if you need further assistance. Thanks! 36 | days-before-pr-stale: 14 37 | days-before-pr-close: 14 38 | stale-pr-label: "status:stale" 39 | stale-pr-message: > 40 | Marking this pull request as stale since it has been open for 14 days with no activity. 41 | This PR will be closed if no further activity occurs. 42 | close-pr-message: > 43 | This pull request was closed because it has been inactive for 28 days. 44 | Please open a new pull request if you need further assistance. Thanks! 45 | # Label that can be assigned to issues to exclude them from being marked as stale 46 | exempt-issue-labels: 'override-stale' 47 | # Label that can be assigned to PRs to exclude them from being marked as stale 48 | exempt-pr-labels: "override-stale" 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a Python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | coverage.xml 45 | *.cover 46 | *.py,cover 47 | .cache 48 | nosetests.xml 49 | coverage/ 50 | *.cover 51 | .hypothesis/ 52 | 53 | # Pytest cache 54 | .pytest_cache/ 55 | .cache/ 56 | 57 | # MyPy cache 58 | .mypy_cache/ 59 | 60 | # Profiling data 61 | *.lprof 62 | .prof 63 | 64 | # Virtual environment directories 65 | venv/ 66 | ENV/ 67 | env/ 68 | .venv/ 69 | env.bak/ 70 | venv.bak/ 71 | 72 | # Jupyter Notebook checkpoints 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # Editor directories and files 79 | .vscode/ 80 | .idea/ 81 | *.swp 82 | *.swo 83 | *~ 84 | 85 | # macOS system files 86 | .DS_Store 87 | 88 | # Temporary files 89 | *.tmp 90 | *.log 91 | *.bak 92 | *.orig 93 | 94 | # Local development overrides 95 | .local/ 96 | .env 97 | 98 | # Docker-related files 99 | docker-compose.override.yml 100 | 101 | *.pyc 102 | k-gemma-it/.env 103 | k-gemma-it/weights/*.h5 104 | k-mail-replier/k_mail_replier/.env 105 | k-mail-replier/k_mail_replier/weights/*.backup 106 | venv/ 107 | Gemma/personal-code-assistant/gemma-web-service/.env 108 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to the Gemma Cookbook 2 | 3 | We would love to accept your patches and contributions to the Gemma Cookbook. We are excited that you are considering donating some of your time, and this guide will help us be respectful of that time. 4 | 5 | # Before you send anything 6 | 7 | ## Sign our contributor agreement 8 | 9 | All contributions to this project must be accompanied by a [Contributor License Agreement](https://cla.developers.google.com/about) (CLA). You (or your employer) retain the copyright to your contribution; this simply gives us permission to use and redistribute your contributions as part of the project. 10 | 11 | If you or your current employer have already signed the Google CLA (even if it was for a different project), you probably don't need to do it again. 12 | 13 | Visit [https://cla.developers.google.com/](https://cla.developers.google.com/) to see your current agreements or to sign a new one. 14 | 15 | ## Style guides 16 | 17 | Before you start writing, take a look at the [technical writing style guide](https://developers.google.com/style). You don’t need to fully digest the whole document, but do read the [highlights](https://developers.google.com/style/highlights) so you can anticipate the most common feedback. 18 | 19 | Also check out the relevant [style guide](https://google.github.io/styleguide/) for the language you will be using. These apply strictly to raw code files (e.g. *.py, *.js), though code fragments in documentation (such as markdown files or notebooks) tend to favor readability over strict adherence. 20 | 21 | # PR checklist 22 | 23 | 1. Commit your finished notebook with comments and clean output after finishing the following: 24 | * Make sure to include the setup steps at the top (you can copy from any existing notebook), including: 25 | * the Colab self-link to your notebook 26 | * how to select GPU 27 | * how to set up Kaggle/HF tokens 28 | * Include a byline at the top of the notebook with your name, social handle and/or GitHub username 29 | * Run ‘nbfmt’ and 'nblint' for formatting and linting ([reference](.github/workflows/notebooks.yaml)) 30 | * Name your notebook with words separated by underscores. For example, ‘Integrate_with_Mesop.ipynb’ 31 | 2. Add the notebook name and a short description in the table of contents in README.md 32 | 3. (If applicable) remove the entry you have implemented in WISHLIST.md 33 | 4. Submit for review 34 | 5. In your PR comment, let us know if you would like your contribution to be highlighted in Google’s social handle (e.g., [Google for Developers](https://x.com/googledevs?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor) Twitter) 35 | 36 | # Making changes 37 | 38 | ## Small fixes 39 | 40 | Small fixes, such as typos or bug fixes, can be submitted directly via a pull request. 41 | 42 | ## Large changes or a new notebook 43 | 44 | Before you send a PR, or even write a single line, please file an [issue](https://github.com/google-gemini/gemma-cookbook/issues). There we can discuss the request and provide guidance about how to structure any content you write. 45 | 46 | Adding a new guide often involves lots of detailed reviews and we want to make sure that your idea is fully formed and has full support before you start writing anything. Please also check the table of contents first to avoid duplicating existing work. If you want to port an existing guide across (e.g. if you have a guide for Gemma on your own GitHub), feel free to link to it in the issue. 47 | 48 | ## Things we consider 49 | 50 | When accepting a new guide, we want to balance a few aspects: 51 | * Originality - e.g. Is there another guide that does the same thing? 52 | * Pedagogy - e.g. Does this guide teach something useful? Specifically for a Gemma feature? 53 | * Quality - e.g. Does this guide contain clear, descriptive prose? Is the code easy to understand? Is there any error? 54 | * Practicality - e.g., Is the technique used in the guide practical in the real world? 55 | 56 | It is not crucial for a submission to be strong along all of these dimensions, but the stronger the better. Old submissions may be replaced in favor of newer submissions that exceed these properties. 57 | -------------------------------------------------------------------------------- /CodeGemma/README.md: -------------------------------------------------------------------------------- 1 | # CodeGemma 2 | 3 | This folder is organized into several categories, each focusing on a specific aspect of working with CodeGemma models: 4 | 5 | * [Inference](#inference): How to load and run CodeGemma for inference 6 | * [Finetuning](#finetuning): Dive into finetuning CodeGemma models for specific tasks and domains 7 | 8 | ## Inference 9 | | Notebook Name | Description | 10 | | :--------------------------------------------------------------------------------------------- | ------------------------------------------------ | 11 | | [[CodeGemma_1]Common_use_cases.ipynb]([CodeGemma_1]Common_use_cases.ipynb) | Illustrate some common use cases for CodeGemma . | 12 | 13 | ## Finetuning 14 | | Notebook Name | Description | 15 | | :--------------------------------------------------------------------------------------------- | ------------------------------------------------ | 16 | | [[CodeGemma_1]Finetune_with_SQL.ipynb]([CodeGemma_1]Finetune_with_SQL.ipynb) | Fine-Tuning CodeGemma on the SQL Spider Dataset. | 17 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("org.jetbrains.kotlin.android") 4 | } 5 | 6 | android { 7 | namespace = "com.example.scigemma" 8 | compileSdk = 34 9 | 10 | defaultConfig { 11 | applicationId = "com.example.scigemma" 12 | minSdk = 24 13 | targetSdk = 34 14 | versionCode = 1 15 | versionName = "1.0" 16 | 17 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 18 | vectorDrawables { 19 | useSupportLibrary = true 20 | } 21 | } 22 | 23 | buildTypes { 24 | release { 25 | isMinifyEnabled = false 26 | proguardFiles( 27 | getDefaultProguardFile("proguard-android-optimize.txt"), 28 | "proguard-rules.pro" 29 | ) 30 | } 31 | } 32 | compileOptions { 33 | sourceCompatibility = JavaVersion.VERSION_1_8 34 | targetCompatibility = JavaVersion.VERSION_1_8 35 | } 36 | kotlinOptions { 37 | jvmTarget = "1.8" 38 | } 39 | buildFeatures { 40 | compose = true 41 | } 42 | composeOptions { 43 | kotlinCompilerExtensionVersion = "1.5.1" 44 | } 45 | packaging { 46 | resources { 47 | excludes += "/META-INF/{AL2.0,LGPL2.1}" 48 | } 49 | } 50 | } 51 | 52 | dependencies { 53 | 54 | implementation("androidx.core:core-ktx:1.12.0") 55 | implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0") 56 | implementation("androidx.activity:activity-compose:1.8.2") 57 | implementation("androidx.navigation:navigation-compose:2.7.7") 58 | implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0") 59 | implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0") 60 | 61 | implementation(platform("androidx.compose:compose-bom:2024.02.00")) 62 | implementation("androidx.compose.ui:ui") 63 | implementation("androidx.compose.ui:ui-graphics") 64 | implementation("androidx.compose.ui:ui-tooling-preview") 65 | implementation("androidx.compose.material3:material3") 66 | 67 | implementation ("com.google.mediapipe:tasks-genai:0.10.14") 68 | 69 | 70 | testImplementation("junit:junit:4.13.2") 71 | androidTestImplementation("androidx.test.ext:junit:1.1.5") 72 | androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") 73 | androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00")) 74 | androidTestImplementation("androidx.compose.ui:ui-test-junit4") 75 | debugImplementation("androidx.compose.ui:ui-tooling") 76 | debugImplementation("androidx.compose.ui:ui-test-manifest") 77 | } 78 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/androidTest/java/com/example/scigemma/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.scigemma 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.example.scigemma", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 15 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/java/com/example/scigemma/ChatMessage.kt: -------------------------------------------------------------------------------- 1 | package com.example.scigemma 2 | 3 | import java.util.UUID 4 | 5 | /** 6 | * Used to represent a ChatMessage 7 | */ 8 | data class ChatMessage( 9 | val id: String = UUID.randomUUID().toString(), 10 | val message: String = "", 11 | val author: String, 12 | val isLoading: Boolean = false 13 | ) { 14 | val isFromUser: Boolean 15 | get() = author == USER_PREFIX 16 | } 17 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/java/com/example/scigemma/ChatViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.example.scigemma 2 | 3 | import android.content.Context 4 | import androidx.lifecycle.ViewModel 5 | import androidx.lifecycle.ViewModelProvider 6 | import androidx.lifecycle.viewModelScope 7 | import androidx.lifecycle.viewmodel.CreationExtras 8 | import kotlinx.coroutines.Dispatchers 9 | import kotlinx.coroutines.flow.MutableStateFlow 10 | import kotlinx.coroutines.flow.StateFlow 11 | import kotlinx.coroutines.flow.asStateFlow 12 | import kotlinx.coroutines.flow.collectIndexed 13 | import kotlinx.coroutines.launch 14 | 15 | class ChatViewModel( 16 | private val inferenceModel: InferenceModel 17 | ) : ViewModel() { 18 | 19 | // `GemmaUiState()` is optimized for the Gemma model. 20 | // Replace `GemmaUiState` with `ChatUiState()` if you're using a different model 21 | private val _uiState: MutableStateFlow = MutableStateFlow(GemmaUiState()) 22 | val uiState: StateFlow = 23 | _uiState.asStateFlow() 24 | 25 | private val _textInputEnabled: MutableStateFlow = 26 | MutableStateFlow(true) 27 | val isTextInputEnabled: StateFlow = 28 | _textInputEnabled.asStateFlow() 29 | 30 | fun sendMessage(userMessage: String) { 31 | viewModelScope.launch(Dispatchers.IO) { 32 | _uiState.value.addMessage(userMessage, USER_PREFIX) 33 | var currentMessageId: String? = _uiState.value.createLoadingMessage() 34 | setInputEnabled(false) 35 | try { 36 | val fullPrompt = _uiState.value.fullPrompt 37 | inferenceModel.generateResponseAsync(fullPrompt) 38 | inferenceModel.partialResults 39 | .collectIndexed { index, (partialResult, done) -> 40 | currentMessageId?.let { 41 | if (index == 0) { 42 | _uiState.value.appendFirstMessage(it, partialResult) 43 | } else { 44 | _uiState.value.appendMessage(it, partialResult, done) 45 | } 46 | if (done) { 47 | currentMessageId = null 48 | // Re-enable text input 49 | setInputEnabled(true) 50 | } 51 | } 52 | } 53 | } catch (e: Exception) { 54 | _uiState.value.addMessage(e.localizedMessage ?: "Unknown Error", MODEL_PREFIX) 55 | setInputEnabled(true) 56 | } 57 | } 58 | } 59 | 60 | private fun setInputEnabled(isEnabled: Boolean) { 61 | _textInputEnabled.value = isEnabled 62 | } 63 | 64 | companion object { 65 | fun getFactory(context: Context) = object : ViewModelProvider.Factory { 66 | override fun create(modelClass: Class, extras: CreationExtras): T { 67 | val inferenceModel = InferenceModel.getInstance(context) 68 | return ChatViewModel(inferenceModel) as T 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/java/com/example/scigemma/InferenceModel.kt: -------------------------------------------------------------------------------- 1 | package com.example.scigemma 2 | 3 | import android.content.Context 4 | import com.google.mediapipe.tasks.genai.llminference.LlmInference 5 | import java.io.File 6 | import kotlinx.coroutines.channels.BufferOverflow 7 | import kotlinx.coroutines.flow.MutableSharedFlow 8 | import kotlinx.coroutines.flow.SharedFlow 9 | import kotlinx.coroutines.flow.asSharedFlow 10 | 11 | class InferenceModel private constructor(context: Context) { 12 | private var llmInference: LlmInference 13 | 14 | private val modelExists: Boolean 15 | get() = File(MODEL_PATH).exists() 16 | 17 | private val _partialResults = MutableSharedFlow>( 18 | extraBufferCapacity = 1, 19 | onBufferOverflow = BufferOverflow.DROP_OLDEST 20 | ) 21 | val partialResults: SharedFlow> = _partialResults.asSharedFlow() 22 | 23 | init { 24 | if (!modelExists) { 25 | throw IllegalArgumentException("Model not found at path: $MODEL_PATH") 26 | } 27 | 28 | val options = LlmInference.LlmInferenceOptions.builder() 29 | .setModelPath(MODEL_PATH) 30 | .setMaxTokens(1024) 31 | .setResultListener { partialResult, done -> 32 | _partialResults.tryEmit(partialResult to done) 33 | } 34 | .build() 35 | 36 | llmInference = LlmInference.createFromOptions(context, options) 37 | } 38 | 39 | fun generateResponseAsync(prompt: String) { 40 | llmInference.generateResponseAsync(prompt) 41 | } 42 | 43 | companion object { 44 | private const val MODEL_PATH = "/data/local/tmp/llm/YOUR_MODEL_NAME.bin" 45 | private var instance: InferenceModel? = null 46 | 47 | fun getInstance(context: Context): InferenceModel { 48 | return if (instance != null) { 49 | instance!! 50 | } else { 51 | InferenceModel(context).also { instance = it } 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/java/com/example/scigemma/LoadingScreen.kt: -------------------------------------------------------------------------------- 1 | package com.example.scigemma 2 | 3 | import androidx.compose.foundation.layout.Arrangement 4 | import androidx.compose.foundation.layout.Box 5 | import androidx.compose.foundation.layout.Column 6 | import androidx.compose.foundation.layout.padding 7 | import androidx.compose.material3.CircularProgressIndicator 8 | import androidx.compose.material3.MaterialTheme 9 | import androidx.compose.material3.Text 10 | import androidx.compose.runtime.Composable 11 | import androidx.compose.runtime.LaunchedEffect 12 | import androidx.compose.runtime.getValue 13 | import androidx.compose.runtime.mutableStateOf 14 | import androidx.compose.runtime.remember 15 | import androidx.compose.runtime.setValue 16 | import androidx.compose.ui.Alignment 17 | import androidx.compose.ui.Modifier 18 | import androidx.compose.ui.platform.LocalContext 19 | import androidx.compose.ui.res.stringResource 20 | import androidx.compose.ui.text.style.TextAlign 21 | import androidx.compose.ui.unit.dp 22 | import androidx.compose.ui.graphics.Color 23 | import kotlinx.coroutines.Dispatchers 24 | import kotlinx.coroutines.withContext 25 | 26 | @Composable 27 | internal fun LoadingRoute( 28 | onModelLoaded: () -> Unit = { } 29 | ) { 30 | val context = LocalContext.current.applicationContext 31 | var errorMessage by remember { mutableStateOf("") } 32 | 33 | if (errorMessage != "") { 34 | ErrorMessage(errorMessage) 35 | } else { 36 | LoadingIndicator() 37 | } 38 | 39 | LaunchedEffect(Unit, block = { 40 | // Create the LlmInference in a separate thread 41 | withContext(Dispatchers.IO) { 42 | try { 43 | InferenceModel.getInstance(context) 44 | // Notify the UI that the model has finished loading 45 | withContext(Dispatchers.Main) { 46 | onModelLoaded() 47 | } 48 | } catch (e: Exception) { 49 | errorMessage = e.localizedMessage ?: "UnknownError" 50 | } 51 | } 52 | }) 53 | } 54 | 55 | @Composable 56 | fun LoadingIndicator() { 57 | Column( 58 | horizontalAlignment = Alignment.CenterHorizontally, 59 | verticalArrangement = Arrangement.Center 60 | ) { 61 | Text( 62 | color = Color(0XFF6A1B9A), 63 | text = "Loading model", 64 | style = MaterialTheme.typography.titleMedium, 65 | modifier = Modifier 66 | .padding(bottom = 8.dp) 67 | ) 68 | CircularProgressIndicator(color = Color(0XFF9575CD)) 69 | } 70 | } 71 | 72 | @Composable 73 | fun ErrorMessage( 74 | errorMessage: String 75 | ) { 76 | Box( 77 | contentAlignment = Alignment.Center 78 | ) { 79 | Text( 80 | text = errorMessage, 81 | color = MaterialTheme.colorScheme.error, 82 | textAlign = TextAlign.Center 83 | ) 84 | } 85 | } -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/java/com/example/scigemma/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.scigemma 2 | 3 | import android.os.Bundle 4 | import androidx.activity.ComponentActivity 5 | import androidx.activity.compose.setContent 6 | import androidx.compose.foundation.background 7 | import androidx.compose.foundation.layout.Box 8 | import androidx.compose.foundation.layout.Column 9 | import androidx.compose.foundation.layout.fillMaxSize 10 | import androidx.compose.foundation.layout.fillMaxWidth 11 | import androidx.compose.foundation.layout.padding 12 | import androidx.compose.material3.ExperimentalMaterial3Api 13 | import androidx.compose.material3.MaterialTheme 14 | import androidx.compose.material3.Scaffold 15 | import androidx.compose.material3.Surface 16 | import androidx.compose.material3.Text 17 | import androidx.compose.material3.TopAppBar 18 | import androidx.compose.material3.TopAppBarDefaults 19 | import androidx.compose.runtime.Composable 20 | import androidx.compose.ui.Modifier 21 | import androidx.compose.ui.res.stringResource 22 | import androidx.compose.ui.text.style.TextAlign 23 | import androidx.compose.ui.unit.dp 24 | import androidx.compose.ui.graphics.Color 25 | import androidx.navigation.compose.NavHost 26 | import androidx.navigation.compose.composable 27 | import androidx.navigation.compose.rememberNavController 28 | import com.example.scigemma.ui.theme.SciGemmaTheme 29 | 30 | const val START_SCREEN = "start_screen" 31 | const val CHAT_SCREEN = "chat_screen" 32 | 33 | class MainActivity : ComponentActivity() { 34 | override fun onCreate(savedInstanceState: Bundle?) { 35 | super.onCreate(savedInstanceState) 36 | setContent { 37 | SciGemmaTheme { 38 | Scaffold( 39 | topBar = { AppBar() } 40 | ) { innerPadding -> 41 | // A surface container using the 'background' color from the theme 42 | Surface( 43 | modifier = Modifier 44 | .fillMaxSize() 45 | .padding(innerPadding), 46 | color = Color.White, 47 | ) { 48 | val navController = rememberNavController() 49 | 50 | NavHost( 51 | navController = navController, 52 | startDestination = START_SCREEN 53 | ) { 54 | composable(START_SCREEN) { 55 | LoadingRoute( 56 | onModelLoaded = { 57 | navController.navigate(CHAT_SCREEN) { 58 | popUpTo(START_SCREEN) { inclusive = true } 59 | launchSingleTop = true 60 | } 61 | } 62 | ) 63 | } 64 | 65 | composable(CHAT_SCREEN) { 66 | ChatRoute() 67 | } 68 | } 69 | } 70 | } 71 | } 72 | } 73 | } 74 | 75 | 76 | @OptIn(ExperimentalMaterial3Api::class) 77 | @Composable 78 | fun AppBar() { 79 | Column( 80 | modifier = Modifier.fillMaxWidth() 81 | ) { 82 | TopAppBar( 83 | title = { Text(stringResource(R.string.app_name)) }, 84 | colors = TopAppBarDefaults.topAppBarColors( 85 | containerColor = Color(0XFF6A1B9A), 86 | titleContentColor = Color(0XFFFFFFFF), 87 | ), 88 | ) 89 | } 90 | } 91 | } 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/java/com/example/scigemma/ui/theme/Color.kt: -------------------------------------------------------------------------------- 1 | package com.example.scigemma.ui.theme 2 | 3 | import androidx.compose.ui.graphics.Color 4 | 5 | val Purple80 = Color(0xFFD0BCFF) 6 | val PurpleGrey80 = Color(0xFFCCC2DC) 7 | val Pink80 = Color(0xFFEFB8C8) 8 | 9 | val Purple40 = Color(0xFF6650a4) 10 | val PurpleGrey40 = Color(0xFF625b71) 11 | val Pink40 = Color(0xFF7D5260) -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/java/com/example/scigemma/ui/theme/Theme.kt: -------------------------------------------------------------------------------- 1 | package com.example.scigemma.ui.theme 2 | 3 | import android.app.Activity 4 | import android.os.Build 5 | import androidx.compose.foundation.isSystemInDarkTheme 6 | import androidx.compose.material3.MaterialTheme 7 | import androidx.compose.material3.darkColorScheme 8 | import androidx.compose.material3.dynamicDarkColorScheme 9 | import androidx.compose.material3.dynamicLightColorScheme 10 | import androidx.compose.material3.lightColorScheme 11 | import androidx.compose.runtime.Composable 12 | import androidx.compose.runtime.SideEffect 13 | import androidx.compose.ui.graphics.Color 14 | import androidx.compose.ui.graphics.toArgb 15 | import androidx.compose.ui.platform.LocalContext 16 | import androidx.compose.ui.platform.LocalView 17 | import androidx.core.view.WindowCompat 18 | 19 | 20 | private val DarkColorScheme = darkColorScheme( 21 | primary = Purple80, 22 | secondary = PurpleGrey80, 23 | tertiary = Pink80 24 | ) 25 | 26 | private val LightColorScheme = lightColorScheme( 27 | primary = Purple40, 28 | secondary = PurpleGrey40, 29 | tertiary = Pink40 30 | 31 | /* Other default colors to override 32 | background = Color(0xFFFFFBFE), 33 | surface = Color(0xFFFFFBFE), 34 | onPrimary = Color.White, 35 | onSecondary = Color.White, 36 | onTertiary = Color.White, 37 | onBackground = Color(0xFF1C1B1F), 38 | onSurface = Color(0xFF1C1B1F), 39 | */ 40 | ) 41 | 42 | @Composable 43 | fun SciGemmaTheme( 44 | darkTheme: Boolean = isSystemInDarkTheme(), 45 | // Dynamic color is available on Android 12+ 46 | dynamicColor: Boolean = true, 47 | content: @Composable () -> Unit 48 | ) { 49 | val colorScheme = when { 50 | dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { 51 | val context = LocalContext.current 52 | if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) 53 | } 54 | 55 | darkTheme -> DarkColorScheme 56 | else -> LightColorScheme 57 | } 58 | val view = LocalView.current 59 | if (!view.isInEditMode) { 60 | SideEffect { 61 | val window = (view.context as Activity).window 62 | window.statusBarColor = Color(0XFFFAFAFA).toArgb() 63 | WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme 64 | } 65 | } 66 | 67 | MaterialTheme( 68 | colorScheme = colorScheme, 69 | typography = Typography, 70 | content = content 71 | ) 72 | } -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/java/com/example/scigemma/ui/theme/Type.kt: -------------------------------------------------------------------------------- 1 | package com.example.scigemma.ui.theme 2 | 3 | import androidx.compose.material3.Typography 4 | import androidx.compose.ui.text.TextStyle 5 | import androidx.compose.ui.text.font.FontFamily 6 | import androidx.compose.ui.text.font.FontWeight 7 | import androidx.compose.ui.unit.sp 8 | 9 | // Set of Material typography styles to start with 10 | val Typography = Typography( 11 | bodyLarge = TextStyle( 12 | fontFamily = FontFamily.Default, 13 | fontWeight = FontWeight.Normal, 14 | fontSize = 16.sp, 15 | lineHeight = 24.sp, 16 | letterSpacing = 0.5.sp 17 | ) 18 | /* Other default text styles to override 19 | titleLarge = TextStyle( 20 | fontFamily = FontFamily.Default, 21 | fontWeight = FontWeight.Normal, 22 | fontSize = 22.sp, 23 | lineHeight = 28.sp, 24 | letterSpacing = 0.sp 25 | ), 26 | labelSmall = TextStyle( 27 | fontFamily = FontFamily.Default, 28 | fontWeight = FontWeight.Medium, 29 | fontSize = 11.sp, 30 | lineHeight = 16.sp, 31 | letterSpacing = 0.5.sp 32 | ) 33 | */ 34 | ) -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/drawable/scigemmaicon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-gemini/gemma-cookbook/a417e7daeecfa7b4cff80c8e5484bc5411eca777/Demos/Gemma-on-Android/Android_App/app/src/main/res/drawable/scigemmaicon.jpg -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-gemini/gemma-cookbook/a417e7daeecfa7b4cff80c8e5484bc5411eca777/Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-gemini/gemma-cookbook/a417e7daeecfa7b4cff80c8e5484bc5411eca777/Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-gemini/gemma-cookbook/a417e7daeecfa7b4cff80c8e5484bc5411eca777/Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-gemini/gemma-cookbook/a417e7daeecfa7b4cff80c8e5484bc5411eca777/Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-gemini/gemma-cookbook/a417e7daeecfa7b4cff80c8e5484bc5411eca777/Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-gemini/gemma-cookbook/a417e7daeecfa7b4cff80c8e5484bc5411eca777/Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-gemini/gemma-cookbook/a417e7daeecfa7b4cff80c8e5484bc5411eca777/Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-gemini/gemma-cookbook/a417e7daeecfa7b4cff80c8e5484bc5411eca777/Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-gemini/gemma-cookbook/a417e7daeecfa7b4cff80c8e5484bc5411eca777/Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-gemini/gemma-cookbook/a417e7daeecfa7b4cff80c8e5484bc5411eca777/Demos/Gemma-on-Android/Android_App/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SciGemma 3 | -------------------------------------------------------------------------------- /Demos/Gemma-on-Android/Android_App/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |