Skip to content

Commit a069870

Browse files
Bernard Horanolyagpl
Bernard Horan
authored andcommitted
Update README and build.gradle to use correct version
This now produces a native executable
1 parent 5601aaa commit a069870

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

polyglot-chat-app/README.md

+23-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Polyglot Chat Application
22

33
This example demonstrates how to integrate Python on GraalVM with a Micronaut application.
4+
The application uses the nltk module to analyze text sentiment.
45
The application uses the Gradle build tool.
56

67
## Preparation
@@ -15,36 +16,39 @@ The application uses the Gradle build tool.
1516

1617
2. Download and install the latest GraalPy as described in the [Getting Started guide](https://www.graalvm.org/latest/reference-manual/python/#installing-graalpy). For example on Linux:
1718
```bash
18-
wget https://github.com/oracle/graalpython/releases/download/graal-23.1.1/graalpy-23.1.1-linux-amd64.tar.gz
19-
tar xzf graalpy-23.1.1-linux-amd64.tar.gz
19+
pyenv install graalpy-23.1.2
20+
pyenv shell graalpy-23.1.2
2021
``
2122
22-
3. Create a virtual environment for this demo in the _resources_ directory, and install the required packages:
23+
3. Create a virtual environment for the demo in the _resources_ directory, activate it, install the required package, and download a lexicon:
2324
```bash
24-
graalpy-23.1.1-linux-amd64/bin/graalpy -m venv src/main/resources/venv
25+
graalpy -m venv src/main/resources/venv
2526
```
2627
```bash
27-
src/main/resources/venv/bin/graalpy -m pip install nltk
28+
source src/main/resources/venv/bin/activate
2829
```
2930
```bash
30-
src/main/resources/venv/bin/graalpy -c "import nltk; nltk.download('vader_lexicon')"
31+
graalpy -m pip install nltk
32+
```
33+
```bash
34+
graalpy -c "import nltk; nltk.download('vader_lexicon')"
3135
```
3236
33-
4. (Optional) Download and install GraalVM JDK for Java 21 or later to run Python with runtime compilation and to build a native image.
34-
The demo will work on any OpenJDK distribution, but will be much faster on GraalVM JDK.
37+
4. (Optional) [Download and install GraalVM JDK for Java 21](https://www.graalvm.org/downloads/) or later to run Python with runtime compilation and to build a native image.
38+
The demo will work with any OpenJDK distribution, but will be much faster on GraalVM JDK.
3539
36-
## Building and Running the Application:
40+
## Building and Running the Application
3741
38-
1. Build application with Gradle:
42+
1. Build and run the application using Gradle:
3943
```bash
4044
./gradlew run
4145
```
4246
4347
2. Navigate to [http://localhost:12345/#/chat/bob](http://localhost:12345/#/chat/bob).
4448
4549
You can connect from multiple browsers and chat via websockets.
46-
The Python code will load a language model in the background.
47-
Once it is ready, it will analyse the sentiments of all messages and add an emoji to the message to indicate the feelings conveyed.
50+
The Python code loads a language model in the background—this can take up to 5 minutes.
51+
Once it is ready, it analyzes the sentiments of messages and add an emoji to each message to indicate the feelings conveyed.
4852
A chat may look like this (newest message at the top):
4953
5054
```
@@ -53,17 +57,19 @@ The demo will work on any OpenJDK distribution, but will be much faster on Graal
5357
[bob 💬] still loading the sentiment model I believe
5458
```
5559
56-
## Building a Native Image
60+
## (Optional) Building a Native Executable
61+
62+
> Note: this requires [Download and install GraalVM JDK for Java 21](https://www.graalvm.org/downloads/) or later.
5763
58-
The application can be AOT compiled using GraalVM Native Image.
59-
The Python code has to be shipped in a _resources_ directory that is kept next to the native executable.
64+
The application can be compiled ahead-of-time to a native executable using GraalVM Native Image.
65+
The Python code must be copied to the _build/_ directory that is kept next to the native executable.
6066
61-
1. Build a native executable with the Micronaut AOT support:
67+
1. Build a native executable using Micronaut AOT support:
6268
```bash
6369
./gradlew nativeCompile
6470
```
6571
66-
2. Copy the venv into the output _resources_ directory:
72+
2. Copy the _venv_ directory into the output _resources_ directory:
6773
```bash
6874
cp -R src/main/resources/venv/ build/native/nativeCompile/resources/python/
6975
```

polyglot-chat-app/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ dependencies {
3131

3232
implementation("jakarta.inject:jakarta.inject-api:2.0.1")
3333

34-
implementation("org.graalvm.sdk:graal-sdk:23.1.1")
35-
implementation("org.graalvm.polyglot:python:23.1.1")
36-
implementation("org.graalvm.sdk:nativeimage:23.1.1")
34+
implementation("org.graalvm.sdk:graal-sdk:23.1.2")
35+
implementation("org.graalvm.polyglot:python:23.1.2")
36+
implementation("org.graalvm.sdk:nativeimage:23.1.2")
3737
}
3838

3939

0 commit comments

Comments
 (0)