From 6eb21b6462062b20cd539cfb8532e6b27282f6de Mon Sep 17 00:00:00 2001 From: Joshua Date: Mon, 20 Feb 2023 17:04:01 +0000 Subject: [PATCH 1/3] Added BrowserLauncher and Updated Index.html Created a Spring component called BrowserLauncher which opens a browser at localhost. Updated index to easily allow the user to switch between ChatGPT and DALL-E. --- .../java/de/bsi/openai/BrowserLauncher.java | 27 +++++++++++++ src/main/resources/application.properties | 2 +- src/main/resources/templates/image.html | 38 +++++++++++-------- src/main/resources/templates/index.html | 3 ++ 4 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 src/main/java/de/bsi/openai/BrowserLauncher.java diff --git a/src/main/java/de/bsi/openai/BrowserLauncher.java b/src/main/java/de/bsi/openai/BrowserLauncher.java new file mode 100644 index 0000000..c09ec70 --- /dev/null +++ b/src/main/java/de/bsi/openai/BrowserLauncher.java @@ -0,0 +1,27 @@ +package de.bsi.openai; + +import java.awt.Desktop; +import java.net.URI; + +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +@Component +public class BrowserLauncher { + + @EventListener(ApplicationReadyEvent.class) + public void launchBrowser() { + + System.setProperty("java.awt.headless", "false"); + + Desktop desktop = Desktop.getDesktop(); + + try { + desktop.browse(new URI("http://localhost:8080")); + } catch (Exception e) { + } + + } + +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c158d9e..30e8b1f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ -openai.api_key=Generate this at openai.com +openai.api_key=Generate this at openai.com \ No newline at end of file diff --git a/src/main/resources/templates/image.html b/src/main/resources/templates/image.html index 0544cb5..e509b49 100644 --- a/src/main/resources/templates/image.html +++ b/src/main/resources/templates/image.html @@ -1,28 +1,36 @@ - - - DALL-E & Spring demo - + + +DALL-E & Spring demo +
+
+ Use ChatGPT +
-

DALL-E API at
agile-coding.blogspot.com

+

+ DALL-E API at
agile-coding.blogspot.com +

Describe image

-
-
- -
-
- -
-
+
+
+ +
+
+ +
+
-

DALL-E draw for you:

- Picture drawn by DALL-E +

DALL-E draw for you:

+ Picture drawn by DALL-E
diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 2299000..cd0a7af 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -8,6 +8,9 @@
+
+ Use DALL-E +

ChatGPT API at
agile-coding.blogspot.com

Send message to ChatGPT

From d673f833776e590c6ed4fb75a3901110203a85d8 Mon Sep 17 00:00:00 2001 From: Joshua W <104085258+tigjaw@users.noreply.github.com> Date: Mon, 20 Feb 2023 17:08:50 +0000 Subject: [PATCH 2/3] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d9ddc3a..fe99ec2 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ * Create API key at https://beta.openai.com/account/api-keys * Store the key in application.properties file in cloned project. * Start it as Spring Boot application. -* For chatting with ChatGPT: http://localhost:8080/ -* For drawing images with DALL-E: http://localhost:8080/image +* Browser opens index.html automatically, hosted at: + * http://localhost:8080/ (for chatting with ChatGPT) + * http://localhost:8080/image (for drawing images with DALL-E) ## Setup proxy If you need a proxy to communicate with Internet (ChatGPT API is in Internet), adapt ChatGptController.java like this: From b8743dc85350707d6b0d7a8e05d6ff900f5bad2b Mon Sep 17 00:00:00 2001 From: Joshua W <104085258+tigjaw@users.noreply.github.com> Date: Fri, 17 Mar 2023 17:11:44 +0000 Subject: [PATCH 3/3] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0a51551 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Joshua W. (@Tigjaw) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.