Created first App Sample
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
API_ENDPOINT = "http://cps.hifeyinc.com/predict"
|
| 5 |
+
|
| 6 |
+
st.title("CPS UseCase Text Classification App")
|
| 7 |
+
|
| 8 |
+
author = st.text_input("Enter Author")
|
| 9 |
+
headline = st.text_area("Enter Headline")
|
| 10 |
+
|
| 11 |
+
if st.button("Predict"):
|
| 12 |
+
if author and headline:
|
| 13 |
+
payload = {
|
| 14 |
+
"data": [{"headline": headline, "authors": author}]
|
| 15 |
+
}
|
| 16 |
+
response = requests.post(API_ENDPOINT, json=payload)
|
| 17 |
+
if response.status_code == 200:
|
| 18 |
+
result = response.json()
|
| 19 |
+
predictions = result.get("predictions", [])
|
| 20 |
+
if predictions:
|
| 21 |
+
st.success(f"Predicted Category: {predictions[0]}")
|
| 22 |
+
else:
|
| 23 |
+
st.warning("No predictions available.")
|
| 24 |
+
else:
|
| 25 |
+
st.error("Error occurred while making prediction.")
|
| 26 |
+
else:
|
| 27 |
+
st.warning("Please enter both author and headline.")
|