Spaces:
Sleeping
Sleeping
Download llm_api/native_api.py from creativeforce/attribution: direct link, hf CLI and curl.
- Browser
- Download file 992 Bytes
-
https://huggingface.co/spaces/creativeforce/attribution/resolve/main/llm_api/native_api.py
- Command line
-
hf download hf://spaces/creativeforce/attribution/llm_api/native_api.py
-
curl -L -o native_api.py https://huggingface.co/spaces/creativeforce/attribution/resolve/main/llm_api/native_api.py
992 Bytes
| import base64 | |
| from dotenv import load_dotenv | |
| from . import anthropic_api as anthropic_extractor | |
| from . import openai_api as openai_info_extractor | |
| def encode_image(image_path): | |
| with open(image_path, "rb") as image_file: | |
| return base64.b64encode(image_file.read()).decode("utf-8") | |
| def extract_info(image_paths, provider, schema, known_data=None): | |
| if provider == "anthropic": | |
| extractor = anthropic_extractor | |
| elif provider == "openai": | |
| extractor = openai_info_extractor | |
| else: | |
| raise ValueError("Invalid provider") | |
| return extractor.extract_info(image_paths, schema, known_data=known_data) | |
| def follow_structure(json_info, provider, schema, known_data=None): | |
| if provider == "anthropic": | |
| extractor = anthropic_extractor | |
| elif provider == "openai": | |
| extractor = openai_info_extractor | |
| else: | |
| raise ValueError("Invalid provider") | |
| return extractor.follow_structure(json_info, schema, known_data=known_data) | |