Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
ts token authentication
Browse files- app/main.py +5 -2
app/main.py
CHANGED
|
@@ -19,7 +19,6 @@ logger = logging.getLogger(__name__)
|
|
| 19 |
|
| 20 |
# WHISP API configuration
|
| 21 |
WHISP_API_URL = config.get('whisp', 'WHISP_API_URL', fallback="https://giz-chatfed-whisp.hf.space/")
|
| 22 |
-
HF_TOKEN = os.getenv('HF_TOKEN')
|
| 23 |
|
| 24 |
def get_value(df, colname):
|
| 25 |
"""Fetch value from WhispAPI-style Column/Value dataframe"""
|
|
@@ -90,6 +89,10 @@ Fecha de análisis: {datetime.now().isoformat()}"""
|
|
| 90 |
def process_geojson_whisp(file_content: bytes, filename: str) -> tuple[str, dict]:
|
| 91 |
"""Process GeoJSON file through WHISP API and return formatted context"""
|
| 92 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
# Create temporary file for WHISP API
|
| 94 |
import tempfile
|
| 95 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.geojson') as tmp_file:
|
|
@@ -98,7 +101,7 @@ def process_geojson_whisp(file_content: bytes, filename: str) -> tuple[str, dict
|
|
| 98 |
|
| 99 |
try:
|
| 100 |
# Call WHISP API
|
| 101 |
-
client = Client(WHISP_API_URL
|
| 102 |
result = client.predict(
|
| 103 |
file=handle_file(tmp_file_path),
|
| 104 |
api_name="/get_statistics"
|
|
|
|
| 19 |
|
| 20 |
# WHISP API configuration
|
| 21 |
WHISP_API_URL = config.get('whisp', 'WHISP_API_URL', fallback="https://giz-chatfed-whisp.hf.space/")
|
|
|
|
| 22 |
|
| 23 |
def get_value(df, colname):
|
| 24 |
"""Fetch value from WhispAPI-style Column/Value dataframe"""
|
|
|
|
| 89 |
def process_geojson_whisp(file_content: bytes, filename: str) -> tuple[str, dict]:
|
| 90 |
"""Process GeoJSON file through WHISP API and return formatted context"""
|
| 91 |
try:
|
| 92 |
+
hf_token = os.getenv('HF_TOKEN')
|
| 93 |
+
if not hf_token:
|
| 94 |
+
raise ValueError("HF_TOKEN environment variable not found. Please set it in your Space secrets.")
|
| 95 |
+
|
| 96 |
# Create temporary file for WHISP API
|
| 97 |
import tempfile
|
| 98 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.geojson') as tmp_file:
|
|
|
|
| 101 |
|
| 102 |
try:
|
| 103 |
# Call WHISP API
|
| 104 |
+
client = Client(WHISP_API_URL)
|
| 105 |
result = client.predict(
|
| 106 |
file=handle_file(tmp_file_path),
|
| 107 |
api_name="/get_statistics"
|