add inference results to profile

This commit is contained in:
Brandon Thomas committed 2021-05-29 21:17:10 -04:00
1 parent ddc562fa0e
commit b5eea6970a
5 files changed
+112 -3

No files matched your search

+6 -1
View File
@@ -65,10 +65,15 @@ class ApiConfig {
return `${this.getScheme()}://${this.getNewApiHost()}/profile/${username}`;
}
listW2lForUser(username: string) : string {
listW2lTemplatesForUser(username: string) : string {
return `${this.getScheme()}://${this.getNewApiHost()}/user/${username}/w2l_templates`;
}
listW2lInferenceResultsForUser(username: string) : string {
return `${this.getScheme()}://${this.getNewApiHost()}/user/${username}/w2l_results`;
}
private getScheme() : string {
return this.isLocalDev ? "http" : "https";
}
@@ -3,6 +3,7 @@ import { ApiConfig } from '../../v1/api/ApiConfig';
import { Profile_W2lTemplateListFc } from './Profile_W2lTemplateListFc';
import { RouteProps } from 'react-router-dom';
import { SessionWrapper } from '../../session/SessionWrapper';
import { Profile_W2lInferenceResultsListFc } from './Profile_W2lInferenceResultListFc';
interface ProfileResponsePayload {
success: boolean,
@@ -115,6 +116,12 @@ class ProfileComponent extends React.Component<Props, State> {
<h3 className="title is-3"> Uploaded Templates </h3>
<Profile_W2lTemplateListFc username={username} />
<br />
<br />
<h3 className="title is-3"> Lipsync Results </h3>
<Profile_W2lInferenceResultsListFc username={username} />
</div>
)
}
@@ -0,0 +1,97 @@
import React, { useState, useEffect } from 'react';
import { ApiConfig } from '../../v1/api/ApiConfig';
import { Link } from "react-router-dom";
interface W2lInferenceResultListResponsePayload {
success: boolean,
results: Array<W2lInferenceResult>,
}
interface W2lInferenceResult {
w2l_result_token: string,
maybe_w2l_template_token?: string,
maybe_tts_inference_result_token?: string,
template_type: string,
template_title: string,
maybe_creator_user_token?: string,
maybe_creator_username?: string,
maybe_creator_display_name?: string,
file_size_bytes: number,
frame_width: number,
frame_height: number,
duration_millis: number,
created_at: string,
updated_at: string,
}
interface Props {
username: string,
}
function Profile_W2lInferenceResultsListFc(props: Props) {
const [w2lResults, setW2lResults] = useState<Array<W2lInferenceResult>>([]);
useEffect(() => {
const api = new ApiConfig();
const endpointUrl = api.listW2lInferenceResultsForUser(props.username);
fetch(endpointUrl, {
method: 'GET',
headers: {
'Accept': 'application/json',
},
credentials: 'include',
})
.then(res => res.json())
.then(res => {
console.log('list', res);
const templatesResponse : W2lInferenceResultListResponsePayload = res;
if (!templatesResponse.success) {
return;
}
setW2lResults(templatesResponse.results)
})
.catch(e => {
//this.props.onSpeakErrorCallback();
});
}, []); // NB: Empty array dependency sets to run ONLY on mount
let rows : Array<JSX.Element> = [];
w2lResults.forEach(result => {
let duration_seconds = result.duration_millis / 1000;
let title = result.template_title.length < 5 ? `Title: ${result.template_title}` : result.template_title;
rows.push(
<tr>
<th><Link to="/">{title}</Link></th>
<td>{duration_seconds} s</td>
<td>{result.created_at} s</td>
</tr>
);
});
return (
<div>
<table className="table">
<thead>
<tr>
<th><abbr title="Detail">Title</abbr></th>
<th><abbr title="Detail">Duration</abbr></th>
<th><abbr title="Value">Creation Date (UTC)</abbr></th>
</tr>
</thead>
<tbody>
{rows}
</tbody>
</table>
</div>
)
}
export { Profile_W2lInferenceResultsListFc };
@@ -34,7 +34,7 @@ function Profile_W2lTemplateListFc(props: Props) {
useEffect(() => {
const api = new ApiConfig();
const endpointUrl = api.listW2lForUser(props.username);
const endpointUrl = api.listW2lTemplatesForUser(props.username);
fetch(endpointUrl, {
method: 'GET',
@@ -34,7 +34,7 @@ function ProfileData_W2lTemplateListFc(props: Props) {
useEffect(() => {
const api = new ApiConfig();
const endpointUrl = api.listW2lForUser(props.username);
const endpointUrl = api.listW2lTemplatesForUser(props.username);
fetch(endpointUrl, {
method: 'GET',