MyTranslator / app.py
moslem's picture
Update app.py
aa0ae99 verified
raw
history blame
675 Bytes
from fastapi import FastAPI, Query
from transformers import pipeline
# ساخت اپ FastAPI
app = FastAPI(title="English–Persian Translator")
# لود مدل سبک ترجمه (عمومی و بدون نیاز به لاگین)
translator_en_fa = pipeline(
"translation_en_to_fa",
model="Helsinki-NLP/opus-mt-en-fa",
trust_remote_code=True
)
@app.get("/")
def home():
return {"message": "Welcome to English–Persian Translator!"}
@app.get("/translate")
def translate(text: str = Query(..., description="English text to translate to Persian")):
result = translator_en_fa(text)
return {"input": text, "translation": result[0]["translation_text"]}