Spaces:
Running
Running
Commit
·
5661288
1
Parent(s):
aedd7d9
Major update. Support for 15 LLMs, World Flora Online taxonomy validation, geolocation, 2 OCR methods, significant UI changes, stability improvements, consistent JSON parsing
Browse files- app.py +20 -8
- vouchervision/API_validation.py +3 -3
app.py
CHANGED
|
@@ -1588,7 +1588,11 @@ def content_header():
|
|
| 1588 |
|
| 1589 |
path_custom_prompts = os.path.join(st.session_state.dir_home,'custom_prompts',st.session_state.config['leafmachine']['project']['prompt_version'])
|
| 1590 |
# Call the machine function.
|
| 1591 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1592 |
st.session_state.dir_home,
|
| 1593 |
path_custom_prompts,
|
| 1594 |
None,
|
|
@@ -1597,24 +1601,32 @@ def content_header():
|
|
| 1597 |
path_api_cost=os.path.join(st.session_state.dir_home,'api_cost','api_cost.yaml'),
|
| 1598 |
is_hf = st.session_state['is_hf'],
|
| 1599 |
is_real_run=True)
|
| 1600 |
-
|
|
|
|
|
|
|
|
|
|
| 1601 |
if n_failed_OCR > 0:
|
| 1602 |
-
|
|
|
|
| 1603 |
|
| 1604 |
if n_failed_LLM_calls > 0:
|
| 1605 |
-
|
| 1606 |
-
|
|
|
|
| 1607 |
|
| 1608 |
if total_cost:
|
| 1609 |
-
|
|
|
|
| 1610 |
else:
|
| 1611 |
-
|
|
|
|
| 1612 |
st.balloons()
|
| 1613 |
if st.session_state['zip_filepath']:
|
| 1614 |
create_download_button(st.session_state['zip_filepath'], col_run_1)
|
| 1615 |
else:
|
| 1616 |
st.button("Start Processing", type='primary', disabled=True)
|
| 1617 |
-
|
|
|
|
| 1618 |
|
| 1619 |
if st.session_state['formatted_json']:
|
| 1620 |
if st.session_state['hold_output']:
|
|
|
|
| 1588 |
|
| 1589 |
path_custom_prompts = os.path.join(st.session_state.dir_home,'custom_prompts',st.session_state.config['leafmachine']['project']['prompt_version'])
|
| 1590 |
# Call the machine function.
|
| 1591 |
+
total_cost = 0.00
|
| 1592 |
+
n_failed_OCR = 0
|
| 1593 |
+
n_failed_LLM_calls = 0
|
| 1594 |
+
try:
|
| 1595 |
+
st.session_state['formatted_json'], st.session_state['formatted_json_WFO'], st.session_state['formatted_json_GEO'], total_cost, n_failed_OCR, n_failed_LLM_calls, st.session_state['zip_filepath'] = voucher_vision(None,
|
| 1596 |
st.session_state.dir_home,
|
| 1597 |
path_custom_prompts,
|
| 1598 |
None,
|
|
|
|
| 1601 |
path_api_cost=os.path.join(st.session_state.dir_home,'api_cost','api_cost.yaml'),
|
| 1602 |
is_hf = st.session_state['is_hf'],
|
| 1603 |
is_real_run=True)
|
| 1604 |
+
except Exception as e:
|
| 1605 |
+
with col_run_4:
|
| 1606 |
+
st.error(f"Transcription failed. Error: {e}")
|
| 1607 |
+
|
| 1608 |
if n_failed_OCR > 0:
|
| 1609 |
+
with col_run_4:
|
| 1610 |
+
st.error(f"Caution:heavy_exclamation_mark: :loudspeaker: {n_failed_LLM_calls} images had a no extractable OCR text :eyes:")
|
| 1611 |
|
| 1612 |
if n_failed_LLM_calls > 0:
|
| 1613 |
+
with col_run_4:
|
| 1614 |
+
st.error(f"Caution:heavy_exclamation_mark: :loudspeaker: {n_failed_LLM_calls} images had a failed LLM API call :eyes:")
|
| 1615 |
+
st.error(f"Make sure that you have access to the chosen LLM API model. Sometimes certain OpenAI accounts do not have access to all models, for example")
|
| 1616 |
|
| 1617 |
if total_cost:
|
| 1618 |
+
with col_run_4:
|
| 1619 |
+
st.success(f":money_with_wings: This run cost :heavy_dollar_sign:{total_cost:.4f}")
|
| 1620 |
else:
|
| 1621 |
+
with col_run_4:
|
| 1622 |
+
st.info(f":money_with_wings: This run cost :heavy_dollar_sign:{total_cost:.4f}")
|
| 1623 |
st.balloons()
|
| 1624 |
if st.session_state['zip_filepath']:
|
| 1625 |
create_download_button(st.session_state['zip_filepath'], col_run_1)
|
| 1626 |
else:
|
| 1627 |
st.button("Start Processing", type='primary', disabled=True)
|
| 1628 |
+
with col_run_4:
|
| 1629 |
+
st.error(":heavy_exclamation_mark: Required API keys not set. Please visit the 'API Keys' tab and set the Google Vision OCR API key and at least one LLM key.")
|
| 1630 |
|
| 1631 |
if st.session_state['formatted_json']:
|
| 1632 |
if st.session_state['hold_output']:
|
vouchervision/API_validation.py
CHANGED
|
@@ -185,10 +185,9 @@ class APIvalidation:
|
|
| 185 |
def check_google_vertex_genai_api_key(self):
|
| 186 |
results = {"palm2": False, "gemini": False}
|
| 187 |
if self.cfg_private:
|
| 188 |
-
try:
|
| 189 |
# Assuming genai and vertexai are clients for Google services
|
| 190 |
# os.environ["GOOGLE_API_KEY"] = self.cfg_private['google_palm']['google_palm_api']
|
| 191 |
-
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = self.get_google_credentials()
|
| 192 |
# genai.configure(api_key=self.cfg_private['google_palm']['google_palm_api'])
|
| 193 |
vertexai.init(project= self.cfg_private['google_palm']['project_id'], location=self.cfg_private['google_palm']['location'])
|
| 194 |
|
|
@@ -218,10 +217,11 @@ class APIvalidation:
|
|
| 218 |
except Exception as e: # Replace with a more specific exception if possible
|
| 219 |
return results
|
| 220 |
else:
|
|
|
|
| 221 |
try:
|
| 222 |
# Assuming genai and vertexai are clients for Google services
|
| 223 |
# os.environ["GOOGLE_API_KEY"] = os.getenv('PALM_API_KEY')
|
| 224 |
-
|
| 225 |
vertexai.init(project= os.getenv('GOOGLE_PROJECT_ID'), location=os.getenv('GOOGLE_LOCATION'))
|
| 226 |
|
| 227 |
try:
|
|
|
|
| 185 |
def check_google_vertex_genai_api_key(self):
|
| 186 |
results = {"palm2": False, "gemini": False}
|
| 187 |
if self.cfg_private:
|
| 188 |
+
try: # Local
|
| 189 |
# Assuming genai and vertexai are clients for Google services
|
| 190 |
# os.environ["GOOGLE_API_KEY"] = self.cfg_private['google_palm']['google_palm_api']
|
|
|
|
| 191 |
# genai.configure(api_key=self.cfg_private['google_palm']['google_palm_api'])
|
| 192 |
vertexai.init(project= self.cfg_private['google_palm']['project_id'], location=self.cfg_private['google_palm']['location'])
|
| 193 |
|
|
|
|
| 217 |
except Exception as e: # Replace with a more specific exception if possible
|
| 218 |
return results
|
| 219 |
else:
|
| 220 |
+
### is hugging face
|
| 221 |
try:
|
| 222 |
# Assuming genai and vertexai are clients for Google services
|
| 223 |
# os.environ["GOOGLE_API_KEY"] = os.getenv('PALM_API_KEY')
|
| 224 |
+
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = self.get_google_credentials()
|
| 225 |
vertexai.init(project= os.getenv('GOOGLE_PROJECT_ID'), location=os.getenv('GOOGLE_LOCATION'))
|
| 226 |
|
| 227 |
try:
|