frontend changes to support w2l inference (wip)

This commit is contained in:
Brandon Thomas committed 2021-05-28 01:18:04 -04:00
1 parent 99fb2b3dad
commit 480212a3dc
2 files changed
+70 -27

No files matched your search

+3
View File
@@ -57,6 +57,9 @@ class ApiConfig {
return `${this.getScheme()}://${this.getNewApiHost()}/w2l/template/${templateSlug}`;
}
inferW2l() : string {
return `${this.getScheme()}://${this.getNewApiHost()}/w2l/inference`;
}
getProfile(username: string) : string {
return `${this.getScheme()}://${this.getNewApiHost()}/profile/${username}`;
@@ -1,7 +1,9 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { ApiConfig } from '../../v1/api/ApiConfig';
import { SessionWrapper } from '../../session/SessionWrapper';
import { RouteProps, useHistory, useParams, Link } from 'react-router-dom';
import { SessionWrapper } from '../../session/SessionWrapper';
import { v1 as uuidv1 } from 'uuid';
interface W2lTemplateViewResponsePayload {
success: boolean,
@@ -34,6 +36,7 @@ function W2lTemplateViewFc(props: Props) {
let { templateSlug } = useParams();
const [w2lTemplate, setW2lTemplate] = useState<W2lTemplate|undefined>(undefined);
const [audioFile, setAudioFile] = useState<File|undefined>(undefined);
useEffect(() => {
const api = new ApiConfig();
@@ -61,8 +64,64 @@ function W2lTemplateViewFc(props: Props) {
});
}, []); // NB: Empty array dependency sets to run ONLY on mount
let creatorLink=`/profile/${w2lTemplate?.creator_username}`;
const handleAudioFileChange = (fileList: FileList|null) => {
if (fileList === null
|| fileList === undefined
|| fileList.length < 1) {
setAudioFile(undefined);
}
let file = fileList![0];
setAudioFile(file);
};
const handleFormSubmit = (ev: React.FormEvent<HTMLFormElement>) : boolean => {
ev.preventDefault();
if (audioFile === undefined) {
return false;
}
if (w2lTemplate === undefined) {
return false;
}
const templateToken = w2lTemplate!.template_token;
let formData = new FormData();
formData.append('audio', audioFile!);
formData.append('template_token', templateToken);
formData.append('uuid_idempotency_token', uuidv1()!);
const api = new ApiConfig();
const endpointUrl = api.inferW2l(templateToken);
// NB: Using 'axios' because 'fetch' was having problems with form-multipart
// and then interpreting the resultant JSON. Maybe I didn't try hard enough?
axios.post(endpointUrl, formData)
.then(res => res.data)
.then(res => {
/*if (res.uuid !== undefined) {
this.setState({
jobUuid: res.uuid
});
//let job = new VideoJob(res.uuid, VideoJobStatus.Pending);
//this.props.startVideoJobCallback(job);
// Make sure we show the processing status modal
window.scrollTo(0, document.body.scrollHeight);
}*/
console.log(res);
});
return false;
};
let creatorLink=`/profile/${w2lTemplate?.creator_username}`;
let object : string|undefined = undefined;
if (w2lTemplate?.maybe_image_object_name !== undefined && w2lTemplate?.maybe_image_object_name !== null) {
@@ -74,29 +133,10 @@ function W2lTemplateViewFc(props: Props) {
let url = `https://storage.googleapis.com/dev-vocodes-public${object}`;
const handleAudioFileChange = (fileList: FileList|null) => {
if (fileList === null
|| fileList === undefined
|| fileList.length < 1) {
//this.setState({
// audioFile: undefined,
//});
}
let file = fileList![0];
//this.setState({
// audioFile: file,
//});
};
const handleFormSubmit = (ev: React.FormEvent<HTMLFormElement>) : boolean => {
ev.preventDefault();
return false;
};
const audioFilename = 'filename.todo';
let audioFilename = '(select a file)';
if (audioFile !== undefined) {
audioFilename = audioFile?.name;
}
return (
<div>
@@ -105,8 +145,8 @@ function W2lTemplateViewFc(props: Props) {
<div className="content is-size-4">
<p>
Upload audio from vo.codes or any other source (music, other websites),
then pick a template below. The audio shouldn't be too long or it will
fail.
then submit. You'll get a lipsynced video. The audio shouldn't be too
long or it will fail.
</p>
</div>