Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,15 @@
|
|
| 1 |
from fastapi import FastAPI, Query
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# ساخت اپ FastAPI
|
| 5 |
app = FastAPI(title="English–Persian Translator")
|
| 6 |
|
| 7 |
-
|
| 8 |
-
translator_en_fa = pipeline(
|
| 9 |
-
"translation_en_to_fa",
|
| 10 |
-
model="Helsinki-NLP/opus-mt-en-fa",
|
| 11 |
-
trust_remote_code=True
|
| 12 |
-
)
|
| 13 |
|
| 14 |
@app.get("/")
|
| 15 |
def home():
|
| 16 |
return {"message": "Welcome to English–Persian Translator!"}
|
| 17 |
|
| 18 |
@app.get("/translate")
|
| 19 |
-
def translate(text: str = Query(
|
| 20 |
result = translator_en_fa(text)
|
| 21 |
return {"input": text, "translation": result[0]["translation_text"]}
|
|
|
|
| 1 |
from fastapi import FastAPI, Query
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
| 4 |
app = FastAPI(title="English–Persian Translator")
|
| 5 |
|
| 6 |
+
translator_en_fa = pipeline("translation_en_to_fa", model="Helsinki-NLP/opus-mt-en-fa")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
@app.get("/")
|
| 9 |
def home():
|
| 10 |
return {"message": "Welcome to English–Persian Translator!"}
|
| 11 |
|
| 12 |
@app.get("/translate")
|
| 13 |
+
def translate(text: str = Query(...)):
|
| 14 |
result = translator_en_fa(text)
|
| 15 |
return {"input": text, "translation": result[0]["translation_text"]}
|