Spaces:
Sleeping
Sleeping
segovia commited on
Commit ·
22b7714
1
Parent(s): c0de355
asd
Browse files- app.py +12 -0
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -14,6 +14,11 @@ from document_processing import extract_text, is_image_document, to_data_uri
|
|
| 14 |
from receipt_ai import extract_receipt_json, extract_receipt_json_from_image
|
| 15 |
from receipt_results import build_empty_result
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
RESULT_COLUMNS = [
|
| 19 |
"source_file",
|
|
@@ -30,6 +35,12 @@ RESULT_COLUMNS = [
|
|
| 30 |
]
|
| 31 |
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def parse_uploaded_file(client, model: str, file_path: str) -> dict:
|
| 34 |
path = Path(file_path)
|
| 35 |
if is_image_document(path):
|
|
@@ -59,6 +70,7 @@ def build_csv_download(rows: list[dict]) -> str:
|
|
| 59 |
return temp_file.name
|
| 60 |
|
| 61 |
|
|
|
|
| 62 |
def process_files(files: list[str] | None, existing_rows: list[dict] | None, model: str):
|
| 63 |
from dotenv import load_dotenv
|
| 64 |
from openai import OpenAI
|
|
|
|
| 14 |
from receipt_ai import extract_receipt_json, extract_receipt_json_from_image
|
| 15 |
from receipt_results import build_empty_result
|
| 16 |
|
| 17 |
+
try:
|
| 18 |
+
import spaces # type: ignore[import-not-found]
|
| 19 |
+
except ImportError:
|
| 20 |
+
spaces = None
|
| 21 |
+
|
| 22 |
|
| 23 |
RESULT_COLUMNS = [
|
| 24 |
"source_file",
|
|
|
|
| 35 |
]
|
| 36 |
|
| 37 |
|
| 38 |
+
def gpu_decorator(fn):
|
| 39 |
+
if spaces is None:
|
| 40 |
+
return fn
|
| 41 |
+
return spaces.GPU(fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
def parse_uploaded_file(client, model: str, file_path: str) -> dict:
|
| 45 |
path = Path(file_path)
|
| 46 |
if is_image_document(path):
|
|
|
|
| 70 |
return temp_file.name
|
| 71 |
|
| 72 |
|
| 73 |
+
@gpu_decorator
|
| 74 |
def process_files(files: list[str] | None, existing_rows: list[dict] | None, model: str):
|
| 75 |
from dotenv import load_dotenv
|
| 76 |
from openai import OpenAI
|
requirements.txt
CHANGED
|
@@ -2,4 +2,5 @@ openai>=1.40.0
|
|
| 2 |
pypdf>=4.2.0
|
| 3 |
python-docx>=1.1.2
|
| 4 |
python-dotenv>=1.0.1
|
| 5 |
-
gradio>=4.0.0
|
|
|
|
|
|
| 2 |
pypdf>=4.2.0
|
| 3 |
python-docx>=1.1.2
|
| 4 |
python-dotenv>=1.0.1
|
| 5 |
+
gradio>=4.0.0
|
| 6 |
+
spaces>=0.31.1
|