Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,52 +10,26 @@ import gradio as gr
|
|
10 |
|
11 |
from rag_pipeline import RAGPipeline
|
12 |
|
13 |
-
from adversarial_framework import *
|
14 |
-
|
15 |
-
# Example Usage:
|
16 |
-
rag = RAGPipeline()
|
17 |
-
#print(rag.generate_answer("Who is the president of NACOS?"))
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
adv_pipeline = AdversarialAttackPipeline(answer_generator=rag.generate_answer)
|
22 |
|
23 |
# Gradio function
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
fig,
|
35 |
-
f"🟠 Perturbed Query:\n\n{pert_q}",
|
36 |
-
f"🟢 Perturbed Response:\n\n{pert_r}",
|
37 |
-
f"🔴 Directly Perturbed Response of Normal Output:\n\n{adv_r}"
|
38 |
-
)
|
39 |
|
40 |
-
# Build Interface
|
41 |
gr.Interface(
|
42 |
-
fn=
|
43 |
inputs=[
|
44 |
-
gr.Textbox(label="Enter
|
45 |
-
gr.Dropdown(choices=["synonym", "delete", "contextual"], label="Perturbation Method"),
|
46 |
gr.Slider(1, 5, step=1, value=3, label="Top-K Retrieved Chunks")
|
47 |
],
|
48 |
-
outputs=
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
gr.Textbox(label="🟠 Perturbed Query Example"),
|
53 |
-
gr.Textbox(label="🟢 Perturbed Response Example"),
|
54 |
-
gr.Textbox(label="🔴 Directly Perturbed Normal Response Example")
|
55 |
-
],
|
56 |
-
title="Adversarial Testing on RAGiant System",
|
57 |
-
description="Evaluate robustness against textual attacks and visualize degradation with ARI & PSC-AUC."
|
58 |
-
).launch()
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
10 |
|
11 |
from rag_pipeline import RAGPipeline
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Gradio function
|
15 |
+
# ==== Instantiate RAG ====
|
16 |
+
rag = RAGPipeline(
|
17 |
+
embedder_model="infly/inf-retriever-v1-1.5b",
|
18 |
+
reranker_model="cross-encoder/ms-marco-MiniLM-L-6-v2",
|
19 |
+
generator_model="google/flan-t5-base"
|
20 |
+
)
|
21 |
|
22 |
+
# ==== Gradio App ====
|
23 |
+
def answer_question(query, top_k):
|
24 |
+
return rag.generate_answer(query, top_k)
|
|
|
|
|
|
|
|
|
|
|
25 |
|
|
|
26 |
gr.Interface(
|
27 |
+
fn=answer_question,
|
28 |
inputs=[
|
29 |
+
gr.Textbox(label="Enter your question"),
|
|
|
30 |
gr.Slider(1, 5, step=1, value=3, label="Top-K Retrieved Chunks")
|
31 |
],
|
32 |
+
outputs=gr.Textbox(label="📘 Generated Answer"),
|
33 |
+
title="RAG-based Question Answering",
|
34 |
+
description="A lightweight RAG system using FAISS + TF-IDF + FLAN-T5. Ask a question, get an answer."
|
35 |
+
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|