YAMITEK commited on
Commit
d840a48
·
verified ·
1 Parent(s): 1b85847

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -54
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
- html_temp = """
11
- <div style="background-color:black;padding:10px">
12
- <h2 style="color:white;text-align:center;">Chat GPT Review Prediction </h2>
13
- </div>
14
- """
15
- st.markdown(html_temp, unsafe_allow_html=True)
16
-
17
- image_url="https://storage.googleapis.com/kaggle-datasets-images/6377125/10302664/91e3eb67027ab3122886b971613e7c2f/dataset-cover.jpg?t=2024-12-26-10-34-17"
18
-
19
- st.image(image_url, use_container_width=True)
20
-
21
-
22
-
23
- input_txt=st.text_input("Enter the Review")
24
-
25
-
26
- # preprocess the text
27
-
28
- def preprocess_text(text):
29
- text = text.lower()
30
- text = re.sub(r'\d+', '', text)
31
- text = re.sub(r'[^\w\s]', '', text)
32
- text = re.sub(r'\s+', ' ', text)
33
-
34
- return text
35
-
36
- # loading the models
37
- loaded_tfidf = joblib.load("tfidf_model.joblib")
38
- model = joblib.load("chat_review_model.joblib")
39
-
40
- # processing
41
- if input:
42
- test=preprocess_text(input_txt)
43
- label=loaded_tfidf.transform([test])
44
-
45
- # predict and display
46
- if st.button("Submit"):
47
- predict=model.predict(label)[0]
48
-
49
- if predict==1:
50
- st.write("Its is a Good Review")
51
-
52
- elif predict==0:
53
- st.write("Its is a Bad Review")
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("")