|
1 | 1 | import streamlit as st
|
2 |
| -import requests |
3 | 2 | import pandas as pd
|
4 | 3 | import numpy as np
|
5 |
| -import os |
6 |
| -from dotenv import load_dotenv |
7 |
| - |
8 |
| -# Load environment variables from .env file |
9 |
| -load_dotenv() |
10 |
| - |
11 |
| -# Get backend URL from environment variable or use default |
12 |
| -BACKEND_URL = os.getenv("BACKEND_URL", "http://localhost:8000") |
13 |
| -API_ENDPOINT = f"{BACKEND_URL}/api/delist-recommender/recommendations" |
| 4 | +from lib.api import fetch_api_data |
14 | 5 |
|
15 | 6 | # --- Helper Functions ---
|
16 | 7 |
|
@@ -60,22 +51,16 @@ def style_recommendation(rec):
|
60 | 51 | def fetch_delist_recommendations():
|
61 | 52 | """Fetches delist recommendations from the backend API."""
|
62 | 53 | try:
|
63 |
| - print(f"Fetching data from: {API_ENDPOINT}") # Debug print |
64 |
| - response = requests.get(API_ENDPOINT, timeout=120) # Increased timeout to 120s |
65 |
| - response.raise_for_status() # Raise an exception for bad status codes |
| 54 | + print("Fetching delist recommendations from API") # Debug print |
| 55 | + response = fetch_api_data( |
| 56 | + "delist-recommender", |
| 57 | + "recommendations", |
| 58 | + retry=True |
| 59 | + ) |
66 | 60 | print("Successfully fetched data from API.") # Debug print
|
67 |
| - return response.json() |
68 |
| - except requests.exceptions.Timeout: |
69 |
| - st.error(f"Error: Timeout connecting to backend API at {API_ENDPOINT}. The request took longer than 120 seconds.") |
70 |
| - return None |
71 |
| - except requests.exceptions.ConnectionError: |
72 |
| - st.error(f"Error: Could not connect to backend API at {API_ENDPOINT}. Please ensure the backend is running.") |
73 |
| - return None |
74 |
| - except requests.exceptions.RequestException as e: |
75 |
| - st.error(f"Error connecting to backend API: {e}") |
76 |
| - return None |
| 61 | + return response |
77 | 62 | except Exception as e:
|
78 |
| - st.error(f"An unexpected error occurred while fetching data: {e}") |
| 63 | + st.error(f"An error occurred while fetching data: {e}") |
79 | 64 | return None
|
80 | 65 |
|
81 | 66 | # --- Streamlit Page ---
|
|
0 commit comments