Spaces:
Sleeping
Sleeping
Update app.py
Browse files18 unmodified lines19202122222324251 unmodified line272829303031323334343535363738394039404142434445464748495045515253544855565758595360616263646518 unmodified lines device_map="auto" ) test_prompt = """Задача: найти эмоционально значимые части в тексте. test_prompt = """Задача: проанализируй эмоциональное состояние в тексте. Найди и перечисли основные эмоции, чувства и настроения.
Текст:Я в печали брожу по аллеям опустевшего парка,1 unmodified lineВ этот час одиночества сердце сжимается жарко,И тоска, словно тень, пробирается к тёмным углам.
Эмоциональный анализ:"""Анализ эмоций:""" print(f"\nTesting with prompt: {test_prompt}") # Токенизируем с явным вниманием inputs = tokenizer( test_prompt, encoded = tokenizer.encode_plus( test_prompt, add_special_tokens=True, return_tensors="pt", padding=True, truncation=True, max_length=512 ).to("cuda" if torch.cuda.is_available() else "cpu") max_length=512, return_attention_mask=True ) input_ids = encoded['input_ids'].to("cuda" if torch.cuda.is_available() else "cpu") attention_mask = encoded['attention_mask'].to("cuda" if torch.cuda.is_available() else "cpu") print("Generating response...") with torch.no_grad(): outputs = model.generate( inputs['input_ids'], input_ids, attention_mask=attention_mask, max_length=1024, num_return_sequences=1, temperature=0.8, temperature=0.7, # Уменьшил температуру для более сфокусированного ответа top_p=0.9, do_sample=True, pad_token_id=tokenizer.pad_token_id, eos_token_id=tokenizer.eos_token_id, repetition_penalty=1.2 repetition_penalty=1.2, no_repeat_ngram_size=3, # Избегаем повторений early_stopping=True ) response = tokenizer.decode(outputs[0], skip_special_tokens=True)app.py+18-9