Spaces:
Runtime error
Runtime error
fix
Browse filesFiles changed (4)
14 unmodified lines1516171814 unmodified linesCHROMA_ROOT=C:/Users/DELL/Desktop/Deploymnet/29 oct/py-learn-backend/ragg/chromaEMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2ALLOWED_ORIGINS=http://localhost:4200,http://127.0.0.1:4200RAG_INGEST_URL=http://localhost:5000/rag/ingest14 unmodified lines15161718192021222314 unmodified linesCHROMA_ROOT=C:/Users/DELL/Desktop/Deploymnet/29 oct/py-learn-backend/ragg/chromaEMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2ALLOWED_ORIGINS=http://localhost:4200,http://127.0.0.1:4200RAG_INGEST_URL=http://localhost:5000/rag/ingestAWS_ACCESS_KEY_ID=AKIA3PWGNRHL7RTV3XRJAWS_SECRET_ACCESS_KEY=SZBvxZHPw8OVkrFd7nMXe+Nt/3ulrpynXVrGBiKmAWS_REGION=ap-south-1S3_BUCKET=pykara-tts-audioS3_PREFIX=audio/
123version https://git-lfs.github.com/spec/v1oid sha256:189a4ca997451cafe72c7652a89ccd0f43fc107064a075624af5499b10f219fesize 1092844123version https://git-lfs.github.com/spec/v1oid sha256:c0f7690ce19971fba91c94c34076908f61d335d88ddbcf456d57a98c53fd155bsize 130532411 unmodified lines12131415161785 unmodified lines103104105106107108211 unmodified lines320321322323324325326327328329330331332333248 unmodified lines58258358458558658758858959059159259359459559611 unmodified linesimport requestsfrom TTS.api import TTS# RAG importstry:85 unmodified linesexcept Exception:pass# Media and voice references# MEDIA_ROOT = Path(os.getenv("MEDIA_ROOT", "./media"))211 unmodified linesreference_files=None,language=data.get("language", "en"),)# ✅ Fixed for Hugging Face audio URLif "localhost" in request.host_url or "127.0.0.1" in request.host_url:base = request.host_url.rstrip("/")else:base = os.getenv("SPACE_URL", "https://pykara-py-learn-backend.hf.space")result_dict["audio_url"] = f"{base}/rag/audio/{wav_path.name}"# base = request.host_url.rstrip("/")# result_dict["audio_url"] = f"{base}/rag/audio/{wav_path.name}"except FileNotFoundError as e:current_app.logger.error("XTTS reference audio missing: %s", e)except Exception as e:248 unmodified linesreference_files=reference_files,language=language,)# ✅ Fixed for Hugging Face audio URLif "localhost" in request.host_url or "127.0.0.1" in request.host_url:base = request.host_url.rstrip("/")else:base = os.getenv("SPACE_URL", "https://pykara-py-learn-backend.hf.space")audio_url = f"{base}/rag/audio/{wav_path.name}"# base = request.host_url.rstrip("/") # e.g., http://localhost:7000# audio_url = f"{base}/rag/audio/{wav_path.name}"return jsonify({"audio_url": audio_url, "file": wav_path.name}), 200except FileNotFoundError as e:current_app.logger.error("XTTS references missing: %s", e)11 unmodified lines1213141516171819202122232485 unmodified lines110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158211 unmodified lines370371372373374375376377378379380381382383384385386387248 unmodified lines63663763863964064164264364464564664764864965065165265365411 unmodified linesimport requestsfrom TTS.api import TTS# --- S3 (added) ---try:import boto3from botocore.exceptions import NoCredentialsError, ClientErrorexcept Exception:boto3 = NoneNoCredentialsError = ClientError = Exception # fallbacks so type names exist# RAG importstry:85 unmodified linesexcept Exception:pass# --- S3 config (added) ---S3_BUCKET = os.getenv("S3_BUCKET", "").strip()AWS_REGION = os.getenv("AWS_REGION", "ap-south-1").strip()S3_PREFIX = os.getenv("S3_PREFIX", "audio/").strip()AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID", "").strip()AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY", "").strip()_s3_client = Noneif boto3 and S3_BUCKET and AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY:try:_s3_client = boto3.client("s3",region_name=AWS_REGION,aws_access_key_id=AWS_ACCESS_KEY_ID,aws_secret_access_key=AWS_SECRET_ACCESS_KEY,)except Exception as _e:_s3_client = Nonedef _upload_to_s3(file_path: Union[str, Path]) -> Optional[str]:"""Upload the file to S3 and return a presigned URL (24h).If S3 is not configured, returns None (caller will fallback)."""if not _s3_client or not S3_BUCKET:return Nonetry:file_path = str(file_path)key = f"{S3_PREFIX}{Path(file_path).name}"_s3_client.upload_file(file_path, S3_BUCKET, key)url = _s3_client.generate_presigned_url("get_object",Params={"Bucket": S3_BUCKET, "Key": key},ExpiresIn=24 * 3600,)return urlexcept (NoCredentialsError, ClientError) as e:try:current_app.logger.error(f"S3 upload failed: {e}")except Exception:print(f"S3 upload failed: {e}")return None# Media and voice references# MEDIA_ROOT = Path(os.getenv("MEDIA_ROOT", "./media"))211 unmodified linesreference_files=None,language=data.get("language", "en"),)# Local: serve from /rag/audio/*if "localhost" in request.host_url or "127.0.0.1" in request.host_url:base = request.host_url.rstrip("/")result_dict["audio_url"] = f"{base}/rag/audio/{wav_path.name}"else:# Deployed: try S3 first; fallback to public SPACE_URL if sets3_url = _upload_to_s3(str(wav_path))if s3_url:result_dict["audio_url"] = s3_urlelse:base = os.getenv("SPACE_URL", "https://pykara-py-learn-backend.hf.space")result_dict["audio_url"] = f"{base}/rag/audio/{wav_path.name}"except FileNotFoundError as e:current_app.logger.error("XTTS reference audio missing: %s", e)except Exception as e:248 unmodified linesreference_files=reference_files,language=language,)# Local: serve static fileif "localhost" in request.host_url or "127.0.0.1" in request.host_url:base = request.host_url.rstrip("/")audio_url = f"{base}/rag/audio/{wav_path.name}"else:# Deployed: try S3 first; fallback to SPACE_URLs3_url = _upload_to_s3(str(wav_path))if s3_url:audio_url = s3_urlelse:base = os.getenv("SPACE_URL", "https://pykara-py-learn-backend.hf.space")audio_url = f"{base}/rag/audio/{wav_path.name}"return jsonify({"audio_url": audio_url, "file": wav_path.name}), 200except FileNotFoundError as e:current_app.logger.error("XTTS references missing: %s", e)
.env+6-1
media/audio/explain_0f06635a143f44bd9e705a53485476d7.wavDeleted-3
media/audio/explain_1bf217407423408f8800bcb2a3db2d3b.wavDeleted-3
ragg/app.py+68-10