diff --git a/openai_product_images/README.rst b/openai_product_images/README.rst new file mode 100644 index 000000000..5ea76f5cb --- /dev/null +++ b/openai_product_images/README.rst @@ -0,0 +1,45 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +Generate Product Images Using OpenAI +========== +* Module which helps search image and save that image to product media in ecommerce on the basis of product prompt + +Installation +============ + - www.odoo.com/documentation/14.0/setup/install.html + - Install our custom addon + +License +------- +General Public License, Version 3 (AGPL v3). +(https://www.odoo.com/documentation/user/14.0/legal/licenses/licenses.html) + +Company +------- +* `Cybrosys Techno Solutions `__ + +Credits +------- +* Developer: +LAJINA K V @ cybrosys + +Contacts +-------- +* Mail Contact : odoo@cybrosys.com + +Bug Tracker +----------- +Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. + +Maintainer +========== +This module is maintained by Cybrosys Technologies. + +For support and more information, please visit https://www.cybrosys.com + +Further information +=================== +HTML Description: ``__ + diff --git a/openai_product_images/__init__.py b/openai_product_images/__init__.py new file mode 100644 index 000000000..f00650520 --- /dev/null +++ b/openai_product_images/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: LAJINA K V (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +from . import models +from . import wizard + diff --git a/openai_product_images/__manifest__.py b/openai_product_images/__manifest__.py new file mode 100644 index 000000000..6255ca601 --- /dev/null +++ b/openai_product_images/__manifest__.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: LAJINA K V (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +{ + 'name': 'Generate Product Images Using OpenAI', + 'version': '14.0.1.0.0', + 'category': 'Sales/Sales', + 'summary': 'This module helps to generate images for products using DALL-E.', + 'description': 'Odoo Module for Generating Product Images using DALL-E', + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'images': ['static/description/banner.png'], + 'website': 'https://www.cybrosys.com', + 'depends': ['base', 'product', 'openai_odoo_base','sale'], + 'data': [ + 'security/ir.model.access.csv', + 'views/product_template_views.xml', + 'views/dalle_image_suggestion_views.xml', + 'wizard/image_suggestion_views.xml', + ], + 'license': 'AGPL-3', + 'installable': True, + 'auto_install': False, + 'application': False, +} diff --git a/openai_product_images/doc/RELEASE_NOTES.md b/openai_product_images/doc/RELEASE_NOTES.md new file mode 100644 index 000000000..2040a8914 --- /dev/null +++ b/openai_product_images/doc/RELEASE_NOTES.md @@ -0,0 +1,7 @@ +## Module + +#### 31.03.2023 +#### Version 14.0.1.0.0 +#### ADD +- Initial commit for Generate Product Images Using OpenAI + diff --git a/openai_product_images/models/__init__.py b/openai_product_images/models/__init__.py new file mode 100644 index 000000000..5b1983794 --- /dev/null +++ b/openai_product_images/models/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: LAJINA K V (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +from . import dalle_image_suggestion +from . import product_template diff --git a/openai_product_images/models/dalle_image_suggestion.py b/openai_product_images/models/dalle_image_suggestion.py new file mode 100644 index 000000000..573b8ff6b --- /dev/null +++ b/openai_product_images/models/dalle_image_suggestion.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: LAJINA K V (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +from odoo import fields, models + + +class DalleImageSuggestion(models.Model): + """image for product from dalle and save it as record""" + _name = 'dalle.image.suggestion' + _description = 'model for save image' + _rec_name = 'product_tmpl_id' + + product_image = fields.Binary('Image', attachment=True, + help="filed to store image") + product_tmpl_id = fields.Many2one('product.template', 'Related Product', + help="filed to store product") + + def action_make_as_product_image(self): + """Summary: + Function to make this image as product image + Returns: + returns the product form view image of corresponding product + """ + + self.product_tmpl_id.image_1920 = self.product_image + return { + 'name': self.product_tmpl_id.name, + 'view_mode': 'form', + 'res_model': 'product.template', + 'type': 'ir.actions.act_window', + 'res_id': self.product_tmpl_id.id, + 'domain': [('id', '=', self.product_tmpl_id.id)], + 'target': 'current', + } diff --git a/openai_product_images/models/product_template.py b/openai_product_images/models/product_template.py new file mode 100644 index 000000000..900e201c3 --- /dev/null +++ b/openai_product_images/models/product_template.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: LAJINA K V (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +from odoo import models + + +class ProductTemplate(models.Model): + """To write function for product template buttons """ + + _inherit = 'product.template' + + def action_open_image_prompt_wizard(self): + """Summary: + Function to view image suggestion + Returns: + returns the image of corresponding product + """ + return { + 'name': self.name, + 'view_mode': 'form', + 'res_model': 'image.suggestion', + 'type': 'ir.actions.act_window', + 'target': 'new', + 'context': {'default_product_tmpl_id': self.id}, + } + + def action_get_dall_e_image(self): + """Summary: + Function to view dalle image suggestion + Returns: + returns the created image of corresponding product + """ + return { + 'name': self.name, + 'view_mode': 'tree,form', + 'res_model': 'dalle.image.suggestion', + 'type': 'ir.actions.act_window', + 'domain': [('product_tmpl_id', '=', self.id)], + } diff --git a/openai_product_images/security/ir.model.access.csv b/openai_product_images/security/ir.model.access.csv new file mode 100644 index 000000000..99e65b51d --- /dev/null +++ b/openai_product_images/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_dalle_image_suggestion,access.dalle.image.suggestion,model_dalle_image_suggestion,base.group_user,1,1,1,1 +access_image_suggestion,access.image.suggestion,model_image_suggestion,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/openai_product_images/static/description/assets/icons/check.png b/openai_product_images/static/description/assets/icons/check.png new file mode 100644 index 000000000..c8e85f51d Binary files /dev/null and b/openai_product_images/static/description/assets/icons/check.png differ diff --git a/openai_product_images/static/description/assets/icons/chevron.png b/openai_product_images/static/description/assets/icons/chevron.png new file mode 100644 index 000000000..2089293d6 Binary files /dev/null and b/openai_product_images/static/description/assets/icons/chevron.png differ diff --git a/openai_product_images/static/description/assets/icons/cogs.png b/openai_product_images/static/description/assets/icons/cogs.png new file mode 100644 index 000000000..95d0bad62 Binary files /dev/null and b/openai_product_images/static/description/assets/icons/cogs.png differ diff --git a/openai_product_images/static/description/assets/icons/consultation.png b/openai_product_images/static/description/assets/icons/consultation.png new file mode 100644 index 000000000..8319d4baa Binary files /dev/null and b/openai_product_images/static/description/assets/icons/consultation.png differ diff --git a/openai_product_images/static/description/assets/icons/ecom-black.png b/openai_product_images/static/description/assets/icons/ecom-black.png new file mode 100644 index 000000000..a9385ff13 Binary files /dev/null and b/openai_product_images/static/description/assets/icons/ecom-black.png differ diff --git a/openai_product_images/static/description/assets/icons/education-black.png b/openai_product_images/static/description/assets/icons/education-black.png new file mode 100644 index 000000000..3eb09b27b Binary files /dev/null and b/openai_product_images/static/description/assets/icons/education-black.png differ diff --git a/openai_product_images/static/description/assets/icons/hotel-black.png b/openai_product_images/static/description/assets/icons/hotel-black.png new file mode 100644 index 000000000..130f613be Binary files /dev/null and b/openai_product_images/static/description/assets/icons/hotel-black.png differ diff --git a/openai_product_images/static/description/assets/icons/license.png b/openai_product_images/static/description/assets/icons/license.png new file mode 100644 index 000000000..a5869797e Binary files /dev/null and b/openai_product_images/static/description/assets/icons/license.png differ diff --git a/openai_product_images/static/description/assets/icons/lifebuoy.png b/openai_product_images/static/description/assets/icons/lifebuoy.png new file mode 100644 index 000000000..658d56ccc Binary files /dev/null and b/openai_product_images/static/description/assets/icons/lifebuoy.png differ diff --git a/openai_product_images/static/description/assets/icons/logo.png b/openai_product_images/static/description/assets/icons/logo.png new file mode 100644 index 000000000..478462d3e Binary files /dev/null and b/openai_product_images/static/description/assets/icons/logo.png differ diff --git a/openai_product_images/static/description/assets/icons/manufacturing-black.png b/openai_product_images/static/description/assets/icons/manufacturing-black.png new file mode 100644 index 000000000..697eb0e9f Binary files /dev/null and b/openai_product_images/static/description/assets/icons/manufacturing-black.png differ diff --git a/openai_product_images/static/description/assets/icons/pos-black.png b/openai_product_images/static/description/assets/icons/pos-black.png new file mode 100644 index 000000000..97c0f90c1 Binary files /dev/null and b/openai_product_images/static/description/assets/icons/pos-black.png differ diff --git a/openai_product_images/static/description/assets/icons/puzzle.png b/openai_product_images/static/description/assets/icons/puzzle.png new file mode 100644 index 000000000..65cf854e7 Binary files /dev/null and b/openai_product_images/static/description/assets/icons/puzzle.png differ diff --git a/openai_product_images/static/description/assets/icons/restaurant-black.png b/openai_product_images/static/description/assets/icons/restaurant-black.png new file mode 100644 index 000000000..4a35eb939 Binary files /dev/null and b/openai_product_images/static/description/assets/icons/restaurant-black.png differ diff --git a/openai_product_images/static/description/assets/icons/service-black.png b/openai_product_images/static/description/assets/icons/service-black.png new file mode 100644 index 000000000..301ab51cb Binary files /dev/null and b/openai_product_images/static/description/assets/icons/service-black.png differ diff --git a/openai_product_images/static/description/assets/icons/trading-black.png b/openai_product_images/static/description/assets/icons/trading-black.png new file mode 100644 index 000000000..9398ba2f1 Binary files /dev/null and b/openai_product_images/static/description/assets/icons/trading-black.png differ diff --git a/openai_product_images/static/description/assets/icons/training.png b/openai_product_images/static/description/assets/icons/training.png new file mode 100644 index 000000000..884ca024d Binary files /dev/null and b/openai_product_images/static/description/assets/icons/training.png differ diff --git a/openai_product_images/static/description/assets/icons/update.png b/openai_product_images/static/description/assets/icons/update.png new file mode 100644 index 000000000..ecbc5a01a Binary files /dev/null and b/openai_product_images/static/description/assets/icons/update.png differ diff --git a/openai_product_images/static/description/assets/icons/user.png b/openai_product_images/static/description/assets/icons/user.png new file mode 100644 index 000000000..6ffb23d9f Binary files /dev/null and b/openai_product_images/static/description/assets/icons/user.png differ diff --git a/openai_product_images/static/description/assets/icons/wrench.png b/openai_product_images/static/description/assets/icons/wrench.png new file mode 100644 index 000000000..6c04dea0f Binary files /dev/null and b/openai_product_images/static/description/assets/icons/wrench.png differ diff --git a/openai_product_images/static/description/assets/modules/approval_image.png b/openai_product_images/static/description/assets/modules/approval_image.png new file mode 100644 index 000000000..84fe94e80 Binary files /dev/null and b/openai_product_images/static/description/assets/modules/approval_image.png differ diff --git a/openai_product_images/static/description/assets/modules/dynamic_image.png b/openai_product_images/static/description/assets/modules/dynamic_image.png new file mode 100644 index 000000000..f55c47e0f Binary files /dev/null and b/openai_product_images/static/description/assets/modules/dynamic_image.png differ diff --git a/openai_product_images/static/description/assets/modules/list_view_image.png b/openai_product_images/static/description/assets/modules/list_view_image.png new file mode 100644 index 000000000..510d36ae9 Binary files /dev/null and b/openai_product_images/static/description/assets/modules/list_view_image.png differ diff --git a/openai_product_images/static/description/assets/modules/multiple_ref_image.png b/openai_product_images/static/description/assets/modules/multiple_ref_image.png new file mode 100644 index 000000000..3fe90e552 Binary files /dev/null and b/openai_product_images/static/description/assets/modules/multiple_ref_image.png differ diff --git a/openai_product_images/static/description/assets/modules/print_image.png b/openai_product_images/static/description/assets/modules/print_image.png new file mode 100644 index 000000000..b470725a1 Binary files /dev/null and b/openai_product_images/static/description/assets/modules/print_image.png differ diff --git a/openai_product_images/static/description/assets/modules/product_return_image.png b/openai_product_images/static/description/assets/modules/product_return_image.png new file mode 100644 index 000000000..3afc14722 Binary files /dev/null and b/openai_product_images/static/description/assets/modules/product_return_image.png differ diff --git a/openai_product_images/static/description/assets/screenshots/hero.gif b/openai_product_images/static/description/assets/screenshots/hero.gif new file mode 100644 index 000000000..19527f5e7 Binary files /dev/null and b/openai_product_images/static/description/assets/screenshots/hero.gif differ diff --git a/openai_product_images/static/description/assets/screenshots/image_1.png b/openai_product_images/static/description/assets/screenshots/image_1.png new file mode 100644 index 000000000..105e8ebf7 Binary files /dev/null and b/openai_product_images/static/description/assets/screenshots/image_1.png differ diff --git a/openai_product_images/static/description/assets/screenshots/image_2.png b/openai_product_images/static/description/assets/screenshots/image_2.png new file mode 100644 index 000000000..9340fb0cf Binary files /dev/null and b/openai_product_images/static/description/assets/screenshots/image_2.png differ diff --git a/openai_product_images/static/description/assets/screenshots/image_3.png b/openai_product_images/static/description/assets/screenshots/image_3.png new file mode 100644 index 000000000..5df2bfdf6 Binary files /dev/null and b/openai_product_images/static/description/assets/screenshots/image_3.png differ diff --git a/openai_product_images/static/description/assets/screenshots/image_4.png b/openai_product_images/static/description/assets/screenshots/image_4.png new file mode 100644 index 000000000..7b483a513 Binary files /dev/null and b/openai_product_images/static/description/assets/screenshots/image_4.png differ diff --git a/openai_product_images/static/description/assets/screenshots/image_5.png b/openai_product_images/static/description/assets/screenshots/image_5.png new file mode 100644 index 000000000..101cc6dd7 Binary files /dev/null and b/openai_product_images/static/description/assets/screenshots/image_5.png differ diff --git a/openai_product_images/static/description/assets/screenshots/image_6.png b/openai_product_images/static/description/assets/screenshots/image_6.png new file mode 100644 index 000000000..40a5b0649 Binary files /dev/null and b/openai_product_images/static/description/assets/screenshots/image_6.png differ diff --git a/openai_product_images/static/description/banner.png b/openai_product_images/static/description/banner.png new file mode 100644 index 000000000..a21794b89 Binary files /dev/null and b/openai_product_images/static/description/banner.png differ diff --git a/openai_product_images/static/description/icon.png b/openai_product_images/static/description/icon.png new file mode 100644 index 000000000..b46d3a885 Binary files /dev/null and b/openai_product_images/static/description/icon.png differ diff --git a/openai_product_images/static/description/index.html b/openai_product_images/static/description/index.html new file mode 100644 index 000000000..649a6ea2e --- /dev/null +++ b/openai_product_images/static/description/index.html @@ -0,0 +1,648 @@ +
+
+
+
+ +
+
+
+ Community +
+
+ Enterprise +
+
+ Odoo.sh +
+
+
+
+
+ +
+
+
+

+ Generate Product Images Using OpenAI

+

+ Generating Product Images using DALL-E +

+ +
+
+ + + +
+
+

+ Overview +

+
+ +
+

+ This Odoo module allows you to generate product images on the basis of prompts using DALL-E, a deep learning + model developed by OpenAI. With this module, you can quickly and easily create high-quality product images that + are customized to your specific needs, without the need for expensive photography equipment or graphic design + software. Simply enter a prompt, such as "red t-shirt with white stripes", and the module will use DALL-E to + generate a unique product image that matches your description. This can be especially useful for e-commerce + websites, where high-quality product images can help to increase sales and customer engagement.

+
+ +
+ + +
+
+

+ Features +

+
+ +
+
+ +
+
+

+ Community & Enterprise Support.

+
+
+ +
+
+ +
+
+

+ Picture sample searching for product

+
+
+
+
+ +
+
+

+ Available in Odoo 16.0 Community and Enterprise.

+
+
+
+
+ +
+
+

+ Convert the pictures to product image.

+
+
+
+ +
+
+

+ Screenshots +

+
+
+

Field to provide api key

+

+ Fill your API key in settings for easy accessibility of api key

+ +
+
+

Searching the product image

+

+ Searching the product image through a wizard by filling prompt, size and number

+ + +
+
+

Sample picture record

+

+ Creates collection of image

+ +
+
+

Convert to product image

+

+ Convert one of that image + to product image

+ + +
+ + +
+ +
+
+

Suggested Products

+
+ + +
+
+ + + +
+
+
+

Our Services

+
+
+ +
+
+ +
+
+ Odoo + Customization
+
+ +
+
+ +
+
+ Odoo + Implementation
+
+ +
+
+ +
+
+ Odoo + Support
+
+ + +
+
+ +
+
+ Hire + Odoo + Developer
+
+ +
+
+ +
+
+ Odoo + Integration
+
+ +
+
+ +
+
+ Odoo + Migration
+
+ + +
+
+ +
+
+ Odoo + Consultancy
+
+ +
+
+ +
+
+ Odoo + Implementation
+
+ +
+
+ +
+
+ Odoo + Licensing Consultancy
+
+
+
+ + + +
+
+
+

Our Industries

+
+
+ +
+
+ +
+ Trading +
+

+ Easily procure + and + sell your products

+
+
+ +
+
+ +
+ POS +
+

+ Easy + configuration + and convivial experience

+
+
+ +
+
+ +
+ Education +
+

+ A platform for + educational management

+
+
+ +
+
+ +
+ Manufacturing +
+

+ Plan, track and + schedule your operations

+
+
+ +
+
+ +
+ E-commerce & Website +
+

+ Mobile + friendly, + awe-inspiring product pages

+
+
+ +
+
+ +
+ Service Management +
+

+ Keep track of + services and invoice

+
+
+ +
+
+ +
+ Restaurant +
+

+ Run your bar or + restaurant methodically

+
+
+ +
+
+ +
+ Hotel Management +
+

+ An + all-inclusive + hotel management application

+
+
+ +
+
+ + + + + +
+
+
+

Need Help?

+
+
+
+ + +
+ +
+ + +
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+
+ + +
\ No newline at end of file diff --git a/openai_product_images/views/dalle_image_suggestion_views.xml b/openai_product_images/views/dalle_image_suggestion_views.xml new file mode 100644 index 000000000..74aa128d4 --- /dev/null +++ b/openai_product_images/views/dalle_image_suggestion_views.xml @@ -0,0 +1,44 @@ + + + + + + dalle.image.suggestion.view.form + dalle.image.suggestion + +
+
+
+ +
+
+ + + + + +
+
+
+
+ + + dalle.image.suggestion.view.tree + + dalle.image.suggestion + + + + + + + +
+
\ No newline at end of file diff --git a/openai_product_images/views/product_template_views.xml b/openai_product_images/views/product_template_views.xml new file mode 100644 index 000000000..a9a228ad7 --- /dev/null +++ b/openai_product_images/views/product_template_views.xml @@ -0,0 +1,31 @@ + + + + + + Generate Image Using Dall-E + + + list,form + code + action =records.action_open_image_prompt_wizard() + + + + + + product_template.view.form.inherit.openai_product_images + product.template + +
+ +
+
+
+
+
\ No newline at end of file diff --git a/openai_product_images/wizard/__init__.py b/openai_product_images/wizard/__init__.py new file mode 100644 index 000000000..9f4a1f5f8 --- /dev/null +++ b/openai_product_images/wizard/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: LAJINA K V (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +from . import image_suggestion diff --git a/openai_product_images/wizard/image_suggestion.py b/openai_product_images/wizard/image_suggestion.py new file mode 100644 index 000000000..77524c206 --- /dev/null +++ b/openai_product_images/wizard/image_suggestion.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: LAJINA K V (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +import json +import base64 +import requests +from requests.structures import CaseInsensitiveDict +from odoo import fields, models +from odoo.exceptions import ValidationError + + +class ImageSuggestion(models.TransientModel): + """image for product from dalle""" + _name = 'image.suggestion' + _description = 'model for creation of dalle image' + _rec_name = 'product_tmpl_id' + + image_prompt = fields.Char(string="Prompt for image", + help="field to fill prompt", required=True) + product_tmpl_id = fields.Many2one('product.template', string="Product", + help="field to store product", + required=True) + num_image = fields.Integer(string="Number of image needed", + help="field to store number of image", + required=True, + default=1) + size_image = fields.Selection( + [('256x256', '256x256'), ('512x512', '512x512')], string="Resolution", + help="field to store image size", required=True) + + def action_search(self): + """Summary: + Function to search image suggestion from dalle + Returns: + returns the created media image of corresponding product + """ + + api_key = self.env['ir.config_parameter'].sudo().get_param( + 'openai_api_key') + if not api_key: + raise ValidationError("Please Enter Valid Open AI Key") + headers = CaseInsensitiveDict() + headers["Content-Type"] = "application/json" + headers["Authorization"] = f"Bearer {api_key}" + data = '{"model": "image-alpha-001",' \ + ' "prompt": "' + self.image_prompt + '", "num_images": ' + \ + str(self.num_image) + ', "size": "' \ + + self.size_image + '", "response_format": "url"}' + + resp = requests.post("https://api.openai.com/v1/images/generations", + headers=headers, data=data) + if resp.status_code != 200: + raise ValidationError("Failed to generate image") + response_text = json.loads(resp.text) + for url in response_text['data']: + image_url = url['url'] + # Get image data and encode it in base64 + image_resp = requests.get(image_url) + if image_resp.status_code != 200: + raise ValidationError("Failed to retrieve image") + image_b64 = base64.b64encode(image_resp.content) + # Store encoded image as binary field on model + self.env['dalle.image.suggestion'].create( + {'product_image': image_b64, + 'product_tmpl_id': self.product_tmpl_id.id, }) + return { + 'name': self.product_tmpl_id.name, + 'view_mode': 'tree,form', + 'res_model': 'dalle.image.suggestion', + 'type': 'ir.actions.act_window', + 'domain': [('product_tmpl_id', '=', self.product_tmpl_id.id)], + 'target': 'current', + } diff --git a/openai_product_images/wizard/image_suggestion_views.xml b/openai_product_images/wizard/image_suggestion_views.xml new file mode 100644 index 000000000..072157586 --- /dev/null +++ b/openai_product_images/wizard/image_suggestion_views.xml @@ -0,0 +1,30 @@ + + + + + + image.suggestion.form.view + image.suggestion + +
+ + + + + + + + + + + +
+
+
+
+
\ No newline at end of file