Spaces:
Running
Running
fix
Browse files- media/audio/explain_1112505a6701429cb241d131a88bf709.wav +3 -0
- media/audio/explain_5c2a7427d1f14a2aa9fa9e59bb1ad603.wav +3 -0
- media/audio/explain_975ae1b5996743f6b76b5016f17056de.wav +3 -0
- media/audio/explain_ca92720c882d4926973973aa4b9f2316.wav +3 -0
- media/audio/explain_cc24a21b0b374e50bc8afbf73a7398c4.wav +3 -0
- media/audio/explain_dd70fb52325d44fc84cde7c1c9215232.wav +3 -0
- media/audio/synth_22ebf1e3b9404b34a41b2fdc2c691adb.wav +3 -0
- media/audio/synth_2757240115da4ba3a9aa1286aee57db9.wav +3 -0
- media/audio/synth_4965badeb7da43ffac0c3a7af781ab0f.wav +3 -0
- media/audio/synth_7bccf943f0b24880b77aa038b38f8bf1.wav +3 -0
- media/audio/synth_ee1e3e992d6641b9a06d214e0e67ea92.wav +3 -0
- ragg/app.py +111 -12
media/audio/explain_1112505a6701429cb241d131a88bf709.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0f7aae706a5bc1c25e9cf61ddc970ab3d0454650c14a936c7da051556c057091
|
| 3 |
+
size 1951916
|
media/audio/explain_5c2a7427d1f14a2aa9fa9e59bb1ad603.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:af65a4273dbbcb6aa004215de1f58b1fd964bcdb1df04ce10a0a872a920b29c5
|
| 3 |
+
size 634956
|
media/audio/explain_975ae1b5996743f6b76b5016f17056de.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7c54cd66b876ad6ab7ad9b7420fd38e2aa80e625e5d34be2fb3ef9d96461ddff
|
| 3 |
+
size 503372
|
media/audio/explain_ca92720c882d4926973973aa4b9f2316.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:14a428d11bba10b2f51c72826a9339dde62189153473796269b0fd7a09f27c54
|
| 3 |
+
size 193612
|
media/audio/explain_cc24a21b0b374e50bc8afbf73a7398c4.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a1dff985cf893840190f1f1e8229e99c80ed5651035f820c1590e39690fc009f
|
| 3 |
+
size 175692
|
media/audio/explain_dd70fb52325d44fc84cde7c1c9215232.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e37bd2a66186f0e2ca5ee4a02b0a9b63977af13f9bf5bb32f006f8a2066edcf7
|
| 3 |
+
size 470092
|
media/audio/synth_22ebf1e3b9404b34a41b2fdc2c691adb.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7137826339f483af77865b9dfd96c2386311e5cfcc52ca5990a011fabdd12fab
|
| 3 |
+
size 1287340
|
media/audio/synth_2757240115da4ba3a9aa1286aee57db9.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:675814fca44682416fa92128edc0b7637c3afdeeea7043f7a167ce36f4ac4a01
|
| 3 |
+
size 676972
|
media/audio/synth_4965badeb7da43ffac0c3a7af781ab0f.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bab5cb8d0e45d587f484120aaad8eefb100a757ab3c91b8909afedbc199ce106
|
| 3 |
+
size 157772
|
media/audio/synth_7bccf943f0b24880b77aa038b38f8bf1.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2914d7c32525eaf3ab30bedbca0a1dc3a9d1145dad34a0c45eb13f28d67f3d7e
|
| 3 |
+
size 465484
|
media/audio/synth_ee1e3e992d6641b9a06d214e0e67ea92.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8747b294606c0766d55d6d24adc2c5ace29259c1f1969bae781f92e25dfb456f
|
| 3 |
+
size 505932
|
ragg/app.py
CHANGED
|
@@ -332,6 +332,115 @@ def rag_generate_questions():
|
|
| 332 |
|
| 333 |
|
| 334 |
# @rag_bp.route("/explain-grammar", methods=["POST", "OPTIONS"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
@rag_bp.route("/explain-grammar", methods=["POST", "OPTIONS"])
|
| 336 |
def rag_explain_grammar():
|
| 337 |
if request.method == "OPTIONS":
|
|
@@ -391,18 +500,8 @@ def rag_explain_grammar():
|
|
| 391 |
reference_files=None,
|
| 392 |
language=data.get("language", "en"),
|
| 393 |
)
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
base = request.host_url.rstrip("/")
|
| 397 |
-
result_dict["audio_url"] = f"{base}/rag/audio/{wav_path.name}"
|
| 398 |
-
else:
|
| 399 |
-
# Deployed: try S3 first; fallback to public SPACE_URL if set
|
| 400 |
-
s3_url = _upload_to_s3(str(wav_path))
|
| 401 |
-
if s3_url:
|
| 402 |
-
result_dict["audio_url"] = s3_url
|
| 403 |
-
else:
|
| 404 |
-
base = os.getenv("SPACE_URL", "https://pykara-py-learn-backend.hf.space")
|
| 405 |
-
result_dict["audio_url"] = f"{base}/rag/audio/{wav_path.name}"
|
| 406 |
except FileNotFoundError as e:
|
| 407 |
current_app.logger.error("XTTS reference audio missing: %s", e)
|
| 408 |
except Exception as e:
|
|
|
|
| 332 |
|
| 333 |
|
| 334 |
# @rag_bp.route("/explain-grammar", methods=["POST", "OPTIONS"])
|
| 335 |
+
# @rag_bp.route("/explain-grammar", methods=["POST", "OPTIONS"])
|
| 336 |
+
# def rag_explain_grammar():
|
| 337 |
+
# if request.method == "OPTIONS":
|
| 338 |
+
# return ("", 204)
|
| 339 |
+
|
| 340 |
+
# data = request.get_json(force=True) or {}
|
| 341 |
+
|
| 342 |
+
# # --- Extract username and db_level ---
|
| 343 |
+
# username = extract_username_from_request(request)
|
| 344 |
+
# db_level = user_to_db_level(username)
|
| 345 |
+
|
| 346 |
+
# # --- MAIN BODY (your preferred structure) ---
|
| 347 |
+
# body = ExplainBody(
|
| 348 |
+
# question=(data.get("question") or "").strip(),
|
| 349 |
+
# model=data.get("model", "gpt-4o-mini"),
|
| 350 |
+
# db_level=db_level,
|
| 351 |
+
# source_ids=data.get("source_ids") or []
|
| 352 |
+
# )
|
| 353 |
+
|
| 354 |
+
# # --- 1) Run LLM / RAG explanation ---
|
| 355 |
+
# result_raw = llm_explain(body)
|
| 356 |
+
|
| 357 |
+
# # --- 2) Normalize + extract answer safely ---
|
| 358 |
+
# result_dict = None
|
| 359 |
+
# answer_text = ""
|
| 360 |
+
# try:
|
| 361 |
+
# if isinstance(result_raw, dict):
|
| 362 |
+
# result_dict = dict(result_raw)
|
| 363 |
+
# elif hasattr(result_raw, "model_dump"):
|
| 364 |
+
# result_dict = result_raw.model_dump()
|
| 365 |
+
# elif hasattr(result_raw, "dict"):
|
| 366 |
+
# result_dict = result_raw.dict()
|
| 367 |
+
# elif isinstance(result_raw, str):
|
| 368 |
+
# result_dict = {"answer": result_raw}
|
| 369 |
+
# else:
|
| 370 |
+
# result_dict = {"answer": str(result_raw)}
|
| 371 |
+
|
| 372 |
+
# answer_text = (
|
| 373 |
+
# result_dict.get("answer")
|
| 374 |
+
# or result_dict.get("response")
|
| 375 |
+
# or result_dict.get("text")
|
| 376 |
+
# or ""
|
| 377 |
+
# ).strip()
|
| 378 |
+
# except Exception as e:
|
| 379 |
+
# current_app.logger.exception("Failed to normalize llm_explain result: %s", e)
|
| 380 |
+
# return jsonify({"error": "Internal error normalizing LLM response"}), 500
|
| 381 |
+
|
| 382 |
+
# # --- 3) Optional: synthesize TTS audio ---
|
| 383 |
+
# try:
|
| 384 |
+
# if data.get("synthesize_audio"):
|
| 385 |
+
# try:
|
| 386 |
+
# out_name = f"explain_{uuid.uuid4().hex}.wav"
|
| 387 |
+
# wav_path = xtts_speak_to_file(
|
| 388 |
+
# text=answer_text or result_dict.get("answer", ""),
|
| 389 |
+
# out_file=AUDIO_DIR / out_name,
|
| 390 |
+
# reference_dir=XTTS_REF_DIR,
|
| 391 |
+
# reference_files=None,
|
| 392 |
+
# language=data.get("language", "en"),
|
| 393 |
+
# )
|
| 394 |
+
# # Local: serve from /rag/audio/*
|
| 395 |
+
# if "localhost" in request.host_url or "127.0.0.1" in request.host_url:
|
| 396 |
+
# base = request.host_url.rstrip("/")
|
| 397 |
+
# result_dict["audio_url"] = f"{base}/rag/audio/{wav_path.name}"
|
| 398 |
+
# else:
|
| 399 |
+
# # Deployed: try S3 first; fallback to public SPACE_URL if set
|
| 400 |
+
# s3_url = _upload_to_s3(str(wav_path))
|
| 401 |
+
# if s3_url:
|
| 402 |
+
# result_dict["audio_url"] = s3_url
|
| 403 |
+
# else:
|
| 404 |
+
# base = os.getenv("SPACE_URL", "https://pykara-py-learn-backend.hf.space")
|
| 405 |
+
# result_dict["audio_url"] = f"{base}/rag/audio/{wav_path.name}"
|
| 406 |
+
# except FileNotFoundError as e:
|
| 407 |
+
# current_app.logger.error("XTTS reference audio missing: %s", e)
|
| 408 |
+
# except Exception as e:
|
| 409 |
+
# current_app.logger.exception("XTTS synthesis during explain-grammar failed: %s", e)
|
| 410 |
+
# except Exception:
|
| 411 |
+
# current_app.logger.exception("Unexpected error while attempting inline synthesis")
|
| 412 |
+
|
| 413 |
+
# # --- 4) Optional: synthesize video (D-ID) ---
|
| 414 |
+
# try:
|
| 415 |
+
# if data.get("synthesize_video"):
|
| 416 |
+
# if not DID_API_KEY or not DID_SOURCE_IMAGE_URL:
|
| 417 |
+
# current_app.logger.error("D-ID not configured for inline explain-grammar video synthesis")
|
| 418 |
+
# else:
|
| 419 |
+
# try:
|
| 420 |
+
# talk_id, err = _did_create_talk(answer_text or result_dict.get("answer", ""))
|
| 421 |
+
# if err:
|
| 422 |
+
# current_app.logger.error(
|
| 423 |
+
# "D-ID create error during explain-grammar: %s",
|
| 424 |
+
# err[0] if isinstance(err, tuple) else err,
|
| 425 |
+
# )
|
| 426 |
+
# else:
|
| 427 |
+
# video_url, err = _did_poll_talk(talk_id, timeout_sec=120, interval_sec=2.0)
|
| 428 |
+
# if err:
|
| 429 |
+
# current_app.logger.error(
|
| 430 |
+
# "D-ID poll error during explain-grammar: %s",
|
| 431 |
+
# err[0] if isinstance(err, tuple) else err,
|
| 432 |
+
# )
|
| 433 |
+
# else:
|
| 434 |
+
# if video_url:
|
| 435 |
+
# result_dict["video_url"] = video_url
|
| 436 |
+
# except Exception as e:
|
| 437 |
+
# current_app.logger.exception("D-ID inline synthesis failed during explain-grammar: %s", e)
|
| 438 |
+
# except Exception:
|
| 439 |
+
# current_app.logger.exception("Unexpected error while attempting inline video synthesis")
|
| 440 |
+
|
| 441 |
+
# # --- Final response ---
|
| 442 |
+
# return jsonify(result_dict), 200
|
| 443 |
+
|
| 444 |
@rag_bp.route("/explain-grammar", methods=["POST", "OPTIONS"])
|
| 445 |
def rag_explain_grammar():
|
| 446 |
if request.method == "OPTIONS":
|
|
|
|
| 500 |
reference_files=None,
|
| 501 |
language=data.get("language", "en"),
|
| 502 |
)
|
| 503 |
+
base = request.host_url.rstrip("/")
|
| 504 |
+
result_dict["audio_url"] = f"{base}/rag/audio/{wav_path.name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 505 |
except FileNotFoundError as e:
|
| 506 |
current_app.logger.error("XTTS reference audio missing: %s", e)
|
| 507 |
except Exception as e:
|