File size: 942 Bytes
affa2df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests

# Streamlit UI
st.title("Object Detection with FastAPI and Streamlit")

uploaded_file = st.file_uploader("Choose an image...", type="jpg")

if uploaded_file is not None:
    # Display the uploaded image
    st.image(uploaded_file, caption="Uploaded Image.", use_column_width=True)

    # Make a prediction using FastAPI endpoint
    if st.button("Predict"):
        # Define the FastAPI endpoint URL
        api_url = "http://localhost:8001/predict/"

        # Make a POST request to the FastAPI endpoint
        files = {"file": ("image.jpg", uploaded_file, "image/jpeg")}
        response = requests.post(api_url, files=files)

        if response.status_code == 200:
            # Display the predicted image
            st.image(response.content, caption="Predicted Image.", use_column_width=True)
        else:
            st.error(f"Error: {response.status_code}. Failed to make a prediction.")