-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
27 lines (19 loc) · 669 Bytes
/
Copy pathmain.py
File metadata and controls
27 lines (19 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from dataclasses import asdict
from typing import Any
import functions_framework # type: ignore
from flask import Request
from translation import Translator, get_translation
from router import RequestRouter
translator = Translator()
app = RequestRouter()
@app.route("/", "POST")
def translate(data: dict[str, Any]) -> dict:
text = data["text"]
return asdict(get_translation(translator, text))
@app.route("/", "GET")
def status(_: dict[str, Any]) -> str:
return """<title>TranslationFunction</title>
<H1>The function is online.</H1>"""
@functions_framework.http
def TranslationFunction(request: Request) -> str:
return app.dispatch(request)