@ -0,0 +1,46 @@ |
|||||
|
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg |
||||
|
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
:alt: License: AGPL-3 |
||||
|
|
||||
|
Generate Product Images Using OpenAI |
||||
|
===================================== |
||||
|
Odoo Module for Generating Product Images using DALL-E,OpenAI,dalle,chatgpt, |
||||
|
odoo chatgpt connector,odoo chatgpt,openai odoo. |
||||
|
|
||||
|
Configuration |
||||
|
============= |
||||
|
* Fill OpenAI API key from settings |
||||
|
|
||||
|
License |
||||
|
------- |
||||
|
General Public License, Version 3 (AGPL v3). |
||||
|
(https://www.gnu.org/licenses/agpl-3.0-standalone.html) |
||||
|
|
||||
|
Company |
||||
|
------- |
||||
|
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
||||
|
|
||||
|
Credits |
||||
|
------- |
||||
|
* Developer: (V18) Manasa T P |
||||
|
|
||||
|
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 |
||||
|
========== |
||||
|
.. image:: https://cybrosys.com/images/logo.png |
||||
|
:target: https://cybrosys.com |
||||
|
This module is maintained by Cybrosys Technologies. |
||||
|
|
||||
|
For support and more information, please visit https://www.cybrosys.com |
||||
|
|
||||
|
Further information |
||||
|
=================== |
||||
|
HTML Description: `<static/description/index.html>`__ |
||||
|
|
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
################################################################################ |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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 <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
################################################################################ |
||||
|
from . import models |
||||
|
from . import wizard |
@ -0,0 +1,47 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
################################################################################ |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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 <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
################################################################################ |
||||
|
{ |
||||
|
'name': 'Generate Product Images Using OpenAI', |
||||
|
'version': '18.0.1.0.0', |
||||
|
'category': 'Extra Tools', |
||||
|
'summary': 'This module helps to generate images for products using ' |
||||
|
'DALL-E.', |
||||
|
'description': 'Odoo Module for Generating Product Images using ' |
||||
|
'DALL-E,OpenAI,dalle,chatgpt,odoo chatgpt connector,' |
||||
|
'odoo chatgpt,openai odoo', |
||||
|
'author': 'Cybrosys Techno Solutions', |
||||
|
'company': 'Cybrosys Techno Solutions', |
||||
|
'maintainer': 'Cybrosys Techno Solutions', |
||||
|
'website': 'https://www.cybrosys.com', |
||||
|
'depends': ['base', 'product', 'openai_odoo_base'], |
||||
|
'data': [ |
||||
|
'security/ir.model.access.csv', |
||||
|
'views/product_template_views.xml', |
||||
|
'views/dalle_image_suggestion_views.xml', |
||||
|
'wizard/image_suggestion_views.xml', |
||||
|
], |
||||
|
'images': ['static/description/banner.png'], |
||||
|
'license': 'AGPL-3', |
||||
|
'installable': True, |
||||
|
'auto_install': False, |
||||
|
'application': False, |
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
## Module <openai_product_images> |
||||
|
#### 14.11.2024 |
||||
|
#### Version 18.0.1.0.0 |
||||
|
#### ADD |
||||
|
- Initial commit for Generate Product Images Using OpenAI |
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
################################################################################ |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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 <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
################################################################################ |
||||
|
from . import dalle_image_suggestion |
||||
|
from . import product_template |
@ -0,0 +1,51 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
################################################################################ |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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 <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
################################################################################ |
||||
|
from odoo import fields, models |
||||
|
|
||||
|
|
||||
|
class DalleImageSuggestion(models.Model): |
||||
|
"""image for product from dalle and save it as record""" |
||||
|
_name = 'dalle.image.suggestion' |
||||
|
_rec_name = 'product_tmpl_id' |
||||
|
_description = 'model for save image' |
||||
|
|
||||
|
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', |
||||
|
} |
@ -0,0 +1,57 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
################################################################################ |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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 <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
################################################################################ |
||||
|
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 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': 'list,form', |
||||
|
'res_model': 'dalle.image.suggestion', |
||||
|
'type': 'ir.actions.act_window', |
||||
|
'domain': [('product_tmpl_id', '=', self.id)], |
||||
|
} |
|
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 628 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 215 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 767 KiB |
After Width: | Height: | Size: 138 KiB |
After Width: | Height: | Size: 760 KiB |
After Width: | Height: | Size: 92 KiB |
After Width: | Height: | Size: 697 KiB |
After Width: | Height: | Size: 1.1 MiB |
After Width: | Height: | Size: 74 KiB |
After Width: | Height: | Size: 97 KiB |
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 134 KiB |
After Width: | Height: | Size: 121 KiB |
After Width: | Height: | Size: 115 KiB |
After Width: | Height: | Size: 880 KiB |
After Width: | Height: | Size: 91 KiB |
After Width: | Height: | Size: 9.1 KiB |
@ -0,0 +1,41 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<!-- form view for the model dalle.image.suggestion--> |
||||
|
<record id="dalle_image_suggestion_form_view" model="ir.ui.view"> |
||||
|
<field name="name">dalle.image.suggestion.form.view</field> |
||||
|
<field name="model">dalle.image.suggestion</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form string="Dall-E Image Suggestion"> |
||||
|
<header> |
||||
|
<button name="action_make_as_product_image" type="object" |
||||
|
string="Make as Product Image"/> |
||||
|
</header> |
||||
|
<sheet> |
||||
|
<div class="oe_title"> |
||||
|
<label for="product_tmpl_id"/> |
||||
|
<h1> |
||||
|
<field name="product_tmpl_id" |
||||
|
placeholder="Title"/> |
||||
|
</h1> |
||||
|
</div> |
||||
|
<group> |
||||
|
<group> |
||||
|
<field name="product_image" widget="image"/> |
||||
|
</group> |
||||
|
</group> |
||||
|
</sheet> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
<!-- tree view for the model dalle.image.suggestion--> |
||||
|
<record id="dalle_image_suggestion_tree_view" model="ir.ui.view"> |
||||
|
<field name="name">dalle_image_suggestion.view.tree</field> |
||||
|
<field name="model">dalle.image.suggestion</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<list string="Dall-E Image Suggestion"> |
||||
|
<field name="product_tmpl_id"/> |
||||
|
<field name="product_image" widget="image"/> |
||||
|
</list> |
||||
|
</field> |
||||
|
</record> |
||||
|
</odoo> |
@ -0,0 +1,29 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<!-- Added a server action in the model product template--> |
||||
|
<record id="action_product_template_dalle" model="ir.actions.server"> |
||||
|
<field name="name">Generate Image Using Dall-E</field> |
||||
|
<field name="model_id" ref="product.model_product_template"/> |
||||
|
<field name="binding_model_id" |
||||
|
ref="product.model_product_template"/> |
||||
|
<field name="binding_view_types">list,form</field> |
||||
|
<field name="state">code</field> |
||||
|
<field name="code">action =records.action_open_image_prompt_wizard() |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<!--Added smart button in the product.template form--> |
||||
|
<record id="product_template_only_form_view" model="ir.ui.view"> |
||||
|
<field name="name">product.template.view.form.inherit.openai.product.images</field> |
||||
|
<field name="inherit_id" ref="product.product_template_only_form_view"/> |
||||
|
<field name="model">product.template</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<div name="button_box" position="inside"> |
||||
|
<button name="get_dall_e_image" type="object" |
||||
|
class="oe_stat_button" icon="fa-id-card-o" |
||||
|
string="Dall E Image"> |
||||
|
</button> |
||||
|
</div> |
||||
|
</field> |
||||
|
</record> |
||||
|
</odoo> |
@ -0,0 +1,22 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
################################################################################ |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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 <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
################################################################################ |
||||
|
from . import image_suggestion |
@ -0,0 +1,91 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
################################################################################ |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
||||
|
# Author: Cybrosys Techno Solutions(<https://www.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 <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
################################################################################ |
||||
|
import requests |
||||
|
from requests.structures import CaseInsensitiveDict |
||||
|
import json |
||||
|
import base64 |
||||
|
from odoo import fields, models, _ |
||||
|
from odoo.exceptions import ValidationError |
||||
|
|
||||
|
|
||||
|
class ImageSuggestion(models.TransientModel): |
||||
|
"""image for product from dalle""" |
||||
|
_name = 'image.suggestion' |
||||
|
_rec_name = 'product_tmpl_id' |
||||
|
_description = 'model for creation of dalle image ' |
||||
|
|
||||
|
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( |
||||
|
_("Invalid API key provided. Please ensure that you have " |
||||
|
"entered the correct API key. ")) |
||||
|
headers = CaseInsensitiveDict() |
||||
|
headers["Content-Type"] = "application/json" |
||||
|
headers["Authorization"] = f"Bearer {api_key}" |
||||
|
data = '{"model": "dall-e-2",' \ |
||||
|
' "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': 'list,form', |
||||
|
'res_model': 'dalle.image.suggestion', |
||||
|
'type': 'ir.actions.act_window', |
||||
|
'domain': [('product_tmpl_id', '=', self.product_tmpl_id.id)], |
||||
|
'target': 'current', |
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<odoo> |
||||
|
<!--form view for the model image.suggestion--> |
||||
|
<record id="image_suggestion_view_form" model="ir.ui.view"> |
||||
|
<field name="name">image.suggestion.view.form</field> |
||||
|
<field name="model">image.suggestion</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form string="Image Suggestion"> |
||||
|
<sheet> |
||||
|
<group> |
||||
|
<group> |
||||
|
<field name="product_tmpl_id"/> |
||||
|
<field name="image_prompt"/> |
||||
|
<field name="num_image"/> |
||||
|
<field name="size_image"/> |
||||
|
</group> |
||||
|
</group> |
||||
|
<footer> |
||||
|
<button name="action_search" type="object" |
||||
|
string="Search" class="btn-primary"/> |
||||
|
<button string="Cancel" special="cancel" |
||||
|
data-hotkey="z"/> |
||||
|
</footer> |
||||
|
</sheet> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
</odoo> |