-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added files for german translation pa
- Loading branch information
1 parent
a779137
commit 9972e55
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM python:3.9-slim | ||
|
||
WORKDIR /app | ||
|
||
COPY requirements.txt . | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY . . | ||
|
||
EXPOSE 8177 | ||
|
||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8177"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
import requests | ||
|
||
from fastapi import FastAPI, HTTPException | ||
from pydantic import BaseModel | ||
|
||
app = FastAPI() | ||
|
||
GIGACHAT_API_URL = os.getenv("GIGACHAT_API_URL", "http://gigachat-api:8187/respond") | ||
|
||
class TextInput(BaseModel): | ||
text: str | ||
|
||
@app.post("/translate") | ||
def translate_text(input: TextInput): | ||
data = { | ||
"dialog_contexts": [[input.text]], | ||
"prompts": ["You are a translator that translates English text into German."], | ||
"configs": [None], | ||
"gigachat_credentials": [os.getenv("GIGACHAT_CREDENTIAL")], | ||
"gigachat_scopes": [os.getenv("GIGACHAT_SCOPE")], | ||
} | ||
try: | ||
response = requests.post(GIGACHAT_API_URL, json=data) | ||
response.raise_for_status() | ||
result = response.json() | ||
translated_text = result[0][0] | ||
return {"translated_text": translated_text} | ||
except Exception as e: | ||
raise HTTPException(status_code=500, detail=str(e)) |