CoolFace
Apppublic

admin08077/Githubgemini

sourceHugging Faceotherupdated 10mo agoView on Hugging Face
0likes
AiStyleTransfer-DgF2wuEc.js.map1 linesDownload Raw Back to assets
1{"version":3,"file":"AiStyleTransfer-DgF2wuEc.js","sources":["../../components/features/AiStyleTransfer.tsx"],"sourcesContent":["import React, { useState, useCallback } from 'react';\nimport { transferCodeStyleStream } from '../../services/index.ts';\nimport { SparklesIcon } from '../icons.tsx';\nimport { LoadingSpinner } from '../shared/index.tsx';\nimport { MarkdownRenderer } from '../shared/index.tsx';\n\nconst exampleCode = `function my_func(x,y){return x+y;}`;\nconst exampleStyleGuide = `- Use camelCase for function names.\n- Add a space after commas in argument lists.\n- Use semicolons at the end of statements.`;\n\nexport const AiStyleTransfer: React.FC = () => {\n    const [inputCode, setInputCode] = useState<string>(exampleCode);\n    const [styleGuide, setStyleGuide] = useState<string>(exampleStyleGuide);\n    const [outputCode, setOutputCode] = useState<string>('');\n    const [isLoading, setIsLoading] = useState<boolean>(false);\n    const [error, setError] = useState<string>('');\n\n    const handleGenerate = useCallback(async () => {\n        if (!inputCode.trim() || !styleGuide.trim()) {\n            setError('Please provide both code and a style guide.');\n            return;\n        }\n        setIsLoading(true);\n        setError('');\n        setOutputCode('');\n        try {\n            const stream = transferCodeStyleStream({ code: inputCode, styleGuide });\n            let fullResponse = '';\n            for await (const chunk of stream) {\n                fullResponse += chunk;\n                setOutputCode(fullResponse);\n            }\n        } catch (err) {\n            const errorMessage = err instanceof Error ? err.message : 'An unknown error occurred.';\n            setError(`Failed to transfer style: ${errorMessage}`);\n        } finally {\n            setIsLoading(false);\n        }\n    }, [inputCode, styleGuide]);\n\n    return (\n        <div className=\"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary\">\n            <header className=\"mb-6\">\n                <h1 className=\"text-3xl font-bold flex items-center\">\n                    <SparklesIcon />\n                    <span className=\"ml-3\">AI Code Style Transfer</span>\n                </h1>\n                <p className=\"text-text-secondary mt-1\">Rewrite code to match a specific style guide using AI.</p>\n            </header>\n            <div className=\"flex-grow flex flex-col gap-4 min-h-0\">\n                <div className=\"flex flex-col flex-1 min-h-0\">\n                    <label htmlFor=\"input-code\" className=\"text-sm font-medium text-text-secondary mb-2\">Original Code</label>\n                    <textarea\n                        id=\"input-code\"\n                        value={inputCode}\n                        onChange={(e) => setInputCode(e.target.value)}\n                        className=\"flex-grow p-4 bg-surface border border-border rounded-md resize-y font-mono text-sm\"\n                    />\n                </div>\n                 <div className=\"flex flex-col flex-1 min-h-0\">\n                    <label htmlFor=\"style-guide\" className=\"text-sm font-medium text-text-secondary mb-2\">Style Guide</label>\n                    <textarea\n                        id=\"style-guide\"\n                        value={styleGuide}\n                        onChange={(e) => setStyleGuide(e.target.value)}\n                        className=\"flex-grow p-4 bg-surface border border-border rounded-md resize-y font-mono text-sm\"\n                    />\n                </div>\n                 <div className=\"flex-shrink-0\">\n                    <button\n                        onClick={handleGenerate}\n                        disabled={isLoading}\n                        className=\"btn-primary w-full max-w-xs mx-auto flex items-center justify-center px-6 py-3\"\n                    >\n                        {isLoading ? <LoadingSpinner /> : 'Rewrite Code'}\n                    </button>\n                </div>\n                <div className=\"flex flex-col flex-1 min-h-0\">\n                    <label className=\"text-sm font-medium text-text-secondary mb-2\">Rewritten Code</label>\n                    <div className=\"flex-grow p-1 bg-background border border-border rounded-md overflow-y-auto\">\n                        {isLoading && !outputCode && <div className=\"flex items-center justify-center h-full\"><LoadingSpinner /></div>}\n                        {error && <p className=\"p-4 text-red-500\">{error}</p>}\n                        {outputCode && <MarkdownRenderer content={outputCode} />}\n                         {!isLoading && !outputCode && !error && <div className=\"text-text-secondary h-full flex items-center justify-center\">Rewritten code will appear here.</div>}\n                    </div>\n                </div>\n            </div>\n        </div>\n    );\n};"],"names":["exampleCode","exampleStyleGuide","AiStyleTransfer","inputCode","setInputCode","useState","styleGuide","setStyleGuide","outputCode","setOutputCode","isLoading","setIsLoading","error","setError","handleGenerate","useCallback","stream","transferCodeStyleStream","fullResponse","chun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