Download src/App.tsx from Bombog944/Trans: direct link, hf CLI and curl.
- Browser
- Download file 2.47 kB
-
https://huggingface.co/spaces/Bombog944/Trans/resolve/main/src/App.tsx
- Command line
-
hf download hf://spaces/Bombog944/Trans/src/App.tsx
-
curl -L -o App.tsx https://huggingface.co/spaces/Bombog944/Trans/resolve/main/src/App.tsx
2.47 kB
| import React, { useState } from "react"; | |
| export default function App() { | |
| const [file, setFile] = useState<File | null>(null); | |
| const [originalText, setOriginalText] = useState(""); | |
| const [translated, setTranslated] = useState(""); | |
| const [loading, setLoading] = useState(false); | |
| async function handleTranslate() { | |
| if (!file) return; | |
| setLoading(true); | |
| const text = await file.text(); | |
| setOriginalText(text); | |
| const res = await fetch("https://libretranslate.com/translate", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ q: text, source: "auto", target: "ar", format: "text" }), | |
| }); | |
| const data = await res.json(); | |
| setTranslated(data.translatedText); | |
| setLoading(false); | |
| } | |
| return ( | |
| <div> | |
| <h1 style={{ textAlign: "center", color: "#1a73e8" }}>📘 Document Translator</h1> | |
| <div style={{ textAlign: "center", margin: "20px 0" }}> | |
| <input | |
| type="file" | |
| accept=".txt,.docx,.pdf" | |
| onChange={(e) => setFile(e.target.files?.[0] || null)} | |
| style={{ | |
| padding: "10px", | |
| border: "2px dashed #1a73e8", | |
| borderRadius: "10px", | |
| cursor: "pointer", | |
| }} | |
| /> | |
| <br /> | |
| <button | |
| onClick={handleTranslate} | |
| disabled={!file || loading} | |
| style={{ | |
| marginTop: 20, | |
| padding: "10px 25px", | |
| background: "#1a73e8", | |
| color: "white", | |
| border: "none", | |
| borderRadius: 8, | |
| cursor: "pointer", | |
| }} | |
| > | |
| {loading ? "Translating..." : "Translate"} | |
| </button> | |
| </div> | |
| {loading && <p style={{ textAlign: "center" }}>⏳ Translating, please wait...</p>} | |
| {translated && ( | |
| <div | |
| style={{ | |
| display: "grid", | |
| gridTemplateColumns: "1fr 1fr", | |
| gap: 20, | |
| marginTop: 30, | |
| }} | |
| > | |
| <div style={{ background: "#f1f3f4", padding: 20, borderRadius: 10 }}> | |
| <h3>Original Text</h3> | |
| <p style={{ whiteSpace: "pre-wrap" }}>{originalText}</p> | |
| </div> | |
| <div style={{ background: "#e8f0fe", padding: 20, borderRadius: 10 }}> | |
| <h3>Translated (Arabic)</h3> | |
| <p style={{ direction: "rtl", whiteSpace: "pre-wrap" }}>{translated}</p> | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| ); | |
| } |