chibuzordev commited on
Commit
58feab0
·
verified ·
1 Parent(s): 078acda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -41
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
- def gradio_wrapper(query, method, k):
25
- stats_text, auc, fig, pert_q, pert_r, adv_r = adv_pipeline.evaluate_adversarial_robustness(
26
- query=query,
27
- method=method,
28
- k=k
29
- )
30
 
31
- return (
32
- stats_text,
33
- f"{auc}",
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=gradio_wrapper,
43
  inputs=[
44
- gr.Textbox(label="Enter a Question"),
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
- gr.Textbox(label="📊 Summary Statistics"),
50
- gr.Textbox(label="🔺 PSC-AUC Score"),
51
- gr.Plot(label="📈 PSC Curve"),
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()