2022-12-14 13:44:10 -07:00
|
|
|
import { InferenceInput, InferenceResult, PlayingState } from "../types";
|
2022-12-12 23:28:14 -07:00
|
|
|
import { IoMdClose } from "react-icons/io";
|
2022-12-14 13:44:10 -07:00
|
|
|
import Pause from "./Pause";
|
2022-11-23 22:47:18 -07:00
|
|
|
|
|
|
|
interface PromptEntryProps {
|
2022-12-12 23:28:14 -07:00
|
|
|
prompt: string;
|
|
|
|
index: number;
|
|
|
|
className: string;
|
|
|
|
playingState: PlayingState;
|
|
|
|
resetCallback: () => void;
|
2022-12-14 13:44:10 -07:00
|
|
|
inferenceResults: InferenceResult[];
|
|
|
|
nowPlayingResult: InferenceResult;
|
|
|
|
setPaused: (value: boolean) => void;
|
2022-11-23 22:47:18 -07:00
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:30 -07:00
|
|
|
export default function PromptEntry({
|
2022-12-12 23:28:14 -07:00
|
|
|
prompt,
|
|
|
|
index,
|
|
|
|
className,
|
|
|
|
playingState,
|
|
|
|
resetCallback,
|
2022-12-14 13:44:10 -07:00
|
|
|
inferenceResults,
|
|
|
|
nowPlayingResult,
|
|
|
|
setPaused
|
2022-11-30 17:30:52 -07:00
|
|
|
}: PromptEntryProps) {
|
2022-12-14 13:44:10 -07:00
|
|
|
|
2022-12-12 23:28:14 -07:00
|
|
|
const getPromptCopy = (prompt: string) => {
|
|
|
|
switch (playingState) {
|
|
|
|
case PlayingState.UNINITIALIZED:
|
|
|
|
case PlayingState.SAME_PROMPT:
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
2022-12-14 13:44:10 -07:00
|
|
|
return (
|
|
|
|
<div className="tooltip text-left" data-tip="⏪ Jump to previous prompt?" onClick={() => { jumpToPrompt(prompt, inferenceResults, setPaused, nowPlayingResult) }} >
|
|
|
|
<p className={className}>{prompt}</p>
|
|
|
|
</div>
|
|
|
|
);
|
2022-12-12 23:28:14 -07:00
|
|
|
case 1:
|
2022-12-14 13:44:10 -07:00
|
|
|
return (
|
|
|
|
<div className="tooltip text-left" data-tip="⏪ Jump to previous prompt?" onClick={() => { jumpToPrompt(prompt, inferenceResults, setPaused, nowPlayingResult) }} >
|
|
|
|
<p className={className}>{prompt}</p>
|
|
|
|
</div>
|
|
|
|
);
|
2022-12-12 23:28:14 -07:00
|
|
|
case 2:
|
2022-12-14 13:44:10 -07:00
|
|
|
// active prompt
|
2022-12-12 23:28:14 -07:00
|
|
|
if (prompt == " " || prompt == "") {
|
|
|
|
return <span className="text-slate-600">{"<enter prompt>"}</span>;
|
|
|
|
} else {
|
2022-12-14 13:44:10 -07:00
|
|
|
return (
|
|
|
|
<div className="tooltip text-left" data-tip="🔁 Restart current prompt?" onClick={() => { jumpToPrompt(prompt, inferenceResults, setPaused, nowPlayingResult) }} >
|
|
|
|
<p className={className}>{prompt}</p>
|
|
|
|
</div>
|
|
|
|
)
|
2022-12-12 23:28:14 -07:00
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
if (prompt == " " || prompt == "") {
|
2022-12-14 13:44:10 -07:00
|
|
|
return <p className={className}>...</p>
|
2022-12-12 23:28:14 -07:00
|
|
|
} else {
|
2022-12-14 13:44:10 -07:00
|
|
|
return (
|
|
|
|
<div className="tooltip text-left" data-tip="🚀 Jump to upcoming prompt?" onClick={() => { jumpToPrompt(prompt, inferenceResults, setPaused, nowPlayingResult) }} >
|
|
|
|
<p className={className}>{prompt}</p>
|
|
|
|
</div>
|
|
|
|
)
|
2022-12-12 23:28:14 -07:00
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
if (prompt == " " || prompt == "") {
|
2022-12-14 13:44:10 -07:00
|
|
|
return <p className={className}>UP NEXT: Anything you want</p>;
|
2022-12-12 23:28:14 -07:00
|
|
|
} else {
|
2022-12-14 13:44:10 -07:00
|
|
|
return (
|
|
|
|
<div className="tooltip text-left" data-tip="🚀 Jump to upcoming prompt?" onClick={() => { jumpToPrompt(prompt, inferenceResults, setPaused, nowPlayingResult) }} >
|
|
|
|
<p className={className}>UP NEXT: {prompt}</p>
|
|
|
|
</div>
|
|
|
|
)
|
2022-12-12 23:28:14 -07:00
|
|
|
}
|
|
|
|
default: {
|
|
|
|
console.log("UNHANDLED default");
|
2022-12-14 13:44:10 -07:00
|
|
|
return <p className={className}>{prompt}</p>;
|
2022-12-12 23:28:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case PlayingState.TRANSITION:
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
2022-12-14 13:44:10 -07:00
|
|
|
return (
|
|
|
|
<div className="tooltip text-left" data-tip="⏪ Jump to previous prompt?" onClick={() => { jumpToPrompt(prompt, inferenceResults, setPaused, nowPlayingResult) }} >
|
|
|
|
<p className={className}>{prompt}</p>
|
|
|
|
</div>
|
|
|
|
);
|
2022-12-12 23:28:14 -07:00
|
|
|
case 1:
|
2022-12-14 13:44:10 -07:00
|
|
|
return (
|
|
|
|
<div className="tooltip text-left" data-tip="⏪ Jump to previous prompt?" onClick={() => { jumpToPrompt(prompt, inferenceResults, setPaused, nowPlayingResult) }} >
|
|
|
|
<p className={className}>{prompt}</p>
|
|
|
|
</div>
|
|
|
|
);
|
2022-12-12 23:28:14 -07:00
|
|
|
case 2:
|
2022-12-14 13:44:10 -07:00
|
|
|
return (
|
|
|
|
<div className="tooltip text-left" data-tip="🔁 Restart outgoing prompt?" onClick={() => { jumpToPrompt(prompt, inferenceResults, setPaused, nowPlayingResult) }} >
|
|
|
|
<p className={className}>{prompt}</p>
|
|
|
|
</div>
|
|
|
|
)
|
2022-12-12 23:28:14 -07:00
|
|
|
case 3:
|
|
|
|
if (prompt == " " || prompt == "") {
|
2022-12-14 13:44:10 -07:00
|
|
|
return <p className={className}> -enter prompt- </p>;
|
2022-12-12 23:28:14 -07:00
|
|
|
} else {
|
2022-12-14 13:44:10 -07:00
|
|
|
return (
|
|
|
|
<div className="tooltip text-left" data-tip="🚀 Jump to incoming prompt?" onClick={() => { jumpToPrompt(prompt, inferenceResults, setPaused, nowPlayingResult) }} >
|
|
|
|
<p className={className}>{prompt}</p>
|
|
|
|
</div>
|
|
|
|
)
|
2022-12-12 23:28:14 -07:00
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
if (prompt == " " || prompt == "") {
|
2022-12-14 13:44:10 -07:00
|
|
|
return <p className={className}>...</p>;
|
2022-12-12 23:28:14 -07:00
|
|
|
} else {
|
2022-12-14 13:44:10 -07:00
|
|
|
return (
|
|
|
|
<div className="tooltip text-left" data-tip="🚀 Jump to upcoming prompt?" onClick={() => { jumpToPrompt(prompt, inferenceResults, setPaused, nowPlayingResult) }} >
|
2022-12-15 01:06:30 -07:00
|
|
|
<p className={className}>{prompt}</p>
|
2022-12-14 13:44:10 -07:00
|
|
|
</div>
|
|
|
|
)
|
2022-12-12 23:28:14 -07:00
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
if (prompt == " " || prompt == "") {
|
2022-12-14 13:44:10 -07:00
|
|
|
return <p className={className}>UP NEXT: Anything you want</p>;
|
2022-12-12 23:28:14 -07:00
|
|
|
} else {
|
2022-12-14 13:44:10 -07:00
|
|
|
return (
|
|
|
|
<div className="tooltip text-left" data-tip="🚀 Jump to upcoming prompt?" onClick={() => { jumpToPrompt(prompt, inferenceResults, setPaused, nowPlayingResult) }} >
|
|
|
|
<p className={className}>UP NEXT: {prompt}</p>
|
|
|
|
</div>
|
|
|
|
)
|
2022-12-12 23:28:14 -07:00
|
|
|
}
|
|
|
|
default: {
|
|
|
|
console.log("UNHANDLED default");
|
2022-12-14 13:44:10 -07:00
|
|
|
return <p className={className}>{prompt}</p>;
|
2022-12-12 23:28:14 -07:00
|
|
|
}
|
2022-11-30 17:30:52 -07:00
|
|
|
}
|
|
|
|
}
|
2022-12-12 23:28:14 -07:00
|
|
|
};
|
2022-11-30 17:30:52 -07:00
|
|
|
|
2022-12-12 23:28:14 -07:00
|
|
|
return (
|
2022-12-14 15:54:27 -07:00
|
|
|
<div className="flex cursor-pointer">
|
2022-12-14 13:44:10 -07:00
|
|
|
{getPromptCopy(prompt)}
|
|
|
|
|
2022-12-12 23:28:14 -07:00
|
|
|
{/* TODO(hayk): Re-enable this when it's working. */}
|
|
|
|
{/* {index == 2 ? (
|
|
|
|
<IoMdClose
|
|
|
|
className="w-6 h-6 ml-2 text-gray-400"
|
|
|
|
onClick={() => {
|
|
|
|
resetCallback();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : null} */}
|
2022-12-14 13:44:10 -07:00
|
|
|
</div >
|
2022-12-12 23:28:14 -07:00
|
|
|
);
|
2022-11-30 17:30:52 -07:00
|
|
|
}
|
2022-12-14 13:44:10 -07:00
|
|
|
|
|
|
|
export function jumpToPrompt(prompt: String, inferenceResults: InferenceResult[], setPaused: (value: boolean) => void, nowPlayingResult?: InferenceResult) {
|
|
|
|
|
|
|
|
// Pause player since this function will open new tab that user will interact with
|
|
|
|
setPaused(true)
|
|
|
|
|
|
|
|
let firstTimePromptAppears = -1;
|
|
|
|
for (let i = 0; i < inferenceResults.length; i++) {
|
|
|
|
if (inferenceResults[i].input.start.prompt === prompt) {
|
|
|
|
firstTimePromptAppears = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (firstTimePromptAppears == -1) {
|
|
|
|
let url = generateLinkToUpcomingPrompt(prompt, nowPlayingResult)
|
2022-12-14 15:31:52 -07:00
|
|
|
window.location.href = url;
|
2022-12-14 13:44:10 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
let url = generateLinkToPreviousInput(inferenceResults[firstTimePromptAppears].input)
|
2022-12-14 15:31:52 -07:00
|
|
|
window.location.href = url;
|
2022-12-14 13:44:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function generateLinkToUpcomingPrompt(prompt, nowPlayingResult?: InferenceResult) {
|
|
|
|
|
|
|
|
var promptString = "&prompt=" + prompt;
|
|
|
|
promptString = promptString.replace(/ /g, "+");
|
|
|
|
|
|
|
|
if (nowPlayingResult != null) {
|
|
|
|
var denoisingString = "&denoising=" + nowPlayingResult.input.start.denoising;
|
|
|
|
var seedImageIdString = "&seedImageId=" + nowPlayingResult.input.seed_image_id;
|
|
|
|
} else {
|
|
|
|
denoisingString = "";
|
|
|
|
seedImageIdString = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
var baseUrl = window.location.origin + "/?";
|
|
|
|
var url = baseUrl + promptString + denoisingString + seedImageIdString;
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Todo: DRY this and share functions
|
|
|
|
export function generateLinkToPreviousInput(selectedInput: InferenceInput) {
|
|
|
|
var prompt;
|
|
|
|
var seed;
|
|
|
|
var denoising;
|
|
|
|
var maskImageId;
|
|
|
|
var seedImageId;
|
|
|
|
var guidance;
|
|
|
|
var numInferenceSteps;
|
|
|
|
var alphaVelocity;
|
|
|
|
|
|
|
|
prompt = selectedInput.start.prompt;
|
|
|
|
seed = selectedInput.start.seed;
|
|
|
|
denoising = selectedInput.start.denoising;
|
|
|
|
maskImageId = selectedInput.mask_image_id;
|
|
|
|
seedImageId = selectedInput.seed_image_id;
|
|
|
|
|
|
|
|
var baseUrl = window.location.origin + "/?";
|
|
|
|
|
|
|
|
if (prompt != null) {
|
|
|
|
var promptString = "&prompt=" + prompt;
|
|
|
|
} else {
|
|
|
|
promptString = "";
|
|
|
|
}
|
|
|
|
if (seed != null) {
|
|
|
|
var seedString = "&seed=" + seed;
|
|
|
|
} else {
|
|
|
|
seedString = "";
|
|
|
|
}
|
|
|
|
if (denoising != null) {
|
|
|
|
var denoisingString = "&denoising=" + denoising;
|
|
|
|
} else {
|
|
|
|
denoisingString = "";
|
|
|
|
}
|
|
|
|
if (maskImageId != null) {
|
|
|
|
var maskImageIdString = "&maskImageId=" + maskImageId;
|
|
|
|
} else {
|
|
|
|
maskImageIdString = "";
|
|
|
|
}
|
|
|
|
if (seedImageId != null) {
|
|
|
|
var seedImageIdString = "&seedImageId=" + seedImageId;
|
|
|
|
} else {
|
|
|
|
seedImageIdString = "";
|
|
|
|
}
|
|
|
|
if (guidance != null) {
|
|
|
|
var guidanceString = "&guidance=" + guidance;
|
|
|
|
} else {
|
|
|
|
guidanceString = "";
|
|
|
|
}
|
|
|
|
if (numInferenceSteps != null) {
|
|
|
|
var numInferenceStepsString = "&numInferenceSteps=" + numInferenceSteps;
|
|
|
|
} else {
|
|
|
|
numInferenceStepsString = "";
|
|
|
|
}
|
|
|
|
if (alphaVelocity != null) {
|
|
|
|
var alphaVelocityString = "&alphaVelocity=" + alphaVelocity;
|
|
|
|
} else {
|
|
|
|
alphaVelocityString = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format strings to have + in place of spaces for ease of sharing, note this is only necessary for prompts currently
|
|
|
|
promptString = promptString.replace(/ /g, "+");
|
|
|
|
|
|
|
|
// create url string with the variables above combined
|
|
|
|
var shareUrl =
|
|
|
|
baseUrl +
|
|
|
|
promptString +
|
|
|
|
seedString +
|
|
|
|
denoisingString +
|
|
|
|
maskImageIdString +
|
|
|
|
seedImageIdString +
|
|
|
|
guidanceString +
|
|
|
|
numInferenceStepsString +
|
|
|
|
alphaVelocityString;
|
|
|
|
|
|
|
|
return shareUrl;
|
|
|
|
}
|