Meshal Falah commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,31 @@
|
|
| 1 |
-
|
| 2 |
-
import gradio as gr
|
| 3 |
-
from rag_system import RAGSystem # تأكد أن الملف اسمه rag_system.py وموجود في نفس المجلد
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
)
|
| 11 |
|
|
|
|
|
|
|
| 12 |
rag.load_vectorstore()
|
| 13 |
rag.load_llm()
|
| 14 |
rag.get_prompt_template()
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
outputs=gr.Textbox(label="Answer"),
|
| 25 |
-
title="ECC Cybersecurity Assistant",
|
| 26 |
-
description="Ask questions based on the Essential Cybersecurity Controls (ECC) Implementation Guide issued by the NCA (Saudi Arabia).",
|
| 27 |
-
)
|
| 28 |
-
|
| 29 |
-
if __name__ == "__main__":
|
| 30 |
-
demo.launch()
|
|
|
|
| 1 |
+
# app.py
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
from fastapi import FastAPI, HTTPException
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
from rag_system import RAGSystem
|
| 6 |
+
|
| 7 |
+
# نموذج بيانات الطلب
|
| 8 |
+
class QuestionRequest(BaseModel):
|
| 9 |
+
question: str
|
| 10 |
+
|
| 11 |
+
# إنشاء التطبيق
|
| 12 |
+
app = FastAPI(
|
| 13 |
+
title="ECC Compliance Assistant API",
|
| 14 |
+
description="Ask questions based on the ECC Cybersecurity Guide using RAG",
|
| 15 |
+
version="1.0.0"
|
| 16 |
)
|
| 17 |
|
| 18 |
+
# تحميل النظام عند بدء التشغيل
|
| 19 |
+
rag = RAGSystem(vector_db_path="vector_db")
|
| 20 |
rag.load_vectorstore()
|
| 21 |
rag.load_llm()
|
| 22 |
rag.get_prompt_template()
|
| 23 |
|
| 24 |
+
# نقطة النهاية
|
| 25 |
+
@app.post("/ask")
|
| 26 |
+
async def ask_question(data: QuestionRequest):
|
| 27 |
+
try:
|
| 28 |
+
answer = rag.ask_question(data.question)
|
| 29 |
+
return {"question": data.question, "answer": answer}
|
| 30 |
+
except Exception as e:
|
| 31 |
+
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|