import streamlit as st import requests BOW_API_ENDPOINT = "http://cps.bow.hifeyinc.com/predict" SEMANTIC_API_ENDPOINT = "http://cps.hifeyinc.com/predict" st.title("CPS UseCase Text Classification App") st.markdown( """ The app was trained to predict the type of headline a post is. Predictions are made by two models: a bag-of-words model and a semantic model. Examples of inputs you can provide are: - Authors: David - Headline: Find a nice summer vacation destination. """ ) author = st.text_input("Enter Author") headline = st.text_area("Enter Headline") if st.button("Predict"): if author and headline: bow_payload = { "data": [{"headline": headline, "authors": author}] } semantic_payload = { "data": [{"headline": headline, "authors": author}] } bow_response = requests.post(BOW_API_ENDPOINT, json=bow_payload) semantic_response = requests.post(SEMANTIC_API_ENDPOINT, json=semantic_payload) if bow_response.status_code == 200 and semantic_response.status_code == 200: bow_result = bow_response.json() semantic_result = semantic_response.json() bow_predictions = bow_result.get("predictions", []) semantic_predictions = semantic_result.get("predictions", []) if bow_predictions and semantic_predictions: st.success("Predictions:") prediction_data = { "Model": ["Bag of Words", "Semantic"], "Prediction": [bow_predictions[0], semantic_predictions[0]] } st.table(prediction_data) else: st.warning("No predictions available.") else: st.error("Error occurred while making predictions.") else: st.warning("Please enter both author and headline.")