Spaces:
Running
Running
fixed issue in backend
Browse files- app.py +34 -26
- backend.py +3 -2
app.py
CHANGED
@@ -152,8 +152,6 @@ if 'secrets' in st.secrets:
|
|
152 |
|
153 |
hf_token = st.secrets['secrets']['LLAMA2_ENDPOINT_HF_TOKEN_chris']
|
154 |
hf_endpoint = st.secrets['secrets']['LLAMA2_ENDPOINT_UPLIMIT']
|
155 |
-
model_token_id = st.secrets['secrets']['MODAL_TOKEN_ID']
|
156 |
-
modal_token_secret = st.secrets['secrets']['MODAL_TOKEN_SECRET']
|
157 |
|
158 |
else :
|
159 |
# st.write("Loading secrets for Huggingface")
|
@@ -164,8 +162,6 @@ else :
|
|
164 |
|
165 |
hf_token = st.secrets['LLAMA2_ENDPOINT_HF_TOKEN_chris']
|
166 |
hf_endpoint = st.secrets['LLAMA2_ENDPOINT_UPLIMIT']
|
167 |
-
model_token_id = st.secrets['MODAL_TOKEN_ID']
|
168 |
-
modal_token_secret = st.secrets['MODAL_TOKEN_SECRET']
|
169 |
|
170 |
# else:
|
171 |
# # if we want to use env file
|
@@ -183,7 +179,8 @@ model_default = 'models/finetuned-all-mpnet-base-v2-300' if we_are_not_online \
|
|
183 |
|
184 |
available_models = ['sentence-transformers/all-mpnet-base-v2',
|
185 |
'sentence-transformers/all-MiniLM-L6-v2',
|
186 |
-
'models/finetuned-all-mpnet-base-v2-300'
|
|
|
187 |
|
188 |
#%%
|
189 |
models_urls = {'models/finetuned-all-mpnet-base-v2-300': "https://drive.google.com/drive/folders/1asJ37-AUv5nytLtH6hp6_bVV3_cZOXfj"}
|
@@ -307,8 +304,10 @@ def main():
|
|
307 |
st.text("Running OFFLINE")
|
308 |
st.write("----------")
|
309 |
|
310 |
-
|
311 |
-
|
|
|
|
|
312 |
|
313 |
hybrid_filter = st.toggle('Filter Guest', True) # i.e. look only at guests' data
|
314 |
|
@@ -322,7 +321,7 @@ def main():
|
|
322 |
|
323 |
rag_it = st.toggle('RAG it', True)
|
324 |
if rag_it:
|
325 |
-
st.
|
326 |
llm_temperature = st.slider(label='LLM T˚', min_value=0.0, max_value=2.0, value=0.01, step=0.10 )
|
327 |
|
328 |
model_name_or_path = st.selectbox(label='Model Name:', options=available_models,
|
@@ -336,29 +335,35 @@ def main():
|
|
336 |
from finetune_backend import finetune
|
337 |
if 'finetuned' in model_name_or_path:
|
338 |
st.write("Model already finetuned")
|
339 |
-
elif
|
340 |
-
st.write("
|
341 |
else:
|
342 |
-
try:
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
|
|
356 |
else:
|
357 |
st.write("Finetuning not available on Streamlit online because of space limitations")
|
358 |
|
359 |
model_name_or_path = check_model(model_name_or_path)
|
360 |
-
|
361 |
-
|
|
|
|
|
|
|
|
|
|
|
362 |
start_class = 'Impact_theory_all_mpnet_base_v2_finetuned'
|
363 |
|
364 |
class_name = st.selectbox(
|
@@ -406,6 +411,9 @@ def main():
|
|
406 |
|
407 |
st.write("\u21D0 Open the sidebar to change Search settings \n ") # https://home.unicode.org also 21E0, 21B0 B2 D0
|
408 |
|
|
|
|
|
|
|
409 |
col1, _ = st.columns([3,7])
|
410 |
with col1:
|
411 |
guest = st.selectbox('Select A Guest',
|
|
|
152 |
|
153 |
hf_token = st.secrets['secrets']['LLAMA2_ENDPOINT_HF_TOKEN_chris']
|
154 |
hf_endpoint = st.secrets['secrets']['LLAMA2_ENDPOINT_UPLIMIT']
|
|
|
|
|
155 |
|
156 |
else :
|
157 |
# st.write("Loading secrets for Huggingface")
|
|
|
162 |
|
163 |
hf_token = st.secrets['LLAMA2_ENDPOINT_HF_TOKEN_chris']
|
164 |
hf_endpoint = st.secrets['LLAMA2_ENDPOINT_UPLIMIT']
|
|
|
|
|
165 |
|
166 |
# else:
|
167 |
# # if we want to use env file
|
|
|
179 |
|
180 |
available_models = ['sentence-transformers/all-mpnet-base-v2',
|
181 |
'sentence-transformers/all-MiniLM-L6-v2',
|
182 |
+
'models/finetuned-all-mpnet-base-v2-300',
|
183 |
+
'sentence-transformers/all-MiniLM-L12-v2']
|
184 |
|
185 |
#%%
|
186 |
models_urls = {'models/finetuned-all-mpnet-base-v2-300': "https://drive.google.com/drive/folders/1asJ37-AUv5nytLtH6hp6_bVV3_cZOXfj"}
|
|
|
304 |
st.text("Running OFFLINE")
|
305 |
st.write("----------")
|
306 |
|
307 |
+
hubrid_search = st.toggle('Hybrid Search', True)
|
308 |
+
if hubrid_search:
|
309 |
+
alpha_input = st.slider(label='Alpha',min_value=0.00, max_value=1.00, value=0.40, step=0.05)
|
310 |
+
retrieval_limit = st.slider(label='Hybrid Search Results', min_value=10, max_value=300, value=10, step=10)
|
311 |
|
312 |
hybrid_filter = st.toggle('Filter Guest', True) # i.e. look only at guests' data
|
313 |
|
|
|
321 |
|
322 |
rag_it = st.toggle('RAG it', True)
|
323 |
if rag_it:
|
324 |
+
st.write(f"Using LLM '{model_nameGPT}'")
|
325 |
llm_temperature = st.slider(label='LLM T˚', min_value=0.0, max_value=2.0, value=0.01, step=0.10 )
|
326 |
|
327 |
model_name_or_path = st.selectbox(label='Model Name:', options=available_models,
|
|
|
335 |
from finetune_backend import finetune
|
336 |
if 'finetuned' in model_name_or_path:
|
337 |
st.write("Model already finetuned")
|
338 |
+
elif "models/" in model_name_or_path:
|
339 |
+
st.write("sentence-transformers models only!")
|
340 |
else:
|
341 |
+
# try:
|
342 |
+
if 'finetuned' in model_name_or_path:
|
343 |
+
st.write("Model already finetuned")
|
344 |
+
else:
|
345 |
+
model_path = finetune(model_name_or_path, savemodel=True, outpath='models')
|
346 |
+
st.write(f"model_path returned = {model_path}")
|
347 |
+
if model_path is not None:
|
348 |
+
if model_name_or_path.split('/')[-1] not in model_path:
|
349 |
+
st.write(model_path) # a warning from finetuning in this case
|
350 |
+
elif model_path not in available_models:
|
351 |
+
# finetuning generated a model, let's add it
|
352 |
+
available_models.append(model_path)
|
353 |
+
st.write("Model saved!")
|
354 |
+
# except Exception:
|
355 |
+
# st.write("Model not found on HF or error")
|
356 |
else:
|
357 |
st.write("Finetuning not available on Streamlit online because of space limitations")
|
358 |
|
359 |
model_name_or_path = check_model(model_name_or_path)
|
360 |
+
try:
|
361 |
+
client, available_classes = get_weaviate_client(Wapi_key, url, model_name_or_path, openai_api_key)
|
362 |
+
except Exception as e:
|
363 |
+
# Weaviate doesn't know this model, maybe we're just finetuning a model
|
364 |
+
st.sidebar.write(f"Model unknown to Weaviate")
|
365 |
+
st.stop()
|
366 |
+
|
367 |
start_class = 'Impact_theory_all_mpnet_base_v2_finetuned'
|
368 |
|
369 |
class_name = st.selectbox(
|
|
|
411 |
|
412 |
st.write("\u21D0 Open the sidebar to change Search settings \n ") # https://home.unicode.org also 21E0, 21B0 B2 D0
|
413 |
|
414 |
+
if not hubrid_search:
|
415 |
+
st.stop()
|
416 |
+
|
417 |
col1, _ = st.columns([3,7])
|
418 |
with col1:
|
419 |
guest = st.selectbox('Select A Guest',
|
backend.py
CHANGED
@@ -100,7 +100,8 @@ def encode_content_splits(content_splits,
|
|
100 |
)
|
101 |
def finetune(training_path='./data/training_data_300.json',
|
102 |
valid_path='./data/validation_data_100.json',
|
103 |
-
model_id=None
|
|
|
104 |
|
105 |
import os
|
106 |
print("Data:", os.listdir('/root/data'))
|
@@ -170,7 +171,7 @@ def finetune(training_path='./data/training_data_300.json',
|
|
170 |
zippedio = bytes_buffer
|
171 |
|
172 |
return zippedio
|
173 |
-
except:
|
174 |
return "Finetuning failed"
|
175 |
|
176 |
|
|
|
100 |
)
|
101 |
def finetune(training_path='./data/training_data_300.json',
|
102 |
valid_path='./data/validation_data_100.json',
|
103 |
+
model_id=None,
|
104 |
+
ignore_existing=False):
|
105 |
|
106 |
import os
|
107 |
print("Data:", os.listdir('/root/data'))
|
|
|
171 |
zippedio = bytes_buffer
|
172 |
|
173 |
return zippedio
|
174 |
+
except Exception:
|
175 |
return "Finetuning failed"
|
176 |
|
177 |
|