Update app.py
Browse files
app.py
CHANGED
|
@@ -25,40 +25,7 @@ from phrases import BLOOMS_PHRASES, DOK_PHRASES
|
|
| 25 |
_backend = HFEmbeddingBackend(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 26 |
_BLOOM_INDEX = build_phrase_index(_backend, BLOOMS_PHRASES)
|
| 27 |
_DOK_INDEX = build_phrase_index(_backend, DOK_PHRASES)
|
| 28 |
-
D = {
|
| 29 |
-
"GSM8k": GSM8k['question'],
|
| 30 |
-
"Olympiad": Olympiad_math['question'],
|
| 31 |
-
"Olympiad2": Olympiad_math2['question'],
|
| 32 |
-
"DeepMind Math": clean_math['question'],
|
| 33 |
-
"MMMLU": MMMLU['question'],
|
| 34 |
-
"MMMU": MMMU['question'],
|
| 35 |
-
"ScienceQA": ScienceQA['question'],
|
| 36 |
-
"PubmedQA": PubmedQA['question']
|
| 37 |
-
}
|
| 38 |
-
all_questions = (
|
| 39 |
-
list(D["GSM8k"]) +
|
| 40 |
-
list(D["Olympiad"]) +
|
| 41 |
-
list(D["MMMLU"]) +
|
| 42 |
-
list(D["MMMU"]) +
|
| 43 |
-
list(D["DeepMind Math"]) +
|
| 44 |
-
list(D["Olympiad2"]) +
|
| 45 |
-
list(D["ScienceQA"]) +
|
| 46 |
-
list(D["PubmedQA"])
|
| 47 |
-
)
|
| 48 |
|
| 49 |
-
emb = HuggingFaceEmbeddings(
|
| 50 |
-
model_name="google/embeddinggemma-300m",
|
| 51 |
-
encode_kwargs={"normalize_embeddings": True},
|
| 52 |
-
)
|
| 53 |
-
texts = all_questions
|
| 54 |
-
index = VectorStoreIndex.from_documents([Document(text=t) for t in texts], embed_model=emb)
|
| 55 |
-
|
| 56 |
-
# ------------------------ Scoring TOOL -----------------------------------
|
| 57 |
-
|
| 58 |
-
emb = HuggingFaceEmbeddings(
|
| 59 |
-
model_name="google/embeddinggemma-300m",
|
| 60 |
-
encode_kwargs={"normalize_embeddings": True},
|
| 61 |
-
)
|
| 62 |
D = {
|
| 63 |
"GSM8k": GSM8k['question'],
|
| 64 |
"Olympiad": Olympiad_math['question'],
|
|
@@ -79,12 +46,17 @@ all_questions = (
|
|
| 79 |
list(D["ScienceQA"]) +
|
| 80 |
list(D["PubmedQA"])
|
| 81 |
)
|
| 82 |
-
texts = all_questions
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
# ------------------------ Agent setup with timeout ------------------------
|
| 89 |
def make_agent(hf_token: str, model_id: str, provider: str, timeout: int, temperature: float, max_tokens: int):
|
| 90 |
client = InferenceClient(
|
|
|
|
| 25 |
_backend = HFEmbeddingBackend(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 26 |
_BLOOM_INDEX = build_phrase_index(_backend, BLOOMS_PHRASES)
|
| 27 |
_DOK_INDEX = build_phrase_index(_backend, DOK_PHRASES)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
D = {
|
| 30 |
"GSM8k": GSM8k['question'],
|
| 31 |
"Olympiad": Olympiad_math['question'],
|
|
|
|
| 46 |
list(D["ScienceQA"]) +
|
| 47 |
list(D["PubmedQA"])
|
| 48 |
)
|
| 49 |
+
texts = all_questions.
|
| 50 |
+
@spaces(15)
|
| 51 |
+
def build_indexes_on_gpu(model="google/embeddinggemma-300m"):
|
| 52 |
+
device = 'cuda'
|
| 53 |
+
emb = HuggingFaceEmbeddings(
|
| 54 |
+
model_name="model",
|
| 55 |
+
model_kwargs={"device": device},
|
| 56 |
+
encode_kwargs={"normalize_embeddings": True},
|
| 57 |
+
index = VectorStoreIndex.from_documents([Document(text=t) for t in texts], embed_model=emb)
|
| 58 |
+
return index
|
| 59 |
+
index = build_indexes_on_gpu(model="google/embeddinggemma-300m")
|
| 60 |
# ------------------------ Agent setup with timeout ------------------------
|
| 61 |
def make_agent(hf_token: str, model_id: str, provider: str, timeout: int, temperature: float, max_tokens: int):
|
| 62 |
client = InferenceClient(
|