Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,30 @@
|
|
1 |
-
from fastapi import FastAPI, Query
|
2 |
-
from langchain_community.vectorstores import Chroma
|
3 |
-
from langchain_community.embeddings import HuggingFaceEmbeddings
|
4 |
-
from together import Together
|
5 |
import os
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
messages=[
|
17 |
-
{"role": "system", "content": "You are a helpful assistant."},
|
18 |
-
{"role": "user", "content": prompt}
|
19 |
-
]
|
20 |
-
)
|
21 |
-
return response.choices[0].message.content
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
docs = vectordb.similarity_search(q, k=3)
|
28 |
-
context = "\n".join([doc.page_content for doc in docs])
|
29 |
-
final_prompt = f"Use the context below to answer the question.\n\nContext:\n{context}\n\nQuestion: {q}"
|
30 |
-
answer = call_llama(final_prompt)
|
31 |
-
return {"answer": answer}
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import gradio as gr
|
3 |
+
from rag_system import RAGSystem # تأكد أن الملف اسمه rag_system.py وموجود في نفس المجلد
|
4 |
|
5 |
+
# --- تحميل النظام ---
|
6 |
+
rag = RAGSystem(
|
7 |
+
vector_db_path="vector_db", # تأكد أن قاعدة البيانات مضغوطة ومرفوعة ضمن files
|
8 |
+
model_name="meta-llama/Llama-3-8b-chat-hf",
|
9 |
+
embedding_model_name="sentence-transformers/all-mpnet-base-v2"
|
10 |
+
)
|
11 |
|
12 |
+
rag.load_vectorstore()
|
13 |
+
rag.load_llm()
|
14 |
+
rag.get_prompt_template()
|
15 |
|
16 |
+
# --- دالة الاستجابة ---
|
17 |
+
def ask_question_interface(question):
|
18 |
+
return rag.ask_question(question)
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
# --- واجهة Gradio ---
|
21 |
+
demo = gr.Interface(
|
22 |
+
fn=ask_question_interface,
|
23 |
+
inputs=gr.Textbox(label="Ask a question about the ECC Guide"),
|
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()
|
|
|
|
|
|
|
|
|
|