Spaces:
Running
Running
Cihangir Emre Er commited on
Commit ·
b20574a
1
Parent(s): 40dd0b6
regenerate function
Browse files
app.py
CHANGED
|
@@ -36,6 +36,10 @@ correction_store = CorrectionStore()
|
|
| 36 |
correction_svc = CorrectionService(kb=pipeline.kb, store=correction_store)
|
| 37 |
correction_svc.replay_corrections_on_startup()
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
class TranslateRequest(BaseModel):
|
| 40 |
report: str
|
| 41 |
|
|
@@ -137,6 +141,33 @@ async def get_correction(correction_id: str):
|
|
| 137 |
raise HTTPException(status_code=404, detail="Correction not found")
|
| 138 |
return record
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
@app.get("/admin/export-correction-store")
|
| 141 |
async def export_correction_store():
|
| 142 |
"""HF Spaces'taki güncel correction_store.db'yi indir."""
|
|
|
|
| 36 |
correction_svc = CorrectionService(kb=pipeline.kb, store=correction_store)
|
| 37 |
correction_svc.replay_corrections_on_startup()
|
| 38 |
|
| 39 |
+
class RegenerateRequest(BaseModel):
|
| 40 |
+
session_id: str
|
| 41 |
+
features: dict
|
| 42 |
+
|
| 43 |
class TranslateRequest(BaseModel):
|
| 44 |
report: str
|
| 45 |
|
|
|
|
| 141 |
raise HTTPException(status_code=404, detail="Correction not found")
|
| 142 |
return record
|
| 143 |
|
| 144 |
+
class RegenerateRequest(BaseModel):
|
| 145 |
+
features: dict # /predict'ten dönen features (zorunlu)
|
| 146 |
+
session_id: str = "" # audit için opsiyonel
|
| 147 |
+
|
| 148 |
+
@app.post("/regenerate-report")
|
| 149 |
+
async def regenerate_report(body: RegenerateRequest):
|
| 150 |
+
from src.query_builder import build_all_queries
|
| 151 |
+
from src.report_generator import build_report_prompt
|
| 152 |
+
|
| 153 |
+
features = body.features
|
| 154 |
+
queries = build_all_queries(features) if features.get("stone_detected") else []
|
| 155 |
+
|
| 156 |
+
largest_mm = features.get("largest_stone_mm")
|
| 157 |
+
size_filter = pipeline._stone_size_range(largest_mm) if largest_mm else None
|
| 158 |
+
|
| 159 |
+
retrieved = pipeline.retrieve_context(queries, size_filter=size_filter) if queries else []
|
| 160 |
+
|
| 161 |
+
system_prompt, user_prompt = build_report_prompt(features, retrieved)
|
| 162 |
+
report = llm.generate(system_prompt=system_prompt, user_prompt=user_prompt, temperature=0.3)
|
| 163 |
+
|
| 164 |
+
return {
|
| 165 |
+
"session_id": body.session_id,
|
| 166 |
+
"report": report,
|
| 167 |
+
"retrieved_context": retrieved,
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
|
| 171 |
@app.get("/admin/export-correction-store")
|
| 172 |
async def export_correction_store():
|
| 173 |
"""HF Spaces'taki güncel correction_store.db'yi indir."""
|