Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -516,12 +516,12 @@ def save_to_oci_bucket(image, text_content, story_title, page_number, file_type=
|
|
| 516 |
'subfolder': f'stories/{story_title}'
|
| 517 |
}
|
| 518 |
|
| 519 |
-
# Create session with retry strategy
|
| 520 |
session = requests.Session()
|
| 521 |
retry_strategy = Retry(
|
| 522 |
total=3, # Retry 3 times
|
| 523 |
status_forcelist=[429, 500, 502, 503, 504], # Retry on these status codes
|
| 524 |
-
|
| 525 |
backoff_factor=1 # Wait 1, 2, 4 seconds between retries
|
| 526 |
)
|
| 527 |
adapter = HTTPAdapter(max_retries=retry_strategy)
|
|
@@ -545,6 +545,28 @@ def save_to_oci_bucket(image, text_content, story_title, page_number, file_type=
|
|
| 545 |
except Exception as e:
|
| 546 |
raise Exception(f"OCI upload failed: {str(e)}")
|
| 547 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
# JOB MANAGEMENT FUNCTIONS
|
| 549 |
def create_job(story_request: StorybookRequest) -> str:
|
| 550 |
job_id = str(uuid.uuid4())
|
|
|
|
| 516 |
'subfolder': f'stories/{story_title}'
|
| 517 |
}
|
| 518 |
|
| 519 |
+
# Create session with retry strategy - FIXED PARAMETERS
|
| 520 |
session = requests.Session()
|
| 521 |
retry_strategy = Retry(
|
| 522 |
total=3, # Retry 3 times
|
| 523 |
status_forcelist=[429, 500, 502, 503, 504], # Retry on these status codes
|
| 524 |
+
allowed_methods=["POST"], # CORRECTED: Use 'allowed_methods' instead of 'method_whitelist'
|
| 525 |
backoff_factor=1 # Wait 1, 2, 4 seconds between retries
|
| 526 |
)
|
| 527 |
adapter = HTTPAdapter(max_retries=retry_strategy)
|
|
|
|
| 545 |
except Exception as e:
|
| 546 |
raise Exception(f"OCI upload failed: {str(e)}")
|
| 547 |
|
| 548 |
+
def test_oci_connection():
|
| 549 |
+
"""Test connection to OCI API"""
|
| 550 |
+
try:
|
| 551 |
+
test_url = f"{OCI_API_BASE_URL}/api/health"
|
| 552 |
+
print(f"🔧 Testing connection to: {test_url}")
|
| 553 |
+
|
| 554 |
+
response = requests.get(test_url, timeout=10)
|
| 555 |
+
print(f"🔧 Connection test response: {response.status_code}")
|
| 556 |
+
|
| 557 |
+
if response.status_code == 200:
|
| 558 |
+
result = response.json()
|
| 559 |
+
print(f"🔧 OCI API Health: {result}")
|
| 560 |
+
return True
|
| 561 |
+
else:
|
| 562 |
+
print(f"🔧 OCI API not healthy: {response.status_code}")
|
| 563 |
+
return False
|
| 564 |
+
|
| 565 |
+
except Exception as e:
|
| 566 |
+
print(f"🔧 Connection test failed: {e}")
|
| 567 |
+
return False
|
| 568 |
+
|
| 569 |
+
|
| 570 |
# JOB MANAGEMENT FUNCTIONS
|
| 571 |
def create_job(story_request: StorybookRequest) -> str:
|
| 572 |
job_id = str(uuid.uuid4())
|