Spaces:
Sleeping
Sleeping
Update app.py
#1
by lmnindzja - opened
app.py
CHANGED
|
@@ -51,8 +51,10 @@ def stream_generate(model, tokenizer, prompt, max_length, temperature, top_p, to
|
|
| 51 |
next_token_id = outputs[0, -1].unsqueeze(0)
|
| 52 |
output_ids = torch.cat([output_ids, next_token_id.unsqueeze(0)], dim=-1)
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
| 56 |
if next_token_id == tokenizer.eos_token_id:
|
| 57 |
break
|
| 58 |
|
|
@@ -138,7 +140,14 @@ def main():
|
|
| 138 |
rating = st.slider("Рейтинг", 1, 5, 1)
|
| 139 |
key_words = st.text_input("Ключевые слова", value="десерт, торт, цена")
|
| 140 |
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
if not category or not key_words:
|
| 144 |
st.warning("Пожалуйста, заполните все поля ввода.")
|
|
@@ -154,7 +163,7 @@ def main():
|
|
| 154 |
model, tokenizer, input_text, params['max_length'], params['temperature'],
|
| 155 |
params['top_p'], params['top_k'], params['do_sample'], params['no_repeat_ngram_size']
|
| 156 |
):
|
| 157 |
-
generated_text += word
|
| 158 |
formatted_text = capitalize_and_punctuate_stream(generated_text)
|
| 159 |
placeholder.write(formatted_text)
|
| 160 |
|
|
|
|
| 51 |
next_token_id = outputs[0, -1].unsqueeze(0)
|
| 52 |
output_ids = torch.cat([output_ids, next_token_id.unsqueeze(0)], dim=-1)
|
| 53 |
|
| 54 |
+
# Очистка и корректировка слова
|
| 55 |
+
new_word = tokenizer.decode(next_token_id, skip_special_tokens=True).strip()
|
| 56 |
+
clean_word = new_word.replace(" ", "").replace("▁", " ") # Очистка BPE пробелов
|
| 57 |
+
yield clean_word
|
| 58 |
if next_token_id == tokenizer.eos_token_id:
|
| 59 |
break
|
| 60 |
|
|
|
|
| 140 |
rating = st.slider("Рейтинг", 1, 5, 1)
|
| 141 |
key_words = st.text_input("Ключевые слова", value="десерт, торт, цена")
|
| 142 |
|
| 143 |
+
# Улучшенный промпт
|
| 144 |
+
input_text = (
|
| 145 |
+
f"Напиши отзыв для заведения. "
|
| 146 |
+
f"Категория: {category}. "
|
| 147 |
+
f"Рейтинг: {rating} из 5. "
|
| 148 |
+
f"Включи ключевые слова: {key_words}. "
|
| 149 |
+
f"Отзыв:"
|
| 150 |
+
)
|
| 151 |
|
| 152 |
if not category or not key_words:
|
| 153 |
st.warning("Пожалуйста, заполните все поля ввода.")
|
|
|
|
| 163 |
model, tokenizer, input_text, params['max_length'], params['temperature'],
|
| 164 |
params['top_p'], params['top_k'], params['do_sample'], params['no_repeat_ngram_size']
|
| 165 |
):
|
| 166 |
+
generated_text += word # Корректное добавление слов
|
| 167 |
formatted_text = capitalize_and_punctuate_stream(generated_text)
|
| 168 |
placeholder.write(formatted_text)
|
| 169 |
|