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