Spaces:
Running
Running
Commit ·
bc4388d
1
Parent(s): 403e6d8
add wizard
Browse files- app.py +2 -0
- routes_wizard.py +66 -0
app.py
CHANGED
|
@@ -8,6 +8,7 @@ from supabase_ie import load_history_for_display
|
|
| 8 |
from datetime import datetime
|
| 9 |
from routes_utils import router as utils_router
|
| 10 |
from routes_stt import router as stt_router
|
|
|
|
| 11 |
|
| 12 |
from translate_query_response import (
|
| 13 |
detect_language_code,
|
|
@@ -28,6 +29,7 @@ APP.add_middleware(
|
|
| 28 |
allow_methods=["*"],
|
| 29 |
allow_headers=["*"],
|
| 30 |
)
|
|
|
|
| 31 |
|
| 32 |
# --- Supabase JWT secret (HS256) ---
|
| 33 |
JWT_SECRET = os.environ.get("SUPABASE_JWT_SECRET")
|
|
|
|
| 8 |
from datetime import datetime
|
| 9 |
from routes_utils import router as utils_router
|
| 10 |
from routes_stt import router as stt_router
|
| 11 |
+
from routes_wizard import router as wizard_router
|
| 12 |
|
| 13 |
from translate_query_response import (
|
| 14 |
detect_language_code,
|
|
|
|
| 29 |
allow_methods=["*"],
|
| 30 |
allow_headers=["*"],
|
| 31 |
)
|
| 32 |
+
APP.include_router(wizard_router)
|
| 33 |
|
| 34 |
# --- Supabase JWT secret (HS256) ---
|
| 35 |
JWT_SECRET = os.environ.get("SUPABASE_JWT_SECRET")
|
routes_wizard.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# routes_wizard.py
|
| 2 |
+
from fastapi import APIRouter, HTTPException
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
|
| 5 |
+
from translate_query_response import translate_to_english, translate_from_english
|
| 6 |
+
|
| 7 |
+
router = APIRouter(prefix="/wizard", tags=["wizard"])
|
| 8 |
+
|
| 9 |
+
# ---- Modello richiesta ----
|
| 10 |
+
class StringsReq(BaseModel):
|
| 11 |
+
ui_lang: str
|
| 12 |
+
|
| 13 |
+
class TranslateReq(BaseModel):
|
| 14 |
+
text: str
|
| 15 |
+
target_lang: str = "en"
|
| 16 |
+
|
| 17 |
+
# ---- Le stringhe base EN (uguali alle tue in index.tsx) ----
|
| 18 |
+
WIZARD_COPY_EN = {
|
| 19 |
+
"step1_q": "Which language do you prefer for our dialogue?",
|
| 20 |
+
"step1_ph": "e.g. English, Italiano...",
|
| 21 |
+
"step2_q": "By what name shall I address you in our conversations?",
|
| 22 |
+
"step2_ph": "Your name",
|
| 23 |
+
"step3_q": "In what country do you now make your home?",
|
| 24 |
+
"step3_ph": "Country you live in",
|
| 25 |
+
"step4_q": "And from which country do your roots, or your family’s roots, arise?",
|
| 26 |
+
"step4_ph": "Country of origin",
|
| 27 |
+
"step5_q": "Finally, which interests or pursuits most often occupy your thoughts and curiosity?",
|
| 28 |
+
"step5_ph": "Comma separated (e.g. parenting, football, philosophy)",
|
| 29 |
+
"next": "NEXT →",
|
| 30 |
+
"prev": "← PREVIOUS",
|
| 31 |
+
"finish": "FINISH",
|
| 32 |
+
"saving": "SAVING...",
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
@router.post("/strings")
|
| 36 |
+
async def wizard_strings(req: StringsReq):
|
| 37 |
+
ui_lang = (req.ui_lang or "en").lower().strip()
|
| 38 |
+
if ui_lang == "en":
|
| 39 |
+
return {"copy": WIZARD_COPY_EN}
|
| 40 |
+
|
| 41 |
+
# Traduci ogni campo dall'inglese alla lingua richiesta
|
| 42 |
+
out = {}
|
| 43 |
+
for k, v in WIZARD_COPY_EN.items():
|
| 44 |
+
try:
|
| 45 |
+
out[k] = translate_from_english(v, ui_lang)
|
| 46 |
+
except Exception:
|
| 47 |
+
out[k] = v # fallback EN se qualcosa va storto
|
| 48 |
+
|
| 49 |
+
return {"copy": out}
|
| 50 |
+
|
| 51 |
+
@router.post("/translate")
|
| 52 |
+
async def wizard_translate(req: TranslateReq):
|
| 53 |
+
text = (req.text or "").strip()
|
| 54 |
+
if not text:
|
| 55 |
+
return {"translated_text": ""}
|
| 56 |
+
|
| 57 |
+
target = (req.target_lang or "en").lower().strip()
|
| 58 |
+
try:
|
| 59 |
+
if target == "en":
|
| 60 |
+
return {"translated_text": translate_to_english(text)}
|
| 61 |
+
else:
|
| 62 |
+
# se ti serve anche tradurre verso altre lingue
|
| 63 |
+
en = translate_to_english(text)
|
| 64 |
+
return {"translated_text": translate_from_english(en, target)}
|
| 65 |
+
except Exception as e:
|
| 66 |
+
raise HTTPException(status_code=500, detail=str(e))
|