-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from erictik:upsclae-variation
Upsclae-variation
- Loading branch information
Showing
7 changed files
with
306 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, { useState } from "react"; | ||
import { Space, Tag } from "antd"; | ||
|
||
const { CheckableTag } = Tag; | ||
|
||
interface Props { | ||
Data: string[]; | ||
onClick?: (tag: string) => void; | ||
} | ||
|
||
const App = ({ Data, onClick }: Props) => { | ||
const [selectedTags, setSelectedTags] = useState<string[]>([]); | ||
// const tagsData = ["V1", "V2", "V3", "V4"]; | ||
const handleChange = (tag: string, checked: boolean) => { | ||
if (!checked) return; | ||
const nextSelectedTags = checked | ||
? [...selectedTags, tag] | ||
: selectedTags.filter((t) => t !== tag); | ||
console.log("You are interested in: ", nextSelectedTags); | ||
onClick && onClick(tag); | ||
setSelectedTags(nextSelectedTags); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Space className="ml-5" size={16} wrap> | ||
{Data.map((tag) => ( | ||
<CheckableTag | ||
className={ | ||
selectedTags.includes(tag) ? "bg-neutral-700" : "bg-neutral-200" | ||
} | ||
key={tag} | ||
checked={selectedTags.includes(tag)} | ||
onChange={(checked) => handleChange(tag, checked)} | ||
> | ||
{tag} | ||
</CheckableTag> | ||
))} | ||
</Space> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
export interface Message { | ||
text: string; | ||
img: string; | ||
} | ||
msgID?: string; | ||
msgHash?: string; | ||
content?: string; | ||
hasTag: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction | ||
import { Midjourney } from 'midjourney' | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
import { ResponseError } from '../../interfaces' | ||
import { Readable } from 'stream' | ||
const client = new Midjourney(<string>process.env.SERVER_ID, <string>process.env.CHANNEL_ID, <string>process.env.SALAI_TOKEN) | ||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const { content,index,msgId,msgHash } = req.body | ||
const stream = new Readable({ | ||
read() { | ||
} | ||
import { Midjourney } from "midjourney"; | ||
import { ResponseError } from "../../interfaces"; | ||
export const config = { | ||
runtime: "edge", | ||
}; | ||
const client = new Midjourney( | ||
<string>process.env.SERVER_ID, | ||
<string>process.env.CHANNEL_ID, | ||
<string>process.env.SALAI_TOKEN | ||
); | ||
client.maxWait = 600; | ||
export default async function handler(req: Request) { | ||
const { content, index, msgId, msgHash } = await req.json(); | ||
console.log("upscale.handler", content); | ||
const encoder = new TextEncoder(); | ||
const readable = new ReadableStream({ | ||
start(controller) { | ||
console.log("upscale.start", content); | ||
client | ||
.Upscale(content, index, msgId, msgHash, (uri: string) => { | ||
console.log("upscale.loading", uri); | ||
controller.enqueue(encoder.encode(JSON.stringify({ uri }))); | ||
}) | ||
.then((msg) => { | ||
console.log("upscale.done", msg); | ||
controller.enqueue(encoder.encode(JSON.stringify(msg))); | ||
controller.close(); | ||
}) | ||
.catch((err: ResponseError) => { | ||
console.log("upscale.error", err); | ||
controller.close(); | ||
}); | ||
}, | ||
}); | ||
client.Upscale(content,index,msgId,msgHash , (uri: string) => { | ||
console.log("upsale.loading", uri) | ||
stream.push(JSON.stringify({ uri })) | ||
}).then((msg) => { | ||
console.log("upsale.done", msg) | ||
stream.push(JSON.stringify(msg)) | ||
stream.push(null) | ||
}).catch((err: ResponseError) => { | ||
console.log("upsale.error", err) | ||
stream.push(null) | ||
}) | ||
stream.pipe(res); | ||
return new Response(readable, {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction | ||
import { Midjourney } from 'midjourney' | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
import { ResponseError } from '../../interfaces' | ||
import { Readable } from 'stream' | ||
const client = new Midjourney(<string>process.env.SERVER_ID, <string>process.env.CHANNEL_ID, <string>process.env.SALAI_TOKEN) | ||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const { content, index, msgId, msgHash } = req.body | ||
const stream = new Readable({ | ||
read() { | ||
|
||
} | ||
import { Midjourney } from "midjourney"; | ||
import { ResponseError } from "../../interfaces"; | ||
export const config = { | ||
runtime: "edge", | ||
}; | ||
const client = new Midjourney( | ||
<string>process.env.SERVER_ID, | ||
<string>process.env.CHANNEL_ID, | ||
<string>process.env.SALAI_TOKEN | ||
); | ||
client.maxWait = 600; | ||
export default async function handler(req: Request) { | ||
const { content, index, msgId, msgHash } = await req.json(); | ||
console.log("variation.handler", content); | ||
const encoder = new TextEncoder(); | ||
const readable = new ReadableStream({ | ||
start(controller) { | ||
console.log("variation.start", content); | ||
client | ||
.Variation(content, index, msgId, msgHash, (uri: string) => { | ||
console.log("variation.loading", uri); | ||
controller.enqueue(encoder.encode(JSON.stringify({ uri }))); | ||
}) | ||
.then((msg) => { | ||
console.log("variation.done", msg); | ||
controller.enqueue(encoder.encode(JSON.stringify(msg))); | ||
controller.close(); | ||
}) | ||
.catch((err: ResponseError) => { | ||
console.log("variation.error", err); | ||
controller.close(); | ||
}); | ||
}, | ||
}); | ||
console.log("variation.start", prompt) | ||
client.Variation(content, index, msgId, msgHash, (uri: string) => { | ||
console.log("variation.loading", uri) | ||
stream.push(JSON.stringify({ uri })) | ||
}).then((msg) => { | ||
console.log("variation.done", msg) | ||
stream.push(JSON.stringify(msg)) | ||
stream.push(null) | ||
}).catch((err: ResponseError) => { | ||
console.log("variation.error", err) | ||
stream.push(null) | ||
}) | ||
stream.pipe(res); | ||
return new Response(readable, {}); | ||
} |
Oops, something went wrong.
0dd9c67
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
midjourney-ui – ./
midjourney-ui.vercel.app
midjourney-ui-git-main-erictik.vercel.app
midjourney-ui-erictik.vercel.app
midjourney.baochi.xin