Spaces:
Sleeping
Sleeping
File size: 2,410 Bytes
d840a48 |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
import pandas as pd
import numpy as np
import re
import streamlit as st
import joblib
import numpy as np
import pandas as pd
st.markdown(f"""
<style>
/* Set the background image for the entire app */
.stApp {{
background-color: #BA944E;
background-size: 100px;
background-repeat:no;
background-attachment: auto;
background-position:full;
}}
</style>
""", unsafe_allow_html=True)
html_temp = """
<div style="background-color:black;padding:10px">
<h2 style="color:white;text-align:center;">Chat GPT Review Prediction </h2>
</div>
"""
st.markdown(html_temp, unsafe_allow_html=True)
image_url="https://storage.googleapis.com/kaggle-datasets-images/6377125/10302664/91e3eb67027ab3122886b971613e7c2f/dataset-cover.jpg?t=2024-12-26-10-34-17"
st.image(image_url, use_container_width=True)
input_txt=st.text_input("Enter the Review")
# preprocess the text
def preprocess_text(text):
text = text.lower()
text = re.sub(r'\d+', '', text)
text = re.sub(r'[^\w\s]', '', text)
text = re.sub(r'\s+', ' ', text)
return text
# loading the models
loaded_tfidf = joblib.load("tfidf_model.joblib")
model = joblib.load("chat_review_model.joblib")
# processing
if input:
test=preprocess_text(input_txt)
label=loaded_tfidf.transform([test])
# Predict and display the result
if st.button("Submit"):
try:
# Get prediction from the model
prediction = model.predict(label)[0]
# Define messages and colors
review_status = {
1: ("✅ It is a Good Review!", "#32CD32"), # Green
0: ("❌ It is a Bad Review!", "#FF4500") # Red-Orange
}
# Get message and color based on prediction
message, color = review_status.get(prediction, ("❓ Unknown Prediction", "#808080"))
# Display styled result
st.markdown(f"""
<div style="
padding: 15px;
background-color: {color};
border-radius: 10px;
text-align: center;
font-size: 18px;
font-weight: bold;
color: white;">
{message}
</div>
""", unsafe_allow_html=True)
except Exception as e:
st.error(f"⚠️ Error in prediction: {e}")
st.write("")
|