Update app.py
Browse files
app.py
CHANGED
|
@@ -417,17 +417,18 @@ async def translate(
|
|
| 417 |
except Exception as e:
|
| 418 |
raise HTTPException(status_code=500, detail=f"Error during translation: {e}")
|
| 419 |
|
| 420 |
-
from
|
| 421 |
-
translator = Translator()
|
| 422 |
|
| 423 |
@app.get("/api/google_translate")
|
| 424 |
-
def google_translate(q: str, from_: Optional[str] =
|
| 425 |
try:
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
|
|
|
|
|
|
| 431 |
except Exception as e:
|
| 432 |
raise HTTPException(status_code=500, detail=f"Error during translation: {e}")
|
| 433 |
|
|
|
|
| 417 |
except Exception as e:
|
| 418 |
raise HTTPException(status_code=500, detail=f"Error during translation: {e}")
|
| 419 |
|
| 420 |
+
from easygoogletranslate import EasyGoogleTranslate
|
|
|
|
| 421 |
|
| 422 |
@app.get("/api/google_translate")
|
| 423 |
+
def google_translate(q: str, from_: Optional[str] = 'auto', to: str = "en"):
|
| 424 |
try:
|
| 425 |
+
translator = EasyGoogleTranslate(
|
| 426 |
+
source_language=from_,
|
| 427 |
+
target_language=to,
|
| 428 |
+
timeout=10
|
| 429 |
+
)
|
| 430 |
+
result = translator.translate('This is an example.')
|
| 431 |
+
return JSONResponse(content=jsonable_encoder({"detected_language": from_ , "original": q , "translated": result}))
|
| 432 |
except Exception as e:
|
| 433 |
raise HTTPException(status_code=500, detail=f"Error during translation: {e}")
|
| 434 |
|