Skip to content

Commit

Permalink
Merge pull request #5 from minosvasilias/random_content
Browse files Browse the repository at this point in the history
Random Content
  • Loading branch information
minosvasilias authored Nov 28, 2023
2 parents bcafb35 + e3bfdfb commit 8d49de4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId = "com.minosapps.aiwp"
minSdk = 24
targetSdk = 33
versionCode = 4
versionName = "1.0.3"
versionCode = 5
versionName = "1.0.4"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
73 changes: 38 additions & 35 deletions app/src/main/java/com/minosapps/aiwp/OpenAIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import okhttp3.MediaType;
Expand All @@ -35,8 +36,6 @@ public OpenAIManager(Context _context) {
}

public String assemblePrompt() {
Instructions instructions = settings.getInstructions();
Style style = settings.getStyle();


String sourcePrompt = "";
Expand All @@ -55,59 +54,63 @@ public String assemblePrompt() {
sourcePrompt = sourcePrompt.replace(".", ". ");


String instructionPrompt = "";
Instructions instructions = settings.getInstructions();
String instructionPrompt = getInstructionPrompt(instructions);

Style style = settings.getStyle();
String stylePrompt = getStylePrompt(style);

String promptTemplate = context.getString(R.string.prompt_template);
String prompt = String.format(promptTemplate, sourcePrompt, instructionPrompt, stylePrompt);
return prompt;
}

private String getInstructionPrompt(Instructions instructions){
switch (instructions) {
case CITY:
instructionPrompt = context.getString(R.string.city_instructions);
break;
return context.getString(R.string.city_instructions);
case NATURE:
instructionPrompt = context.getString(R.string.nature_instructions);
break;
return context.getString(R.string.nature_instructions);
case LANDMARKS:
instructionPrompt = context.getString(R.string.landmarks_instructions);
break;
return context.getString(R.string.landmarks_instructions);
case PEOPLE:
instructionPrompt = context.getString(R.string.people_instructions);
break;
return context.getString(R.string.people_instructions);
case ANIMALS:
instructionPrompt = context.getString(R.string.animals_instructions);
break;
return context.getString(R.string.animals_instructions);
case CUSTOM:
instructionPrompt = settings.getCustomInstructions();
break;
return settings.getCustomInstructions();
case RANDOM:
Instructions randInstructions = Instructions.values()[new Random().nextInt(Instructions.values().length-1)];
return getInstructionPrompt(randInstructions);
default:
return "";
}
}

String stylePrompt = "";

private String getStylePrompt(Style style){
switch (style) {
case WATERCOLOR:
stylePrompt = context.getString(R.string.watercolor_style);
break;
return context.getString(R.string.watercolor_style);
case POINTILLIST:
stylePrompt = context.getString(R.string.pointilism_style);
break;
return context.getString(R.string.pointilism_style);
case ABSTRACT:
stylePrompt = context.getString(R.string.abstract_style);
break;
return context.getString(R.string.abstract_style);
case PHOTOREALISTIC:
stylePrompt = context.getString(R.string.photorealistic_style);
break;
return context.getString(R.string.photorealistic_style);
case IMPRESSIONIST:
stylePrompt = context.getString(R.string.impressionist_style);
break;
return context.getString(R.string.impressionist_style);
case CUBIST:
stylePrompt = context.getString(R.string.cubist_style);
break;
return context.getString(R.string.cubist_style);
case CUSTOM:
stylePrompt = settings.getCustomStyle();
break;
return settings.getCustomStyle();
case RANDOM:
Style randStyle = Style.values()[new Random().nextInt(Style.values().length-1)];
return getStylePrompt(randStyle);
default:
return "";
}

String promptTemplate = context.getString(R.string.prompt_template);
String prompt = String.format(promptTemplate, sourcePrompt, instructionPrompt, stylePrompt);
return prompt;
}

public InputStream fetchImage() throws Exception {
String prompt = assemblePrompt();
OkHttpClient client = new OkHttpClient.Builder()
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/minosapps/aiwp/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public Settings(Context _context) {
}

public enum Instructions {
CITY, NATURE, LANDMARKS, PEOPLE, ANIMALS, CUSTOM;
CITY, NATURE, LANDMARKS, PEOPLE, ANIMALS, CUSTOM, RANDOM;
}

public enum Style {
POINTILLIST, WATERCOLOR, ABSTRACT, PHOTOREALISTIC, IMPRESSIONIST, CUBIST, CUSTOM;
POINTILLIST, WATERCOLOR, ABSTRACT, PHOTOREALISTIC, IMPRESSIONIST, CUBIST, CUSTOM, RANDOM;
}

public enum Frequency {
Expand Down

0 comments on commit 8d49de4

Please sign in to comment.