Spaces:
Sleeping
Sleeping
Commit
·
78bd110
1
Parent(s):
07f735f
Fix order: define app before endpoints; add /debug/translate
Browse files- app/api.py +23 -8
app/api.py
CHANGED
@@ -1,23 +1,38 @@
|
|
1 |
# app/api.py
|
2 |
-
from fastapi import FastAPI, UploadFile, File
|
3 |
from fastapi.middleware.cors import CORSMiddleware
|
4 |
-
from fastapi.responses import JSONResponse, RedirectResponse
|
5 |
-
from pathlib import Path
|
6 |
-
import shutil
|
7 |
-
import traceback
|
8 |
-
# app/api.py (importların altından)
|
9 |
from fastapi.responses import JSONResponse
|
|
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
@app.get("/debug/translate")
|
12 |
def debug_translate():
|
13 |
try:
|
14 |
from transformers import pipeline
|
15 |
-
tr = pipeline("translation", model="Helsinki-NLP/opus-mt-az-en", cache_dir=str(
|
16 |
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"]
|
17 |
-
return {"ok": True, "
|
18 |
except Exception as e:
|
19 |
return JSONResponse(status_code=500, content={"ok": False, "error": str(e)})
|
20 |
|
|
|
|
|
|
|
21 |
|
22 |
from .rag_system import SimpleRAG, UPLOAD_DIR, synthesize_answer as summarize
|
23 |
from .schemas import AskRequest, AskResponse, UploadResponse, HistoryResponse, HistoryItem
|
|
|
1 |
# app/api.py
|
2 |
+
from fastapi import FastAPI, UploadFile, File, Form
|
3 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
|
|
|
|
4 |
from fastapi.responses import JSONResponse
|
5 |
+
from pydantic import BaseModel
|
6 |
+
from typing import List, Optional
|
7 |
|
8 |
+
from .rag_system import SimpleRAG, UPLOAD_DIR, synthesize_answer as summarize
|
9 |
+
|
10 |
+
app = FastAPI(title="RAG API", version="1.2.2")
|
11 |
+
|
12 |
+
app.add_middleware(
|
13 |
+
CORSMiddleware,
|
14 |
+
allow_origins=["*"],
|
15 |
+
allow_credentials=True,
|
16 |
+
allow_methods=["*"],
|
17 |
+
allow_headers=["*"],
|
18 |
+
)
|
19 |
+
|
20 |
+
rag = SimpleRAG()
|
21 |
+
|
22 |
+
# --- Debug: translator test ---
|
23 |
@app.get("/debug/translate")
|
24 |
def debug_translate():
|
25 |
try:
|
26 |
from transformers import pipeline
|
27 |
+
tr = pipeline("translation", model="Helsinki-NLP/opus-mt-az-en", cache_dir=str(rag.cache_dir), device=-1)
|
28 |
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"]
|
29 |
+
return {"ok": True, "example_out": out}
|
30 |
except Exception as e:
|
31 |
return JSONResponse(status_code=500, content={"ok": False, "error": str(e)})
|
32 |
|
33 |
+
# ... qalan endpointlər (health, upload_pdf, ask_question, get_history) buradan sonra gəlir ...
|
34 |
+
|
35 |
+
|
36 |
|
37 |
from .rag_system import SimpleRAG, UPLOAD_DIR, synthesize_answer as summarize
|
38 |
from .schemas import AskRequest, AskResponse, UploadResponse, HistoryResponse, HistoryItem
|