generate_image 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60937ca4cc756a6668f1ce865d9680f9531579314ccc5997c68ca0a43abc4ead
4
- data.tar.gz: 32cb07ec9f209d766fc540a3207a64d6b4e849da30db1561e10a9e5e3cf2139f
3
+ metadata.gz: 462b48a0798e5e6d50bffb2386d428b69d43b2c547a0e1bcc7ef01e1ada2fdb3
4
+ data.tar.gz: 9f6bf6aac0c92744f538aee95c82a64dab88200370891918a6406c77cb047e93
5
5
  SHA512:
6
- metadata.gz: 387399db10e15b05b8abf69bb508ed415ab8d31b4e765225a6e44243aca9e52fc0af15f6e9a7fffb85f03f9948c6f138ace5e63d42e560b9c52f4cd98238f0be
7
- data.tar.gz: 9210e9f29158e8a0c782d6583c920cac5b2740d70341694e0218e194343e47f3578df58c0306d4dd8c82de8f387d47eb55974e6752706a84e9cc12bf3413fa14
6
+ metadata.gz: 3682a51b886ecf2808b6f826bb30243e0b08a2628e93b6011c241fa201ab8abaaecc2195f9f5e46423a347330dbab8286e28fd3795417fb2661c0cf23c939f46
7
+ data.tar.gz: 5426a9c7093f85c6078f9d6d3deaab45253ca5d538dabe5ffd01c53317e8c452e623f0b071f693367c29702990b313499023ec047c62513bd599996100f5ded7
data/README.md CHANGED
@@ -1,39 +1,52 @@
1
1
  # GenerateImage
2
- The generate_image gem is a Ruby gem that provides a simple and easy-to-use interface for generating images using the DALL-E API. The gem is designed to be used in Ruby on Rails projects, but it can also be used in other Ruby projects.
2
+ The GenerateImage gem is a Ruby gem that provides a simple and easy-to-use interface for generating images using the OpenAI DALL-E API. This gem can be used in Ruby on Rails projects or any other Ruby projects.
3
3
 
4
- The gem provides a generate_image method, which takes a text argument and returns the generated image binary data. The method makes a request to the DALL-E API to generate an image based on the text, and returns the image binary data.
4
+ ## Usage
5
+ The gem provides a generate_image method, which takes a text argument and returns the generated image URL as a hash. The method makes a request to the DALL-E API to generate an image based on the provided text.
5
6
 
6
- The gem uses the Net::HTTP library to make the API request and it requires the API key to be set as an environment variable named DALL_E_API_KEY. The gem also includes error handling to ensure that the image generation is successful and raises an error if there's any issue.
7
+ Before using the generate_image method, you must set your OpenAI API key as an environment variable named DALL_E_API_KEY. The gem uses the Net::HTTP library to make API requests and includes error handling to ensure successful image generation. In case of any errors, the method will return a hash with an error key and a message.
8
+
9
+ ## Setting the API Key
10
+
11
+ Before you can use the generate_image method, you must set your OpenAI API key as an environment variable named DALL_E_API_KEY.
12
+
13
+ Here's an example of how you can set the environment variable
14
+
15
+ DALL_E_API_KEY=your_api_key
16
+
17
+ ## Example Usage
18
+
19
+ result = GenerateImage.generate_image('A three-story castle made of ice cream')
20
+ if result[:error]
21
+ puts result[:error]
22
+ else
23
+ puts result[:image_url]
24
+ end
7
25
 
8
26
  ## Installation
9
- To install the gem, add this line to your application's Gemfile:
27
+ ### Add this line to your application's Gemfile:
10
28
 
11
29
  gem 'generate_image'
12
- ### Then run:
13
-
30
+ ### And then execute:
31
+
14
32
  bundle install
15
33
  ### Or install it directly by running:
16
34
 
17
-
18
35
  gem install generate_image
19
-
20
36
  ## Development
21
- ### To contribute to the development of this gem, check out the repo and run the following commands to install dependencies and run the tests:
37
+ To contribute to the development of this gem, clone the repository and run the following commands to install dependencies and run tests:
22
38
 
23
39
  bin/setup
24
40
  rake spec
25
41
  You can also run bin/console for an interactive prompt to experiment with the code.
26
42
 
27
- ### To release a new version, update the version number in version.rb, then run:
43
+ ### To release a new version, update the version number in version.rb and run:
28
44
 
29
45
  bundle exec rake release
30
- This will create a git tag for the new version, push the git commits and tags, and upload the .gem file to rubygems.org.
46
+ This will create a git tag for the new version, push the git commits and tags, and upload the .gem file to RubyGems.org.
31
47
 
32
48
  ## Contributing
33
- Bug reports and pull requests are welcome on GitHub at https://github.com/merouaneamqor/generate_image. This project is intended to be a safe, welcoming space for collaboration, and all contributors are expected to adhere to the code of conduct.
49
+ Bug reports and pull requests are welcome on the GitHub repository. This project is intended to be a safe and welcoming space for collaboration, and all contributors are expected to adhere to the code of conduct.
34
50
 
35
51
  ## License
36
- The gem is available as open source under the terms of the MIT License.
37
-
38
- ## Code of Conduct
39
- Everyone interacting with the project is expected to follow the code of conduct.
52
+ The GenerateImage gem is open source software, released under the terms of the MIT License.
@@ -1,3 +1,3 @@
1
1
  module GenerateImage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -3,15 +3,21 @@ require 'json'
3
3
 
4
4
  module GenerateImage
5
5
  class << self
6
+ API_ENDPOINT = 'https://api.openai.com/v1/images/generations'
7
+ MODEL_NAME = 'image-alpha-001'
8
+
6
9
  def generate_image(text)
7
- api_key = "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"
10
+ api_key = ENV['DALL_E_API_KEY']
11
+ unless api_key
12
+ raise StandardError, "API Key not set"
13
+ end
8
14
 
9
- uri = URI('https://api.openai.com/v1/images/generations')
15
+ uri = URI(API_ENDPOINT)
10
16
  request = Net::HTTP::Post.new(uri)
11
17
  request['Content-Type'] = 'application/json'
12
18
  request['Authorization'] = "Bearer #{api_key}"
13
19
  request.body = {
14
- model: 'image-alpha-001',
20
+ model: MODEL_NAME,
15
21
  prompt: text,
16
22
  num_images: 1
17
23
  }.to_json
@@ -24,7 +30,9 @@ module GenerateImage
24
30
  image_url = JSON.parse(response.body)['data'][0]['url']
25
31
  return { image_url: image_url }
26
32
  else
27
- return { error: "Failed to generate image" }, 500
33
+ message = "Failed to generate image. Response code: #{response.code}. Response body: #{response.body}"
34
+ Rails.logger.error(message) if defined?(Rails)
35
+ return { error: message }, 500
28
36
  end
29
37
  end
30
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: generate_image
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - AMQOR Merouane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-12 00:00:00.000000000 Z
11
+ date: 2023-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http
@@ -66,9 +66,10 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: The 'generate_image' gem is a Ruby gem that provides a simple and easy-to-use
70
- interface for generating images using the DALL-E API. The gem is designed to be
71
- used in Ruby on Rails projects, but it can also be used in other Ruby projects.
69
+ description: Unleash your imagination and create stunning images with the 'generate_image'
70
+ gem. This Ruby gem provides a seamless interface for accessing the powerful DALL-E
71
+ API and generates images based on the text you provide. Perfect for Ruby on Rails
72
+ projects, but can also be used in other Ruby projects.
72
73
  email:
73
74
  - marouane.amqor6@gmail.com
74
75
  executables:
@@ -107,8 +108,7 @@ requirements: []
107
108
  rubygems_version: 3.1.2
108
109
  signing_key:
109
110
  specification_version: 4
110
- summary: A Ruby gem that provides a simple and easy-to-use interface for generating
111
- images using the DALL-E API
111
+ summary: Generate images using the DALL-E API
112
112
  test_files:
113
113
  - spec/generate_image_spec.rb
114
114
  - spec/spec_helper.rb