Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
.env-frontend
.env-frontend-stage
node_modules

# Python cache
__pycache__/
*.pyc
*.pyo
15 changes: 15 additions & 0 deletions GPTutor-Frontend/src/api/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ export function generateImageGet(
}).then((res) => res.json());
}

export function generateMidjourneyImage(
params: GenerateImageRequest,
controller: AbortController
): Promise<GeneratedImage[] & ErrorResponseType> {
return fetch(`${BACKEND_HOST}midjourney`, {
method: "POST",
headers: {
Authorization: httpService.authorization,
"Content-Type": "application/json",
},
signal: controller.signal,
body: JSON.stringify(params),
}).then((res) => res.json());
}

export async function getImageBase64(imageId: string): Promise<string> {
const res = await fetch(`${BACKEND_HOST}image/${imageId}/base64`, {
headers: {
Expand Down
48 changes: 27 additions & 21 deletions GPTutor-Frontend/src/entity/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { memo, sig } from "dignals";
import { ChipOption } from "@vkontakte/vkui";

import ReactivePromise from "$/services/ReactivePromise";
import { generateImage, getImageBase64 } from "$/api/images";
import { generateImage, getImageBase64, generateMidjourneyImage } from "$/api/images";
import {
emptyImageGenerated,
GeneratedImage,
Expand Down Expand Up @@ -308,6 +308,11 @@ class ImageGeneration {
return seed;
}

isMidjourneyModel() {
const model = this.model$.get();
return model.startsWith("midjourney");
}

getPrompt() {
return this.prompt$.get().trim() === ""
? emptyPrompt.ru
Expand All @@ -333,26 +338,27 @@ class ImageGeneration {

this.abortController = new AbortController();

const result = await generateImage(
{
modelId: this.model$.get(),
prompt: prompt.trim(),
createdAt: new Date(),
guidanceScale: this.CFGScale$.get(),
seed: this.getSeed(),
expireTimestamp: datePlus30Days(),
samples: this.samples$.get(),
originalPrompt: "",
scheduler: this.sampler$.get(),
width: this.width$.get(),
height: this.height$.get(),
upscale: this.upscale$.get(),
numInferenceSteps: this.step$.get(),
loraModel: this.loraModel$.get(),
negativePrompt: negativePrompt.trim(),
},
this.abortController!
);
const requestParams = {
modelId: this.model$.get(),
prompt: prompt.trim(),
createdAt: new Date(),
guidanceScale: this.CFGScale$.get(),
seed: this.getSeed(),
expireTimestamp: datePlus30Days(),
samples: this.samples$.get(),
originalPrompt: "",
scheduler: this.sampler$.get(),
width: this.width$.get(),
height: this.height$.get(),
upscale: this.upscale$.get(),
numInferenceSteps: this.step$.get(),
loraModel: this.loraModel$.get(),
negativePrompt: negativePrompt.trim(),
};

const result = this.isMidjourneyModel()
? await generateMidjourneyImage(requestParams, this.abortController!)
: await generateImage(requestParams, this.abortController!);

if (result.error) {
console.log(result);
Expand Down
17 changes: 17 additions & 0 deletions GPTutor-Frontend/src/entity/image/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,26 @@ export const styles = [
imageName: "3D-toon.png",
label: "3D мультик",
},
{
value: "midjourney-v6",
imageName: "midjourney.png",
label: "Midjourney",
},
];

export const models = [
{
value: "midjourney-v6",
label: "Midjourney V6",
},
{
value: "midjourney-v5.2",
label: "Midjourney V5.2",
},
{
value: "midjourney-niji-v6",
label: "Midjourney Niji V6 (Anime)",
},
{
value: "ICantBelieveItsNotPhotography_seco.safetensors [4e7a3dfd]",
label: "I Cant Believe Its Not Photography Seco",
Expand Down
26 changes: 26 additions & 0 deletions GPTutor-Models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from images.dalle3 import generate_dalle
from images.prodia import txt2img
from images.midjourney import txt2img_midjourney
from vk_docs.index import create_question_vk_doc

app = Flask(__name__)
Expand Down Expand Up @@ -66,6 +67,31 @@ def dalle():
)


@app.post("/midjourney")
def midjourney():
print("Midjourney request:", request.json)

try:
return txt2img_midjourney(
prompt=request.json["prompt"],
negative_prompt=request.json.get("negativePrompt", ""),
model=request.json.get("modelId", "midjourney-v6"),
scheduler=request.json.get("scheduler", "midjourney"),
guidance_scale=request.json.get("guidanceScale", 7.0),
seed=request.json.get("seed", -1),
steps=request.json.get("numInferenceSteps", 25),
width=request.json.get("width", 1024),
height=request.json.get("height", 1024),
)

except Exception as e:
print("Midjourney error:", e)
return {
"error": f"Midjourney generation failed: {str(e)}",
"status": 500
}


def run_flask():
app.run(debug=True, port=1337, host="0.0.0.0")

Expand Down
17 changes: 17 additions & 0 deletions GPTutor-Models/images/enums.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
from enum import Enum


class MidjourneyModel(Enum):
MIDJOURNEY_V6 = "midjourney-v6"
MIDJOURNEY_V5_2 = "midjourney-v5.2"
MIDJOURNEY_V5_1 = "midjourney-v5.1"
MIDJOURNEY_V5 = "midjourney-v5"
MIDJOURNEY_NIJI_V6 = "midjourney-niji-v6"
MIDJOURNEY_NIJI_V5 = "midjourney-niji-v5"


class MidjourneyStyle(Enum):
RAW = "raw"
EXPRESSIVE = "expressive"
CUTE = "cute"
SCENIC = "scenic"
ORIGINAL = "original"


class ProdiaModel(Enum):
CHILDREN_STORIES_V1= "childrensStories_v1SemiReal.safetensors [a1c56dbb]"
ANALOG_V1 = "analog-diffusion-1.0.ckpt [9ca13f02]"
Expand Down
Loading