diff --git a/frontend/components/Models.tsx b/frontend/components/Models.tsx index da952f8..41bf4e2 100644 --- a/frontend/components/Models.tsx +++ b/frontend/components/Models.tsx @@ -7,18 +7,11 @@ import { Box, Heading, Text, - Button, - Image, - Icon, - IconButton, - createIcon, - IconProps, - useColorModeValue, Link, HStack, } from "@chakra-ui/react"; import { useQuery } from "react-query"; -import { API_URL, LANGUAGE_CODE_NAMES } from "@/app/config"; +import { API_URL } from "@/app/config"; import { useEffect, useState } from "react"; import axios from "axios"; import NMT from "./TryOut/NMT"; @@ -34,7 +27,38 @@ const fetchModel = async ({ title }: { title: string }) => { } }; -export default function ModelView({ slug }: { slug: Array }) { +interface Model { + service_id: string; + inferenceSchema: any; + languageFilters: any; + hfData: any; + conference: string; + paper_link: string | undefined; + github_link: string | undefined; + title: string; + description?: string; +} + +const renderTryOut = ({ area, model }: { area: string; model: Model }) => { + switch (area) { + case "NMT": + return ( + + ); + } +}; + +export default function ModelView({ + area, + title, +}: { + area: string; + title: string; +}) { const [model, setModel] = useState<{ service_id: string; inferenceSchema: any; @@ -57,13 +81,11 @@ export default function ModelView({ slug }: { slug: Array }) { service_id: "", }); - const [hfData, setHFData] = useState({}); - const { isLoading: modelLoading, error: modelError, data: modelData, - } = useQuery(["fetchModel", slug], () => fetchModel({ title: slug[1] })); + } = useQuery(["fetchModel", title], () => fetchModel({ title: title })); useEffect(() => { if (modelError || modelLoading) { @@ -112,16 +134,20 @@ export default function ModelView({ slug }: { slug: Array }) { Conference : {model.conference} - - - Downloads : {model.hfData.downloads} - - + {model.hfData.downloads ? ( + + + Downloads : {model.hfData.downloads} + + + ) : ( + <> + )} {model.description} @@ -150,11 +176,7 @@ export default function ModelView({ slug }: { slug: Array }) { position={"relative"} w={"full"} > - + {renderTryOut({ area: area, model: model })} diff --git a/frontend/src/app/areas/model/[...slug]/page.tsx b/frontend/src/app/areas/model/[...slug]/page.tsx deleted file mode 100644 index d5639af..0000000 --- a/frontend/src/app/areas/model/[...slug]/page.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import ModelView from "../../../../../components/Models"; - -interface ParamsType { - slug: Array; -} - -interface Model { - area: string; - title: string; -} - -export async function generateStaticParams() { - const models = await fetch("https://admin.models.ai4bharat.org/models/").then( - (res) => res.json() - ); - - return models.map((model: Model) => ({ - slug: [model.area, model.title], - })); -} - -export default function Model({ params }: { params: ParamsType }) { - const slug = params.slug; - return ( - <> - - - ); -} diff --git a/frontend/src/app/areas/model/[area]/[title]/page.tsx b/frontend/src/app/areas/model/[area]/[title]/page.tsx new file mode 100644 index 0000000..9885943 --- /dev/null +++ b/frontend/src/app/areas/model/[area]/[title]/page.tsx @@ -0,0 +1,44 @@ +import { title } from "process"; +import ModelView from "../../../../../../components/Models"; + +interface ParamsType { + slug: Array; +} + +interface Model { + area: string; + title: string; +} + +import axios from "axios"; + +export async function generateStaticParams() { + const response = await axios.get( + "https://admin.models.ai4bharat.org/models/" + ); + const models = response.data; + + let params: any[] = []; + + models.forEach((model: Model) => { + params.push({ + area: model.area, + title: model.title, + }); + }); + + return params; +} + +export const dynamicParams = true; +export default function Model({ + params, +}: { + params: { area: string; title: string }; +}) { + return ( + <> + + + ); +}