Spaces:
Runtime error
Runtime error
import streamlit as st | |
import tensorflow as tf | |
import tensorflow_hub as hub | |
import numpy as np | |
new_model = tf.keras.models.load_model("best_model.h5",custom_objects={"KerasLayer": hub.KerasLayer}, compile=False) | |
def welcome(): | |
return "Welcome to my app" | |
def main(): | |
st.title("Financial News Sentiment Analysis App") | |
st.write( | |
"This app will tell you if mention news is Fake or Real by using Natural Language Processing") | |
html_temp = """ | |
<div style="background-color:tomato;padding:10px"> | |
<h2 style="color:white;text-align:center;">Financial News Sentiment Analysis </h2> | |
</div> | |
""" | |
st.markdown(html_temp, unsafe_allow_html=True) | |
text = st.text_area("Enter your Financial News") | |
if st.button("Predict"): | |
pred_prob = new_model.predict([text]) | |
predict = tf.squeeze(tf.round(pred_prob)).numpy() | |
st.subheader("AI thinks that ...") | |
if predict == 0: | |
col1, col2 = st.columns(2) | |
col1.metric("Prediction", value="It's a Negative News.") | |
col2.metric("Confidence Level", value=f"{np.round(np.max(pred_prob) * 100)}%") | |
else: | |
col1, col2 = st.columns(2) | |
col1.metric("Prediction", value="It's a Positive News.") | |
col2.metric("Confidence Level", value=f"{np.round(np.max(pred_prob) * 100)}%") | |
if st.button("About"): | |
st.text("Built with Streamlit") | |
if __name__ == '__main__': | |
main() | |