bhardwaj08sarthak commited on
Commit
e038f18
·
verified ·
1 Parent(s): 54c3df6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -34
app.py CHANGED
@@ -2,6 +2,8 @@
2
  # It expects `level_classifier_tool.py` to be colocated (or installed on PYTHONPATH).
3
  import sys
4
  import os
 
 
5
  from huggingface_hub import login
6
  login(os.getenv("HF_Token"))
7
  import json
@@ -23,43 +25,46 @@ from all_tools import classify_and_score, QuestionRetrieverTool
23
  from phrases import BLOOMS_PHRASES, DOK_PHRASES
24
  import spaces
25
  # Prebuild embeddings once
26
- _backend = HFEmbeddingBackend(model_name="sentence-transformers/all-MiniLM-L6-v2")
27
  _BLOOM_INDEX = build_phrase_index(_backend, BLOOMS_PHRASES)
28
  _DOK_INDEX = build_phrase_index(_backend, DOK_PHRASES)
29
 
30
- D = {
31
- "GSM8k": GSM8k['question'],
32
- "Olympiad": Olympiad_math['question'],
33
- "Olympiad2": Olympiad_math2['question'],
34
- "DeepMind Math": clean_math['question'],
35
- "MMMLU": MMMLU['question'],
36
- "MMMU": MMMU['question'],
37
- "ScienceQA": ScienceQA['question'],
38
- "PubmedQA": PubmedQA['question']
39
- }
40
- all_questions = (
41
- list(D["GSM8k"]) +
42
- list(D["Olympiad"]) +
43
- list(D["MMMLU"]) +
44
- list(D["MMMU"]) +
45
- list(D["DeepMind Math"]) +
46
- list(D["Olympiad2"]) +
47
- list(D["ScienceQA"]) +
48
- list(D["PubmedQA"])
49
- )
50
- texts = all_questions
51
- @spaces.GPU(15)
52
- def build_indexes_on_gpu(model="google/embeddinggemma-300m"):
53
- device = 'cuda'
54
- emb = HuggingFaceEmbeddings(
55
- model_name="model",
56
- model_kwargs={"device": device},
57
- encode_kwargs={"normalize_embeddings": True})
58
- idx = VectorStoreIndex.from_documents([Document(text=t) for t in texts], embed_model=emb)
59
- return idx
60
- device = "cuda"
61
-
62
- index = build_indexes_on_gpu(model="google/embeddinggemma-300m")
 
 
 
63
  # ------------------------ Agent setup with timeout ------------------------
64
  def make_agent(hf_token: str, model_id: str, provider: str, timeout: int, temperature: float, max_tokens: int):
65
  client = InferenceClient(
 
2
  # It expects `level_classifier_tool.py` to be colocated (or installed on PYTHONPATH).
3
  import sys
4
  import os
5
+ from huggingface_hub import hf_hub_download
6
+ import pickle
7
  from huggingface_hub import login
8
  login(os.getenv("HF_Token"))
9
  import json
 
25
  from phrases import BLOOMS_PHRASES, DOK_PHRASES
26
  import spaces
27
  # Prebuild embeddings once
28
+ _backend = HFEmbeddingBackend(model_name="google/embeddinggemma-300m")
29
  _BLOOM_INDEX = build_phrase_index(_backend, BLOOMS_PHRASES)
30
  _DOK_INDEX = build_phrase_index(_backend, DOK_PHRASES)
31
 
32
+ file_path = hf_hub_download("bhardwaj08sarthak/stem_questioin_embeddings", "index.pkl")
33
+ with open(file_path, "rb") as f:
34
+ index = pickle.load(f)
35
+ #D = {
36
+ # "GSM8k": GSM8k['question'],
37
+ # "Olympiad": Olympiad_math['question'],
38
+ # "Olympiad2": Olympiad_math2['question'],
39
+ # "DeepMind Math": clean_math['question'],
40
+ # "MMMLU": MMMLU['question'],
41
+ # "MMMU": MMMU['question'],
42
+ # "ScienceQA": ScienceQA['question'],
43
+ # "PubmedQA": PubmedQA['question']
44
+ #}
45
+ #all_questions = (
46
+ # list(D["GSM8k"]) +
47
+ # list(D["Olympiad"]) +
48
+ # list(D["MMMLU"]) +
49
+ # list(D["MMMU"]) +
50
+ # list(D["DeepMind Math"]) +
51
+ # list(D["Olympiad2"]) +
52
+ # list(D["ScienceQA"]) +
53
+ # list(D["PubmedQA"])
54
+ #)
55
+ #texts = all_questions
56
+ #@spaces.GPU(15)
57
+ #def build_indexes_on_gpu(model="google/embeddinggemma-300m"):
58
+ # device = 'cuda'
59
+ # emb = HuggingFaceEmbeddings(
60
+ # model_name="model",
61
+ # model_kwargs={"device": device},
62
+ # encode_kwargs={"normalize_embeddings": True})
63
+ # idx = VectorStoreIndex.from_documents([Document(text=t) for t in texts], embed_model=emb)
64
+ # return idx
65
+ # device = "cuda"
66
+
67
+ #index = build_indexes_on_gpu(model="google/embeddinggemma-300m")
68
  # ------------------------ Agent setup with timeout ------------------------
69
  def make_agent(hf_token: str, model_id: str, provider: str, timeout: int, temperature: float, max_tokens: int):
70
  client = InferenceClient(