Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -92,13 +92,21 @@ def generate_final_response(response1, response2):
|
|
92 |
def markdown_to_html(content):
|
93 |
return markdown2.markdown(content)
|
94 |
|
95 |
-
def load_pdfs(
|
96 |
global full_pdf_content, vector_store, rag_chain
|
97 |
|
98 |
documents = []
|
99 |
full_pdf_content = ""
|
100 |
|
101 |
# Load selected regulation PDFs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
for regulation in selected_regulations:
|
103 |
if regulation in regulation_pdfs:
|
104 |
pdf_content = extract_pdf(regulation_pdfs[regulation])
|
@@ -121,6 +129,11 @@ def load_pdfs(selected_regulations, additional_pdfs):
|
|
121 |
rag_chain = create_rag_chain(vector_store)
|
122 |
|
123 |
return "PDFs loaded and RAG system updated successfully!"
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
def process_query(user_query):
|
126 |
global rag_chain, full_pdf_content
|
@@ -151,19 +164,14 @@ rag_chain = None
|
|
151 |
# Gradio interface
|
152 |
with gr.Blocks() as iface:
|
153 |
gr.Markdown("# Data Protection Team")
|
154 |
-
gr.Markdown("
|
155 |
|
156 |
with gr.Row():
|
157 |
gdpr_checkbox = gr.Checkbox(label="GDPR (EU)")
|
158 |
ferpa_checkbox = gr.Checkbox(label="FERPA (US)")
|
159 |
coppa_checkbox = gr.Checkbox(label="COPPA (US <13)")
|
160 |
-
|
161 |
-
|
162 |
-
max-height: 100px;
|
163 |
-
overflow-y: auto;
|
164 |
-
}
|
165 |
-
"""
|
166 |
-
gr.Markdown("**Optional: upload additional PDFs if needed (national regulation, school policy)**")
|
167 |
additional_pdfs = gr.File(
|
168 |
file_count="multiple",
|
169 |
label="Upload additional PDFs",
|
@@ -174,11 +182,11 @@ with gr.Blocks() as iface:
|
|
174 |
load_button = gr.Button("Load PDFs")
|
175 |
load_output = gr.Textbox(label="Load Status")
|
176 |
|
177 |
-
gr.Markdown("
|
178 |
query_input = gr.Textbox(label="Your Question", placeholder="Ask your question here...")
|
179 |
query_button = gr.Button("Submit Query")
|
180 |
|
181 |
-
gr.Markdown("
|
182 |
rag_output = gr.Textbox(label="RAG Pipeline (Llama3.1) Response")
|
183 |
gemini_output = gr.Textbox(label="Long Context (Gemini 1.5 Pro) Response")
|
184 |
final_output = gr.HTML(label="Final (GPT-4o) Response")
|
@@ -186,7 +194,9 @@ with gr.Blocks() as iface:
|
|
186 |
load_button.click(
|
187 |
load_pdfs,
|
188 |
inputs=[
|
189 |
-
|
|
|
|
|
190 |
additional_pdfs
|
191 |
],
|
192 |
outputs=load_output
|
|
|
92 |
def markdown_to_html(content):
|
93 |
return markdown2.markdown(content)
|
94 |
|
95 |
+
def load_pdfs(gdpr, ferpa, coppa, additional_pdfs):
|
96 |
global full_pdf_content, vector_store, rag_chain
|
97 |
|
98 |
documents = []
|
99 |
full_pdf_content = ""
|
100 |
|
101 |
# Load selected regulation PDFs
|
102 |
+
selected_regulations = []
|
103 |
+
if gdpr:
|
104 |
+
selected_regulations.append("GDPR")
|
105 |
+
if ferpa:
|
106 |
+
selected_regulations.append("FERPA")
|
107 |
+
if coppa:
|
108 |
+
selected_regulations.append("COPPA")
|
109 |
+
|
110 |
for regulation in selected_regulations:
|
111 |
if regulation in regulation_pdfs:
|
112 |
pdf_content = extract_pdf(regulation_pdfs[regulation])
|
|
|
129 |
rag_chain = create_rag_chain(vector_store)
|
130 |
|
131 |
return "PDFs loaded and RAG system updated successfully!"
|
132 |
+
|
133 |
+
vector_store = generate_embeddings(documents)
|
134 |
+
rag_chain = create_rag_chain(vector_store)
|
135 |
+
|
136 |
+
return "PDFs loaded and RAG system updated successfully!"
|
137 |
|
138 |
def process_query(user_query):
|
139 |
global rag_chain, full_pdf_content
|
|
|
164 |
# Gradio interface
|
165 |
with gr.Blocks() as iface:
|
166 |
gr.Markdown("# Data Protection Team")
|
167 |
+
gr.Markdown("Get responses combining advanced RAG, Long Context, and SOTA models to data protection related questions.")
|
168 |
|
169 |
with gr.Row():
|
170 |
gdpr_checkbox = gr.Checkbox(label="GDPR (EU)")
|
171 |
ferpa_checkbox = gr.Checkbox(label="FERPA (US)")
|
172 |
coppa_checkbox = gr.Checkbox(label="COPPA (US <13)")
|
173 |
+
|
174 |
+
gr.Markdown("Optional: upload additional PDFs if needed (national regulation, school policy)")
|
|
|
|
|
|
|
|
|
|
|
175 |
additional_pdfs = gr.File(
|
176 |
file_count="multiple",
|
177 |
label="Upload additional PDFs",
|
|
|
182 |
load_button = gr.Button("Load PDFs")
|
183 |
load_output = gr.Textbox(label="Load Status")
|
184 |
|
185 |
+
gr.Markdown("Ask your data protection related question")
|
186 |
query_input = gr.Textbox(label="Your Question", placeholder="Ask your question here...")
|
187 |
query_button = gr.Button("Submit Query")
|
188 |
|
189 |
+
gr.Markdown("Results")
|
190 |
rag_output = gr.Textbox(label="RAG Pipeline (Llama3.1) Response")
|
191 |
gemini_output = gr.Textbox(label="Long Context (Gemini 1.5 Pro) Response")
|
192 |
final_output = gr.HTML(label="Final (GPT-4o) Response")
|
|
|
194 |
load_button.click(
|
195 |
load_pdfs,
|
196 |
inputs=[
|
197 |
+
gdpr_checkbox,
|
198 |
+
ferpa_checkbox,
|
199 |
+
coppa_checkbox,
|
200 |
additional_pdfs
|
201 |
],
|
202 |
outputs=load_output
|