Spaces:
Sleeping
Sleeping
Commit
·
2949aaa
1
Parent(s):
1768b63
runtime: add app.storage using /tmp/rag_data; import it in api.py; replace hardcoded /data
Browse files- app/api.py +7 -7
- app/storage.py +2 -2
app/api.py
CHANGED
|
@@ -24,7 +24,7 @@ __version__ = "1.3.2"
|
|
| 24 |
|
| 25 |
app = FastAPI(title="RAG API", version=__version__)
|
| 26 |
|
| 27 |
-
#
|
| 28 |
app.add_middleware(
|
| 29 |
CORSMiddleware,
|
| 30 |
allow_origins=["*"], # tighten if needed
|
|
@@ -33,7 +33,7 @@ app.add_middleware(
|
|
| 33 |
allow_headers=["*"],
|
| 34 |
)
|
| 35 |
|
| 36 |
-
#
|
| 37 |
rag = SimpleRAG()
|
| 38 |
|
| 39 |
METRICS: Dict[str, Any] = {
|
|
@@ -44,7 +44,7 @@ METRICS: Dict[str, Any] = {
|
|
| 44 |
}
|
| 45 |
HISTORY: List[Dict[str, Any]] = [] # [{"question":..., "timestamp":...}]
|
| 46 |
|
| 47 |
-
#
|
| 48 |
class UploadResponse(BaseModel):
|
| 49 |
message: str
|
| 50 |
filename: str
|
|
@@ -66,7 +66,7 @@ class HistoryResponse(BaseModel):
|
|
| 66 |
total_chunks: int
|
| 67 |
history: List[Dict[str, Any]]
|
| 68 |
|
| 69 |
-
#
|
| 70 |
@app.get("/")
|
| 71 |
def root():
|
| 72 |
return RedirectResponse(url="/docs")
|
|
@@ -84,7 +84,7 @@ def health():
|
|
| 84 |
@app.get("/debug/translate")
|
| 85 |
def debug_translate():
|
| 86 |
"""
|
| 87 |
-
Simple smoke test for the AZ
|
| 88 |
"""
|
| 89 |
try:
|
| 90 |
from transformers import pipeline # type: ignore
|
|
@@ -94,7 +94,7 @@ def debug_translate():
|
|
| 94 |
cache_dir=str(rag.cache_dir),
|
| 95 |
device=-1,
|
| 96 |
)
|
| 97 |
-
out = tr("S
|
| 98 |
return {"ok": True, "example_out": out}
|
| 99 |
except Exception as e:
|
| 100 |
return {"ok": False, "error": str(e)}
|
|
@@ -214,5 +214,5 @@ async def _ensure_dirs():
|
|
| 214 |
# HISTORY_JSON parent is DATA_DIR
|
| 215 |
HISTORY_JSON.parent.mkdir(parents=True, exist_ok=True)
|
| 216 |
except Exception:
|
| 217 |
-
# boot-un
|
| 218 |
pass
|
|
|
|
| 24 |
|
| 25 |
app = FastAPI(title="RAG API", version=__version__)
|
| 26 |
|
| 27 |
+
# в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ CORS в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ
|
| 28 |
app.add_middleware(
|
| 29 |
CORSMiddleware,
|
| 30 |
allow_origins=["*"], # tighten if needed
|
|
|
|
| 33 |
allow_headers=["*"],
|
| 34 |
)
|
| 35 |
|
| 36 |
+
# в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ Core singleton & metrics в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ
|
| 37 |
rag = SimpleRAG()
|
| 38 |
|
| 39 |
METRICS: Dict[str, Any] = {
|
|
|
|
| 44 |
}
|
| 45 |
HISTORY: List[Dict[str, Any]] = [] # [{"question":..., "timestamp":...}]
|
| 46 |
|
| 47 |
+
# в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ Models в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ
|
| 48 |
class UploadResponse(BaseModel):
|
| 49 |
message: str
|
| 50 |
filename: str
|
|
|
|
| 66 |
total_chunks: int
|
| 67 |
history: List[Dict[str, Any]]
|
| 68 |
|
| 69 |
+
# в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ Routes в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ
|
| 70 |
@app.get("/")
|
| 71 |
def root():
|
| 72 |
return RedirectResponse(url="/docs")
|
|
|
|
| 84 |
@app.get("/debug/translate")
|
| 85 |
def debug_translate():
|
| 86 |
"""
|
| 87 |
+
Simple smoke test for the AZ→EN translator pipeline (if available).
|
| 88 |
"""
|
| 89 |
try:
|
| 90 |
from transformers import pipeline # type: ignore
|
|
|
|
| 94 |
cache_dir=str(rag.cache_dir),
|
| 95 |
device=-1,
|
| 96 |
)
|
| 97 |
+
out = tr("SР™в„ўnР™в„ўd tР™в„ўmiri vР™в„ў quraЕџdД±rД±lmasД± ilР™в„ў baДџlД± iЕџlР™в„ўr gГ¶rР“СlР“Сb.", max_length=80)[0]["translation_text"]
|
| 98 |
return {"ok": True, "example_out": out}
|
| 99 |
except Exception as e:
|
| 100 |
return {"ok": False, "error": str(e)}
|
|
|
|
| 214 |
# HISTORY_JSON parent is DATA_DIR
|
| 215 |
HISTORY_JSON.parent.mkdir(parents=True, exist_ok=True)
|
| 216 |
except Exception:
|
| 217 |
+
# boot-un dayanmasД±nД±n qarЕџД±sД±nД± alaq
|
| 218 |
pass
|
app/storage.py
CHANGED
|
@@ -22,8 +22,8 @@ def _first_writable(candidates):
|
|
| 22 |
|
| 23 |
DATA_DIR = _first_writable([
|
| 24 |
os.getenv("DATA_DIR") or None,
|
| 25 |
-
"/
|
| 26 |
-
"/app/
|
| 27 |
str(Path.home() / ".cache" / "rag_data"),
|
| 28 |
"/tmp/rag_data",
|
| 29 |
])
|
|
|
|
| 22 |
|
| 23 |
DATA_DIR = _first_writable([
|
| 24 |
os.getenv("DATA_DIR") or None,
|
| 25 |
+
"/tmp/rag_data",
|
| 26 |
+
"/app/tmp/rag_data",
|
| 27 |
str(Path.home() / ".cache" / "rag_data"),
|
| 28 |
"/tmp/rag_data",
|
| 29 |
])
|