meshsl commited on
Commit
a5d2270
·
verified ·
1 Parent(s): b7c45aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -22
app.py CHANGED
@@ -1,31 +1,18 @@
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))
 
 
1
+ from fastapi import FastAPI, Request
 
 
 
2
  from rag_system import RAGSystem
3
 
4
+ app = FastAPI()
 
 
 
 
 
 
 
 
 
5
 
 
6
  rag = RAGSystem(vector_db_path="vector_db")
7
  rag.load_vectorstore()
8
  rag.load_llm()
9
  rag.get_prompt_template()
10
 
 
11
  @app.post("/ask")
12
+ async def ask_question(request: Request):
13
+ data = await request.json()
14
+ question = data.get("question")
15
+ if not question:
16
+ return {"error": "Question is required"}
17
+ answer = rag.ask_question(question)
18
+ return {"answer": answer}