Spaces:
Running
Running
push final
Browse files- multilingual/multi.py +4 -5
multilingual/multi.py
CHANGED
|
@@ -20,7 +20,7 @@ lang_codes = {
|
|
| 20 |
"sw": "swh_Latn"
|
| 21 |
}
|
| 22 |
|
| 23 |
-
#
|
| 24 |
|
| 25 |
app = FastAPI(
|
| 26 |
title="Farmlingua Translation API",
|
|
@@ -34,7 +34,7 @@ class Query(BaseModel):
|
|
| 34 |
|
| 35 |
def translate(text: str, src: str, tgt: str) -> str:
|
| 36 |
try:
|
| 37 |
-
out = translator(text, src_lang=lang_codes[src], tgt_lang=lang_codes[tgt])
|
| 38 |
return out[0]["translation_text"]
|
| 39 |
except Exception as e:
|
| 40 |
return f"Translation error: {str(e)}"
|
|
@@ -57,7 +57,6 @@ def query_milestone1(prompt: str) -> str:
|
|
| 57 |
# Root endpoint
|
| 58 |
@app.get("/")
|
| 59 |
def root():
|
| 60 |
-
"""Root endpoint with API information"""
|
| 61 |
return {
|
| 62 |
"message": "Welcome to Farmlingua Translation API",
|
| 63 |
"version": "3.0",
|
|
@@ -91,7 +90,7 @@ def multilingual_ask(query: Query):
|
|
| 91 |
if user_lang not in lang_codes:
|
| 92 |
return {"error": "Unsupported language. Use one of: en, ig, ha, yo, sw."}
|
| 93 |
|
| 94 |
-
#
|
| 95 |
lang_names = {
|
| 96 |
"en": "English",
|
| 97 |
"ig": "Igbo",
|
|
@@ -109,7 +108,7 @@ def multilingual_ask(query: Query):
|
|
| 109 |
# Get response from Milestone 1
|
| 110 |
english_response = query_milestone1(english_text)
|
| 111 |
|
| 112 |
-
# Translate response back to original language
|
| 113 |
if user_lang != "en":
|
| 114 |
final_response = translate(english_response, "en", user_lang)
|
| 115 |
else:
|
|
|
|
| 20 |
"sw": "swh_Latn"
|
| 21 |
}
|
| 22 |
|
| 23 |
+
# language identifier
|
| 24 |
|
| 25 |
app = FastAPI(
|
| 26 |
title="Farmlingua Translation API",
|
|
|
|
| 34 |
|
| 35 |
def translate(text: str, src: str, tgt: str) -> str:
|
| 36 |
try:
|
| 37 |
+
out = translator(text, src_lang=lang_codes[src], tgt_lang=lang_codes[tgt], max_length=400)
|
| 38 |
return out[0]["translation_text"]
|
| 39 |
except Exception as e:
|
| 40 |
return f"Translation error: {str(e)}"
|
|
|
|
| 57 |
# Root endpoint
|
| 58 |
@app.get("/")
|
| 59 |
def root():
|
|
|
|
| 60 |
return {
|
| 61 |
"message": "Welcome to Farmlingua Translation API",
|
| 62 |
"version": "3.0",
|
|
|
|
| 90 |
if user_lang not in lang_codes:
|
| 91 |
return {"error": "Unsupported language. Use one of: en, ig, ha, yo, sw."}
|
| 92 |
|
| 93 |
+
# language name for response
|
| 94 |
lang_names = {
|
| 95 |
"en": "English",
|
| 96 |
"ig": "Igbo",
|
|
|
|
| 108 |
# Get response from Milestone 1
|
| 109 |
english_response = query_milestone1(english_text)
|
| 110 |
|
| 111 |
+
# Translate response back to original language
|
| 112 |
if user_lang != "en":
|
| 113 |
final_response = translate(english_response, "en", user_lang)
|
| 114 |
else:
|