Download frontend/src/hooks/useTransform.ts from dipan004/CreepURL: direct link, hf CLI and curl.
- Browser
- Download file 996 Bytes
-
https://huggingface.co/spaces/dipan004/CreepURL/resolve/main/frontend/src/hooks/useTransform.ts
- Command line
-
hf download hf://spaces/dipan004/CreepURL/frontend/src/hooks/useTransform.ts
-
curl -L -o useTransform.ts https://huggingface.co/spaces/dipan004/CreepURL/resolve/main/frontend/src/hooks/useTransform.ts
996 Bytes
| import { useState } from 'react' | |
| import { transformURL, TransformResponse } from '@/services/api' | |
| export type GenerationState = 'idle' | 'loading' | 'success' | 'error' | |
| export function useTransform() { | |
| const [state, setState] = useState<GenerationState>('idle') | |
| const [result, setResult] = useState<TransformResponse | null>(null) | |
| const [error, setError] = useState<string | null>(null) | |
| const transform = async (url: string, destructionLevel: number) => { | |
| setState('loading') | |
| setError(null) | |
| try { | |
| const data = await transformURL({ url, destruction_level: destructionLevel }) | |
| setResult(data) | |
| setState('success') | |
| } catch (err: unknown) { | |
| const message = | |
| err instanceof Error ? err.message : 'Something went wrong. The packet was lost.' | |
| setError(message) | |
| setState('error') | |
| } | |
| } | |
| const reset = () => { | |
| setState('idle') | |
| setResult(null) | |
| setError(null) | |
| } | |
| return { state, result, error, transform, reset } | |
| } | |