Veronika1101 commited on
Commit
85d031e
1 Parent(s): 655b0d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -32,7 +32,7 @@ def main():
32
  if 'user_name' not in st.session_state:
33
  st.session_state.user_name = ''
34
  if 'product_name' not in st.session_state:
35
- st.session_state.product_name = '' # New variable for product name
36
  if 'model_a' not in st.session_state:
37
  st.session_state.model_a = ''
38
  if 'model_b' not in st.session_state:
@@ -45,6 +45,10 @@ def main():
45
  st.session_state.vote_submitted = False
46
  if 'used_models' not in st.session_state:
47
  st.session_state.used_models = []
 
 
 
 
48
 
49
  instruction_gpt = read_prompt('prompts/gpt_prompt.txt')
50
  instruction_gemma = read_prompt('prompts/gemma_prompt.txt')
@@ -53,14 +57,12 @@ def main():
53
  random_row = get_random_review(data)
54
  st.session_state.original_review = random_row['body']
55
  st.session_state.user_name = random_row['user_name']
56
- st.session_state.product_name = random_row['names'] # Get the product name
57
 
58
  if pd.isna(st.session_state.user_name) or st.session_state.user_name.strip() == '':
59
  st.session_state.user_name = 'Пользователь'
60
  if pd.isna(st.session_state.product_name) or st.session_state.product_name.strip() == '':
61
- st.session_state.product_name = 'не найдено' # Default value if name is missing
62
-
63
- st.session_state.used_models = []
64
 
65
  st.session_state.used_models = []
66
 
@@ -72,15 +74,17 @@ def main():
72
  st.session_state.rewrite_a = ''
73
  st.session_state.rewrite_b = ''
74
  st.session_state.vote_submitted = False
 
 
75
 
76
- if st.session_state.original_review:
77
  st.markdown(f"<h2>📝 Оригинальный отзыв от {st.session_state.user_name}:<br>Наименование товара: {st.session_state.product_name}</h2>", unsafe_allow_html=True)
78
  st.markdown(
79
  f"<div class='original-review'>{st.session_state.original_review}</div>",
80
  unsafe_allow_html=True
81
  )
82
 
83
- if st.button("⚔️ Сгенерировать рерайты"):
84
  with st.spinner("Генерация рерайтов..."):
85
 
86
  def generate_rewrite_for_model(model_name, text):
@@ -95,8 +99,9 @@ def main():
95
  st.session_state.model_a, st.session_state.original_review)
96
  st.session_state.rewrite_b = generate_rewrite_for_model(
97
  st.session_state.model_b, st.session_state.original_review)
 
98
 
99
- if st.session_state.rewrite_a and st.session_state.rewrite_b:
100
  st.markdown("""
101
  <h2>🗳️ Проголосуй за лучший рерайт!</h2>
102
  <p>Выбери рерайт, который соответствует данным критериям:</p>
@@ -117,7 +122,7 @@ def main():
117
  )
118
  st.markdown("</div>", unsafe_allow_html=True)
119
  if not st.session_state.vote_submitted:
120
- if st.button("👍 Выбрать Model A"):
121
  st.session_state.vote_submitted = True
122
  st.success("Вы выбрали Model A")
123
  save_vote(db, 'left', models)
@@ -129,13 +134,13 @@ def main():
129
  )
130
  st.markdown("</div>", unsafe_allow_html=True)
131
  if not st.session_state.vote_submitted:
132
- if st.button("👍 Выбрать Model B"):
133
  st.session_state.vote_submitted = True
134
  st.success("Вы выбрали Model B")
135
  save_vote(db, 'right', models)
136
 
137
  if not st.session_state.vote_submitted:
138
- if st.button("😕 Ни один рерайт не понравился, получить другие рерайты"):
139
  available_models = [model for model in models if model not in st.session_state.used_models]
140
  if len(available_models) < 2:
141
  st.session_state.used_models = []
 
32
  if 'user_name' not in st.session_state:
33
  st.session_state.user_name = ''
34
  if 'product_name' not in st.session_state:
35
+ st.session_state.product_name = ''
36
  if 'model_a' not in st.session_state:
37
  st.session_state.model_a = ''
38
  if 'model_b' not in st.session_state:
 
45
  st.session_state.vote_submitted = False
46
  if 'used_models' not in st.session_state:
47
  st.session_state.used_models = []
48
+ if 'battle_started' not in st.session_state:
49
+ st.session_state.battle_started = False
50
+ if 'rewrites_generated' not in st.session_state:
51
+ st.session_state.rewrites_generated = False
52
 
53
  instruction_gpt = read_prompt('prompts/gpt_prompt.txt')
54
  instruction_gemma = read_prompt('prompts/gemma_prompt.txt')
 
57
  random_row = get_random_review(data)
58
  st.session_state.original_review = random_row['body']
59
  st.session_state.user_name = random_row['user_name']
60
+ st.session_state.product_name = random_row['names']
61
 
62
  if pd.isna(st.session_state.user_name) or st.session_state.user_name.strip() == '':
63
  st.session_state.user_name = 'Пользователь'
64
  if pd.isna(st.session_state.product_name) or st.session_state.product_name.strip() == '':
65
+ st.session_state.product_name = 'не найдено'
 
 
66
 
67
  st.session_state.used_models = []
68
 
 
74
  st.session_state.rewrite_a = ''
75
  st.session_state.rewrite_b = ''
76
  st.session_state.vote_submitted = False
77
+ st.session_state.battle_started = True
78
+ st.session_state.rewrites_generated = False
79
 
80
+ if st.session_state.battle_started:
81
  st.markdown(f"<h2>📝 Оригинальный отзыв от {st.session_state.user_name}:<br>Наименование товара: {st.session_state.product_name}</h2>", unsafe_allow_html=True)
82
  st.markdown(
83
  f"<div class='original-review'>{st.session_state.original_review}</div>",
84
  unsafe_allow_html=True
85
  )
86
 
87
+ if st.button("⚔️ Сгенерировать рерайты", key='generate_rewrites'):
88
  with st.spinner("Генерация рерайтов..."):
89
 
90
  def generate_rewrite_for_model(model_name, text):
 
99
  st.session_state.model_a, st.session_state.original_review)
100
  st.session_state.rewrite_b = generate_rewrite_for_model(
101
  st.session_state.model_b, st.session_state.original_review)
102
+ st.session_state.rewrites_generated = True
103
 
104
+ if st.session_state.rewrites_generated:
105
  st.markdown("""
106
  <h2>🗳️ Проголосуй за лучший рерайт!</h2>
107
  <p>Выбери рерайт, который соответствует данным критериям:</p>
 
122
  )
123
  st.markdown("</div>", unsafe_allow_html=True)
124
  if not st.session_state.vote_submitted:
125
+ if st.button("👍 Выбрать Model A", key='choose_model_a'):
126
  st.session_state.vote_submitted = True
127
  st.success("Вы выбрали Model A")
128
  save_vote(db, 'left', models)
 
134
  )
135
  st.markdown("</div>", unsafe_allow_html=True)
136
  if not st.session_state.vote_submitted:
137
+ if st.button("👍 Выбрать Model B", key='choose_model_b'):
138
  st.session_state.vote_submitted = True
139
  st.success("Вы выбрали Model B")
140
  save_vote(db, 'right', models)
141
 
142
  if not st.session_state.vote_submitted:
143
+ if st.button("😕 Ни один рерайт не понравился, получить другие рерайты", key='regenerate_rewrites'):
144
  available_models = [model for model in models if model not in st.session_state.used_models]
145
  if len(available_models) < 2:
146
  st.session_state.used_models = []