laurencassidy commited on
Commit
d51b62c
·
verified ·
1 Parent(s): 6dda66c

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +12 -0
  2. README.md +29 -7
  3. app.py +45 -0
  4. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY app.py .
9
+
10
+ EXPOSE 7860
11
+
12
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,12 +1,34 @@
1
  ---
2
- title: Ga En
3
- emoji: 👀
4
- colorFrom: gray
5
- colorTo: blue
6
  sdk: docker
7
  pinned: false
8
- license: mit
9
- short_description: translation api
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Irish English Translation API
3
+ emoji: 🌍
4
+ colorFrom: green
5
+ colorTo: yellow
6
  sdk: docker
7
  pinned: false
 
 
8
  ---
9
 
10
+ # Irish-English Translation API
11
+
12
+ FastAPI backend for Irish (Gaeilge) to English translation.
13
+
14
+ ## Endpoints
15
+
16
+ - `GET /` - Health check
17
+ - `POST /translate` - Translate text
18
+
19
+ ## Request format
20
+
21
+ ```json
22
+ {
23
+ "text": "Dia dhuit",
24
+ "direction": "ga-en"
25
+ }
26
+ ```
27
+
28
+ ## Response format
29
+
30
+ ```json
31
+ {
32
+ "translation": "Hello"
33
+ }
34
+ ```
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from pydantic import BaseModel
4
+ from transformers import pipeline
5
+
6
+ app = FastAPI()
7
+
8
+ # Allow CORS for your website
9
+ app.add_middleware(
10
+ CORSMiddleware,
11
+ allow_origins=["*"], # Update with your actual domain in production
12
+ allow_credentials=True,
13
+ allow_methods=["*"],
14
+ allow_headers=["*"],
15
+ )
16
+
17
+ # Load translation models
18
+ # Using Helsinki-NLP models - you can replace with your own fine-tuned models
19
+ ga_en_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ga-en")
20
+ en_ga_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ga")
21
+
22
+
23
+ class TranslationRequest(BaseModel):
24
+ text: str
25
+ direction: str # "ga-en" or "en-ga"
26
+
27
+
28
+ class TranslationResponse(BaseModel):
29
+ translation: str
30
+
31
+
32
+ @app.get("/")
33
+ def read_root():
34
+ return {"status": "Irish-English Translation API is running"}
35
+
36
+
37
+ @app.post("/translate", response_model=TranslationResponse)
38
+ def translate(request: TranslationRequest):
39
+ if request.direction == "ga-en":
40
+ result = ga_en_translator(request.text, max_length=512)
41
+ else:
42
+ result = en_ga_translator(request.text, max_length=512)
43
+
44
+ translation = result[0]["translation_text"]
45
+ return TranslationResponse(translation=translation)
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ transformers
4
+ torch
5
+ sentencepiece
6
+ sacremoses