Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,8 @@ from helpers.output_clipper import clip_by_ranges
|
|
| 8 |
from parser.assembler import parse_law_from_texts
|
| 9 |
from supabase_utils import save_law_to_supabase
|
| 10 |
from helpers.indexer import build_indexed_response
|
|
|
|
|
|
|
| 11 |
app = FastAPI(
|
| 12 |
title="Text Extractor API",
|
| 13 |
description="API لاستخراج النصوص من صفحات الويب مع إمكانية التحكم في النطاقات",
|
|
@@ -139,3 +141,21 @@ async def extract_indexed(request: IndexedURLRequest):
|
|
| 139 |
|
| 140 |
except Exception as e:
|
| 141 |
raise HTTPException(status_code=500, detail=f"خطأ في معالجة المحتوى: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
from parser.assembler import parse_law_from_texts
|
| 9 |
from supabase_utils import save_law_to_supabase
|
| 10 |
from helpers.indexer import build_indexed_response
|
| 11 |
+
from helpers.indexer_simple import build_indexed
|
| 12 |
+
|
| 13 |
app = FastAPI(
|
| 14 |
title="Text Extractor API",
|
| 15 |
description="API لاستخراج النصوص من صفحات الويب مع إمكانية التحكم في النطاقات",
|
|
|
|
| 141 |
|
| 142 |
except Exception as e:
|
| 143 |
raise HTTPException(status_code=500, detail=f"خطأ في معالجة المحتوى: {str(e)}")
|
| 144 |
+
|
| 145 |
+
# ============================
|
| 146 |
+
# نقطة نهاية GET جديدة
|
| 147 |
+
# ============================
|
| 148 |
+
@app.get("/extract_link")
|
| 149 |
+
async def extract_link_get(
|
| 150 |
+
url: HttpUrl = Query(..., description="رابط الصفحة المراد استخراج النصوص منها"),
|
| 151 |
+
timeout: int = Query(10, ge=1, le=60, description="مهلة الطلب بالثواني")
|
| 152 |
+
):
|
| 153 |
+
try:
|
| 154 |
+
# 1) استخراج النصوص الخام من الرابط
|
| 155 |
+
raw_texts = await extract_text_from_url(str(url), timeout)
|
| 156 |
+
|
| 157 |
+
# 2) بناء القائمة المفهرسة
|
| 158 |
+
return build_indexed(texts=raw_texts)
|
| 159 |
+
|
| 160 |
+
except Exception as e:
|
| 161 |
+
raise HTTPException(status_code=500, detail=f"خطأ في معالجة المحتوى: {str(e)}")
|