fix build errors

This commit is contained in:
Hayk Martiros 2022-12-14 23:28:35 -08:00
parent bf21089f97
commit df35e1fd20
2 changed files with 98 additions and 95 deletions

View File

@ -58,109 +58,112 @@ export default function Share({
} }
// function to generate a link to a the moment in the song based on the played clips, input variable is how many seconds ago // function to generate a link to a the moment in the song based on the played clips, input variable is how many seconds ago
function generateLink(secondsAgo: number) { const generateLink = useCallback(
var prompt; (secondsAgo: number) => {
var seed; var prompt;
var denoising; var seed;
var maskImageId; var denoising;
var seedImageId; var maskImageId;
var guidance; var seedImageId;
var numInferenceSteps; var guidance;
var alphaVelocity; var numInferenceSteps;
var alphaVelocity;
const result = nowPlayingResult ? nowPlayingResult : inferenceResults[0]; const result = nowPlayingResult ? nowPlayingResult : inferenceResults[0];
if (!result) { if (!result) {
return window.location.href; return window.location.href;
} else {
var selectedInput: InferenceResult["input"];
if (secondsAgo == 0) {
selectedInput = result.input;
} else { } else {
var selectedCounter = result.counter - secondsAgo / 5; var selectedInput: InferenceResult["input"];
selectedInput = inferenceResults.find( if (secondsAgo == 0) {
(result) => result.counter == selectedCounter selectedInput = result.input;
)?.input; } else {
var selectedCounter = result.counter - secondsAgo / 5;
selectedInput = inferenceResults.find(
(result) => result.counter == selectedCounter
)?.input;
if (!selectedInput) { if (!selectedInput) {
// TODO: ideally don't show the button in this case... // TODO: ideally don't show the button in this case...
return window.location.href; return window.location.href;
}
} }
// TODO: Consider only including in the link the things that are different from the default values
prompt = selectedInput.start.prompt;
seed = selectedInput.start.seed;
denoising = selectedInput.start.denoising;
maskImageId = selectedInput.mask_image_id;
seedImageId = result.input.seed_image_id;
// TODO, selectively add these based on whether we give user option to change them
// guidance = result.input.guidance
// numInferenceSteps = result.input.num_inference_steps
// alphaVelocity = result.input.alpha_velocity
} }
// TODO: Consider only including in the link the things that are different from the default values var baseUrl = window.location.origin + "/?";
prompt = selectedInput.start.prompt;
seed = selectedInput.start.seed;
denoising = selectedInput.start.denoising;
maskImageId = selectedInput.mask_image_id;
seedImageId = result.input.seed_image_id;
// TODO, selectively add these based on whether we give user option to change them if (prompt != null) {
// guidance = result.input.guidance var promptString = "&prompt=" + prompt;
// numInferenceSteps = result.input.num_inference_steps } else {
// alphaVelocity = result.input.alpha_velocity 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 = "";
}
var baseUrl = window.location.origin + "/?"; // Format strings to have + in place of spaces for ease of sharing, note this is only necessary for prompts currently
promptString = promptString.replace(/ /g, "+");
if (prompt != null) { // create url string with the variables above combined
var promptString = "&prompt=" + prompt; var shareUrl =
} else { baseUrl +
promptString = ""; promptString +
} seedString +
if (seed != null) { denoisingString +
var seedString = "&seed=" + seed; maskImageIdString +
} else { seedImageIdString +
seedString = ""; guidanceString +
} numInferenceStepsString +
if (denoising != null) { alphaVelocityString;
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 return shareUrl;
promptString = promptString.replace(/ /g, "+"); },
[nowPlayingResult, inferenceResults]
// create url string with the variables above combined );
var shareUrl =
baseUrl +
promptString +
seedString +
denoisingString +
maskImageIdString +
seedImageIdString +
guidanceString +
numInferenceStepsString +
alphaVelocityString;
return shareUrl;
}
const getRedditLink = useCallback(() => { const getRedditLink = useCallback(() => {
if (inferenceResults.length == 0) { if (inferenceResults.length == 0) {
@ -172,7 +175,7 @@ export default function Share({
const encodedPrompt = encodeURIComponent(result.input.start.prompt); const encodedPrompt = encodeURIComponent(result.input.start.prompt);
const encodedUrl = encodeURIComponent(generateLink(0)); const encodedUrl = encodeURIComponent(generateLink(0));
return `https://www.reddit.com/r/riffusion/submit?title=Prompt:+${encodedPrompt}&url=${encodedUrl}`; return `https://www.reddit.com/r/riffusion/submit?title=Prompt:+${encodedPrompt}&url=${encodedUrl}`;
}, [nowPlayingResult, inferenceResults]); }, [nowPlayingResult, inferenceResults, generateLink]);
const getTwitterLink = useCallback(() => { const getTwitterLink = useCallback(() => {
if (inferenceResults.length == 0) { if (inferenceResults.length == 0) {
@ -187,7 +190,7 @@ export default function Share({
return `https://twitter.com/intent/tweet?&text=Check+out+this+prompt+on+%23riffusion:+${encodeURI( return `https://twitter.com/intent/tweet?&text=Check+out+this+prompt+on+%23riffusion:+${encodeURI(
'"' '"'
)}${encodedPrompt}${encodeURI('"')}${encodeURI("\n\n")}${encodedUrl}`; )}${encodedPrompt}${encodeURI('"')}${encodeURI("\n\n")}${encodedUrl}`;
}, [nowPlayingResult, inferenceResults]); }, [nowPlayingResult, inferenceResults, generateLink]);
return ( return (
<> <>

View File

@ -476,7 +476,7 @@ export default function Home() {
<h2 className="pt-10 pb-5 text-3xl font-bold">Samples</h2> <h2 className="pt-10 pb-5 text-3xl font-bold">Samples</h2>
<p> <p>
Some of our favorite prompts and results. Check out{" "} Some of our favorite prompts and results. Check out{" "}
<a href="http://reddit.com/r/riffusion" target="_blank"> <a href="http://reddit.com/r/riffusion" target="_blank" rel="noreferrer">
/r/riffusion /r/riffusion
</a>{" "} </a>{" "}
for more. for more.