bek-cs-request

#3
by bek-cs - opened
app.py CHANGED
@@ -17,7 +17,7 @@ with open("vector_db/metadata.pkl", "rb") as f:
17
  ST = SentenceTransformer("BAAI/bge-large-en-v1.5")
18
  github_base_url = "https://github.com/arsiba/EDPB-AI/blob/main/"
19
 
20
- model_id = "HuggingFaceH4/zephyr-7b-beta"
21
  bnb = BitsAndBytesConfig(
22
  load_in_4bit=True,
23
  bnb_4bit_use_double_quant=True,
@@ -40,7 +40,6 @@ SYS = (
40
  "Answer this Question:"
41
  )
42
 
43
- @spaces.GPU()
44
  def retrieve(q, k=3):
45
  emb = ST.encode(q)
46
  D, I = index.search(np.array([emb], dtype="float32"), k)
@@ -78,8 +77,8 @@ def build_markdown_chunks(docs):
78
  return "\n\n".join(lines)
79
 
80
  @spaces.GPU()
81
- def qa_fn(faiss_search, question, top_k, temperature, max_tokens):
82
- docs, file_sources = retrieve(faiss_search, top_k)
83
  file_links = build_markdown_links(file_sources)
84
  markdown_chunks = build_markdown_chunks(docs)
85
  prompt = make_prompt(question, docs)[:8000]
@@ -102,6 +101,8 @@ def qa_fn(faiss_search, question, top_k, temperature, max_tokens):
102
  output = output.split("Output:", 1)[1].strip()
103
  return "\n# Generated Answer\n", output,"\n# Used Documents\n", file_links, "\n# Used Context\n", markdown_chunks
104
 
 
 
105
  heading_answer = gr.Markdown(label="Answer Heading")
106
  outputs_answer = gr.Textbox(label="Answer")
107
  heading_links = gr.Markdown(label="Links Heading")
@@ -112,11 +113,10 @@ outputs_chunks = gr.Markdown(label="Used Chunks")
112
  demo = gr.Interface(
113
  fn=qa_fn,
114
  inputs=[
115
- gr.Textbox(lines=4, label="What Documents are you looking for?", placeholder="Please change to get propper results:\nDocuments covering the EDPB’s stance on automated decision-making, particularly profiling, under the GDPR. Guidelines on how organizations should inform data subjects about automated decisions and the rights of individuals to object to such decisions."),
116
- gr.Textbox(lines=1, label="What is your question?", placeholder="Please change to get propper results:\nWhat does the EDPB recommend regarding automated decision-making and profiling under the GDPR, and what rights do individuals have in relation to such decisions?"),
117
  ],
118
  additional_inputs=[
119
- gr.Slider(1, 10, value=7, step=1, label="Top-K Documents"),
120
  gr.Slider(0.1, 1.0, value=0.6, step=0.05, label="Temperature"),
121
  gr.Slider(64, 1024, value=512, step=64, label="Max Answer Length")
122
  ],
@@ -136,4 +136,4 @@ demo = gr.Interface(
136
  )
137
 
138
  if __name__ == "__main__":
139
- demo.launch(share=True)
 
17
  ST = SentenceTransformer("BAAI/bge-large-en-v1.5")
18
  github_base_url = "https://github.com/arsiba/EDPB-AI/blob/main/"
19
 
20
+ model_id = "nvidia/Llama-3.1-Nemotron-Nano-8B-v1"
21
  bnb = BitsAndBytesConfig(
22
  load_in_4bit=True,
23
  bnb_4bit_use_double_quant=True,
 
40
  "Answer this Question:"
41
  )
42
 
 
43
  def retrieve(q, k=3):
44
  emb = ST.encode(q)
45
  D, I = index.search(np.array([emb], dtype="float32"), k)
 
77
  return "\n\n".join(lines)
78
 
79
  @spaces.GPU()
80
+ def qa_fn(question, top_k, temperature, max_tokens):
81
+ docs, file_sources = retrieve(question, top_k)
82
  file_links = build_markdown_links(file_sources)
83
  markdown_chunks = build_markdown_chunks(docs)
84
  prompt = make_prompt(question, docs)[:8000]
 
101
  output = output.split("Output:", 1)[1].strip()
102
  return "\n# Generated Answer\n", output,"\n# Used Documents\n", file_links, "\n# Used Context\n", markdown_chunks
103
 
104
+ # TODO first model to make prompt more efficient
105
+
106
  heading_answer = gr.Markdown(label="Answer Heading")
107
  outputs_answer = gr.Textbox(label="Answer")
108
  heading_links = gr.Markdown(label="Links Heading")
 
113
  demo = gr.Interface(
114
  fn=qa_fn,
115
  inputs=[
116
+ gr.Textbox(lines=2, label="Your Question"),
 
117
  ],
118
  additional_inputs=[
119
+ gr.Slider(1, 7, value=4, step=1, label="Top-K Documents"),
120
  gr.Slider(0.1, 1.0, value=0.6, step=0.05, label="Temperature"),
121
  gr.Slider(64, 1024, value=512, step=64, label="Max Answer Length")
122
  ],
 
136
  )
137
 
138
  if __name__ == "__main__":
139
+ demo.launch(share=True)
vector_db/chunks.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:67eb6121dfe634c62ce4a49949bf8294f7821eec03b59c3c8db307ff3f62b421
3
- size 37935387
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5cd4fbdc599d57400b805d94897976dcd4c86584623dcd48a1eab3767cfb4e45
3
+ size 35695836
vector_db/index.faiss CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:7a9badb561168f11e80ec649fcf7d7ae7196a4478c00b82116c3552ad6090b5b
3
- size 216687186
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:05a2605f128bb07d1c9c780e2dc23ddb4ed961eea7026da2a91d09f325b5edbd
3
+ size 321729066
vector_db/metadata.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d9620db4956d8afc2ac8cef2447de50b17cc2feb62eb4aa2918befd6d4ac29be
3
- size 1841263
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6b859781f0a2bbefca6659c254d9fccbbca6e2b3d1b1c5790c83cd9ced3082bc
3
+ size 2701479