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.")