Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -417,6 +417,18 @@ async def translate(
|
|
| 417 |
except Exception as e:
|
| 418 |
raise HTTPException(status_code=500, detail=f"Error during translation: {e}")
|
| 419 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
@app.get("/api/youtube/transcript")
|
| 421 |
async def youtube_transcript(
|
| 422 |
video_id: str,
|
|
|
|
| 417 |
except Exception as e:
|
| 418 |
raise HTTPException(status_code=500, detail=f"Error during translation: {e}")
|
| 419 |
|
| 420 |
+
from googletrans import Translator
|
| 421 |
+
translator = Translator()
|
| 422 |
+
|
| 423 |
+
@app.get("/api/google_translate")
|
| 424 |
+
def google_translate(q: str, from_: Optional[str] = None, to: str = "en"):
|
| 425 |
+
try:
|
| 426 |
+
translations = translator.translate(q, dest=to, src=from_)
|
| 427 |
+
return JSONResponse(content=jsonable_encoder("detected_language": {translations.src} , "original": {translations.origin} , "translated": {translations.text}))
|
| 428 |
+
except Exception as e:
|
| 429 |
+
raise HTTPException(status_code=500, detail=f"Error during translation: {e}")
|
| 430 |
+
|
| 431 |
+
|
| 432 |
@app.get("/api/youtube/transcript")
|
| 433 |
async def youtube_transcript(
|
| 434 |
video_id: str,
|