{"id":2821,"date":"2024-11-21T15:07:33","date_gmt":"2024-11-21T15:07:33","guid":{"rendered":"https:\/\/www.aisupersmart.com\/Question-Answer\/question\/using-googles-generative-ai-for-images-in-kotlin\/"},"modified":"2024-11-21T15:07:33","modified_gmt":"2024-11-21T15:07:33","slug":"using-googles-generative-ai-for-images-in-kotlin","status":"publish","type":"question","link":"https:\/\/www.aisupersmart.com\/Question-Answer\/question\/using-googles-generative-ai-for-images-in-kotlin\/","title":{"rendered":"Using Google&#039;s generative AI for images in Kotlin"},"content":{"rendered":"<p>I&#8217;m trying to use Google&#8217;s generative AI in Kotlin in Android Studio, to write an app that gives me information about a photo. So I would like to pass an image and a text to the gemini-1.5-flash API, but I am not succeeding. This is my code:<\/p>\n<pre class=\"lang-kotlin s-code-block\"><code>            lifecycleScope.launch {\r\n                <span>val<\/span> prompt = arrayOf(\r\n                    Content.Image(selectedImageBitmap),\r\n                    <span>\"What is in this photo?\"<\/span>)\r\n                <span>val<\/span> response = withContext(Dispatchers.IO) {\r\n                    generativeModel.generateContent(prompt)\r\n                }\r\n                withContext(Dispatchers.Main) {\r\n                    OutputValue = response.text\r\n                    myTextOutput.text = OutputValue\r\n                }\r\n            }\r\n<\/code><\/pre>\n<p>selectedImageBitmap is a bitmap object.<\/p>\n<p>In build.grandle.kts file, I&#8217;ve added the dependencies:<\/p>\n<pre class=\"lang-kotlin s-code-block\"><code>implementation(<span>\"com.google.ai.client.generativeai:generativeai:0.9.0\"<\/span>)\r\n\r\n<\/code><\/pre>\n<p>And in my MainActivity, I&#8217;ve added the import:<\/p>\n<pre class=\"lang-kotlin s-code-block\"><code><span>import<\/span> com.google.ai.client.generativeai.GenerativeModel\r\n\r\n<\/code><\/pre>\n<p>I have the following error: Unresolved reference: Content.<\/p>\n<p>That means, the compiler cannot find the definition of &#8216;Content.<\/p>\n<p>What&#8217;s wrong with my code? What do I need to do to get it to work?<\/p>\n<p>I expected generativeModel.generateContent() to easily accept text, images, PDFs, and other input types.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[87],"question_tags":[82],"class_list":["post-2821","question","type-question","status-publish","hentry","question-category-coding","question_tags-coding"],"_links":{"self":[{"href":"https:\/\/www.aisupersmart.com\/Question-Answer\/wp-json\/wp\/v2\/question\/2821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aisupersmart.com\/Question-Answer\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/www.aisupersmart.com\/Question-Answer\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/www.aisupersmart.com\/Question-Answer\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aisupersmart.com\/Question-Answer\/wp-json\/wp\/v2\/comments?post=2821"}],"wp:attachment":[{"href":"https:\/\/www.aisupersmart.com\/Question-Answer\/wp-json\/wp\/v2\/media?parent=2821"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.aisupersmart.com\/Question-Answer\/wp-json\/wp\/v2\/question-category?post=2821"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.aisupersmart.com\/Question-Answer\/wp-json\/wp\/v2\/question_tags?post=2821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}