SaviAnna commited on
Commit
d8146a1
1 Parent(s): 71e717a

Update pages/✨first.py

Browse files
Files changed (1) hide show
  1. pages/✨first.py +46 -110
pages/✨first.py CHANGED
@@ -1,112 +1,48 @@
 
 
 
 
 
1
  import streamlit as st
2
- import base64
3
- import streamlit as st
4
- import plotly.express as px
5
-
6
- df = px.data.iris()
7
-
8
- @st.cache_data
9
- def get_img_as_base64(file):
10
- with open(file, "rb") as f:
11
- data = f.read()
12
- return base64.b64encode(data).decode()
13
-
14
-
15
- page_bg_img = f"""
16
- <style>
17
- [data-testid="stAppViewContainer"] > .main {{
18
- background-image: url("https://wallpapercave.com/wp/wp6480460.jpg");
19
- background-size: 115%;
20
- background-position: top left;
21
- background-repeat: no-repeat;
22
- background-attachment: local;
23
- }}
24
-
25
- [data-testid="stSidebar"] > div:first-child {{
26
- background-image: url("https://ibb.co/ZBkdJRg");
27
- background-size: 115%;
28
- background-position: center;
29
- background-repeat: no-repeat;
30
- background-attachment: fixed;
31
- }}
32
-
33
- [data-testid="stHeader"] {{
34
- background: rgba(0,0,0,0);
35
- }}
36
-
37
- [data-testid="stToolbar"] {{
38
- right: 2rem;
39
- }}
40
-
41
- div.css-1n76uvr.e1tzin5v0 {{
42
- background-color: rgba(238, 238, 238, 0.5);
43
- border: 10px solid #EEEEEE;
44
- padding: 5% 5% 5% 10%;
45
- border-radius: 5px;
46
- }}
47
-
48
- </style>
49
- """
50
- st.markdown(page_bg_img, unsafe_allow_html=True)
51
-
52
- import tensorflow as tf
53
- from tensorflow import keras
54
- import numpy as np
55
- import matplotlib.pyplot as plt
56
-
57
- ################################################################################################
58
- #Тут нужно будет добаить модель. Ниже пример:
59
-
60
- # # Загрузка модели
61
- # model = keras.models.load_model('cgan_model.h5')
62
-
63
- # # Задание размерностей входных данных модели
64
- # latent_dim = 128
65
- # num_classes = 10
66
-
67
- # # Функция для генерации изображения
68
- # def generate_image(number):
69
- # random_latent_vector = tf.random.normal(shape=(1, latent_dim))
70
- # one_hot_label = tf.one_hot([number], num_classes)
71
- # input_data = tf.concat([random_latent_vector, one_hot_label], axis=1)
72
-
73
- # generated_image = model.predict(input_data)
74
- # generated_image = generated_image.reshape(28, 28)
75
- # generated_image = tf.image.resize(generated_image[None, ...], (28, 28))[0] # Добавлено [None, ...] для добавления измерения
76
- # return generated_image
77
-
78
- ################################################################################################
79
-
80
- #Оформление
81
-
82
- col1, col2, col3 = st.columns([1,5,1])
83
- with col2:
84
-
85
- st.title('Название модели')
86
-
87
- col1, col2, col3 = st.columns([2,5,2])
88
- with col2:
89
-
90
- number = st.slider('Выберите число:', 0, 9, step=1)
91
-
92
- ################################################################################################
93
- # Часть, отображаемая на странице
94
-
95
- # number = st.slider('Выберите число:', 0, 9, step=1)
96
-
97
-
98
- # #col1.subheader("Гистограмма total_bill:")
99
-
100
- # # Генерация и отображение изображения
101
- # generated_image = generate_image(number)
102
- # generated_image_np = generated_image.numpy() # Преобразование в массив NumPy
103
- # fig, ax = plt.subplots()
104
- # ax.scatter([1, 2], [1, 2], color='black')
105
- # plt.imshow(generated_image_np, cmap='gray')
106
- # plt.axis('off')
107
- # fig.set_size_inches(3, 3)
108
- # st.pyplot(fig)
109
 
110
- ################################################################################################
111
- #st.markdown("<div style='text-align: center; font-size: 25px;'> ", unsafe_allow_html=True)
112
- #st.markdown("<div style='text-align: center; font-size: 25px;'> ", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ rom sklearn.feature_extraction.text import CountVectorizer
2
+ from sklearn.linear_model import LogisticRegression
3
+ import re
4
+ import string
5
+ import pickle
6
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ # Функция очистки текста
9
+ def clean(text):
10
+ text = text.lower() # нижний регистр
11
+ text = re.sub(r'http\S+', " ", text) # удаляем ссылки
12
+ text = re.sub(r'@\w+',' ',text) # удаляем упоминания пользователей
13
+ text = re.sub(r'#\w+', ' ', text) # удаляем хэштеги
14
+ text = re.sub(r'\d+', ' ', text) # удаляем числа
15
+ text = text.translate(str.maketrans('', '', string.punctuation))
16
+ return text
17
+
18
+ # Загрузка весов модели
19
+
20
+ model_filename = '/home/nika/ds-phase-2/10-nlp/model_weights.pkl'
21
+ with open(model_filename, 'rb') as file:
22
+ model = pickle.load(file)
23
+
24
+ # Загрузка весов векторизатора
25
+ vectorizer = CountVectorizer()
26
+ vectorizer_filename = '/home/nika/ds-phase-2/10-nlp/vectorizer_weights.pkl'
27
+ with open(vectorizer_filename, 'rb') as file:
28
+ vectorizer = pickle.load(file)
29
+
30
+ # Само приложение
31
+
32
+ st.title("CritiSense")
33
+ st.subheader("Movie Review Sentiment Analyzer")
34
+ st.write("CritiSense is a powerful app that analyzes the sentiment of movie reviews.")
35
+ st.write("Whether you want to know if a review is positive or negative, CritiSense has got you covered.")
36
+ st.write("Just enter the review, and our app will provide you with instant sentiment analysis.")
37
+ st.write("Make informed decisions about movies with CritiSense!")
38
+ user_review = st.text_input("Enter your review:", "")
39
+ user_review_clean = clean(user_review)
40
+ user_features = vectorizer.transform([user_review_clean])
41
+ prediction = model.predict(user_features)
42
+
43
+ st.write("Review:", user_review)
44
+
45
+ if prediction == 1:
46
+ st.markdown("<p style='color: green;'>Sentiment: Positive</p>", unsafe_allow_html=True)
47
+ else:
48
+ st.markdown("<p style='color: red;'>Sentiment: Negative</p>", unsafe_allow_html=True)