Update app.py
Browse files
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="
|
| 27 |
_BLOOM_INDEX = build_phrase_index(_backend, BLOOMS_PHRASES)
|
| 28 |
_DOK_INDEX = build_phrase_index(_backend, DOK_PHRASES)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
"
|
| 35 |
-
"
|
| 36 |
-
"
|
| 37 |
-
"
|
| 38 |
-
"
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
list(D["
|
| 45 |
-
list(D["
|
| 46 |
-
list(D["
|
| 47 |
-
list(D["
|
| 48 |
-
list(D["
|
| 49 |
-
)
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 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(
|