File size: 929 Bytes
92b63f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
import streamlit as st


# Helper function to send data to FastAPI for prediction
def get_prediction(input_data):
    """
    Sends the input data to the FastAPI backend to get a prediction.

    Args:
        input_data (pd.DataFrame): Input data to send to the FastAPI backend

    Returns:
        dict or None: The JSON response from the FastAPI backend, or None if the request failed
    """


    url = "http://127.0.0.1:8001/predict"  # URL of the FastAPI backend
    headers = {"Content-Type": "application/json"}

    json_data = {
        "dataframe_records": input_data.to_dict(orient="records")
    }

    try:
        response = requests.post(url, headers=headers, json=json_data)
        response.raise_for_status()
        return response.json()  # Return JSON response from FastAPI
    except requests.exceptions.RequestException as e:
        st.error(f"Request failed: {e}")
        return None