generate_image 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 60937ca4cc756a6668f1ce865d9680f9531579314ccc5997c68ca0a43abc4ead
4
+ data.tar.gz: 32cb07ec9f209d766fc540a3207a64d6b4e849da30db1561e10a9e5e3cf2139f
5
+ SHA512:
6
+ metadata.gz: 387399db10e15b05b8abf69bb508ed415ab8d31b4e765225a6e44243aca9e52fc0af15f6e9a7fffb85f03f9948c6f138ace5e63d42e560b9c52f4cd98238f0be
7
+ data.tar.gz: 9210e9f29158e8a0c782d6583c920cac5b2740d70341694e0218e194343e47f3578df58c0306d4dd8c82de8f387d47eb55974e6752706a84e9cc12bf3413fa14
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 AMQOR Merouane
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
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.
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.
5
+
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
+
8
+ ## Installation
9
+ To install the gem, add this line to your application's Gemfile:
10
+
11
+ gem 'generate_image'
12
+ ### Then run:
13
+
14
+ bundle install
15
+ ### Or install it directly by running:
16
+
17
+
18
+ gem install generate_image
19
+
20
+ ## 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:
22
+
23
+ bin/setup
24
+ rake spec
25
+ You can also run bin/console for an interactive prompt to experiment with the code.
26
+
27
+ ### To release a new version, update the version number in version.rb, then run:
28
+
29
+ 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.
31
+
32
+ ## 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.
34
+
35
+ ## 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.
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "generate_image"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module GenerateImage
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module GenerateImage
5
+ class << self
6
+ def generate_image(text)
7
+ api_key = "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"
8
+
9
+ uri = URI('https://api.openai.com/v1/images/generations')
10
+ request = Net::HTTP::Post.new(uri)
11
+ request['Content-Type'] = 'application/json'
12
+ request['Authorization'] = "Bearer #{api_key}"
13
+ request.body = {
14
+ model: 'image-alpha-001',
15
+ prompt: text,
16
+ num_images: 1
17
+ }.to_json
18
+
19
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
20
+ http.request(request)
21
+ end
22
+
23
+ if response.code == '200'
24
+ image_url = JSON.parse(response.body)['data'][0]['url']
25
+ return { image_url: image_url }
26
+ else
27
+ return { error: "Failed to generate image" }, 500
28
+ end
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,9 @@
1
+ RSpec.describe GenerateImage do
2
+ it "has a version number" do
3
+ expect(GenerateImage::VERSION).not_to be nil
4
+ end
5
+
6
+ it "does something useful" do
7
+ expect(false).to eq(true)
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require "generate_image"
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = ".rspec_status"
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: generate_image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - AMQOR Merouane
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: openai
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
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.
72
+ email:
73
+ - marouane.amqor6@gmail.com
74
+ executables:
75
+ - console
76
+ - setup
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - LICENSE.txt
81
+ - README.md
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/generate_image.rb
85
+ - lib/generate_image/version.rb
86
+ - spec/generate_image_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: https://github.com/merouaneamqor/generate_image
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 2.3.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.1.2
108
+ signing_key:
109
+ 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
112
+ test_files:
113
+ - spec/generate_image_spec.rb
114
+ - spec/spec_helper.rb