Skip to content

Commit

Permalink
added files for german translation pa
Browse files Browse the repository at this point in the history
  • Loading branch information
moon-strider committed Nov 5, 2024
1 parent a779137 commit 9972e55
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions annotators/german_translation_pa/Dockerfile
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.
30 changes: 30 additions & 0 deletions annotators/german_translation_pa/server.py
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))

0 comments on commit 9972e55

Please sign in to comment.