File size: 1,932 Bytes
ea81955
 
 
4ce9a7a
6b0a89b
ea81955
 
 
e4bd1ee
 
 
6b0a89b
e4bd1ee
 
 
 
 
 
ea81955
 
 
 
 
6b0a89b
 
 
 
ea81955
 
6b0a89b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea81955
 
 
6b0a89b
ea81955
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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.")