Spaces:
Sleeping
Sleeping
Update src/pages/categorized/page6.py
Browse files
src/pages/categorized/page6.py
CHANGED
|
@@ -4,7 +4,7 @@ import json
|
|
| 4 |
import tempfile
|
| 5 |
import zipfile
|
| 6 |
from io import BytesIO
|
| 7 |
-
import fitz
|
| 8 |
import cv2
|
| 9 |
import numpy as np
|
| 10 |
|
|
@@ -15,7 +15,11 @@ import base64
|
|
| 15 |
from typing import Dict, Any, Optional
|
| 16 |
from collections import defaultdict
|
| 17 |
|
| 18 |
-
API_KEY = "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
API_URL = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-09-2025:generateContent?key={API_KEY}"
|
| 20 |
|
| 21 |
SCHEMA = {
|
|
@@ -88,7 +92,11 @@ def call_gemini_from_bytes(pdf_bytes: bytes, filename: str) -> Optional[Dict[str
|
|
| 88 |
}
|
| 89 |
|
| 90 |
try:
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
r.raise_for_status()
|
| 93 |
data = r.json()
|
| 94 |
|
|
|
|
| 4 |
import tempfile
|
| 5 |
import zipfile
|
| 6 |
from io import BytesIO
|
| 7 |
+
import fitz
|
| 8 |
import cv2
|
| 9 |
import numpy as np
|
| 10 |
|
|
|
|
| 15 |
from typing import Dict, Any, Optional
|
| 16 |
from collections import defaultdict
|
| 17 |
|
| 18 |
+
API_KEY = os.environ.get("GEMINI_API_KEY")
|
| 19 |
+
if not API_KEY:
|
| 20 |
+
st.error("Gemini API key not found. Set GEMINI_API_KEY in Hugging Face Secrets.")
|
| 21 |
+
st.stop()
|
| 22 |
+
|
| 23 |
API_URL = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-09-2025:generateContent?key={API_KEY}"
|
| 24 |
|
| 25 |
SCHEMA = {
|
|
|
|
| 92 |
}
|
| 93 |
|
| 94 |
try:
|
| 95 |
+
headers = {
|
| 96 |
+
"Content-Type": "application/json"
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
r = requests.post(API_URL, json=payload, headers=headers, timeout=300)
|
| 100 |
r.raise_for_status()
|
| 101 |
data = r.json()
|
| 102 |
|