Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import BertTokenizer, BertForSequenceClassification | |
| import torch | |
| print("selam") | |
| st.title("Sentiment Analysis with BERT") | |
| user_input = st.text_area("Enter your text here:") | |
| if st.button("Analyze"): | |
| import streamlit as st | |
| from transformers import BertTokenizer, BertForSequenceClassification | |
| import torch | |
| tokenizer = BertTokenizer.from_pretrained("ulascelenk/siena") | |
| model = BertForSequenceClassification.from_pretrained("ulascelenk/siena") | |
| inputs = tokenizer.encode_plus( | |
| user_input, | |
| return_tensors='pt', # PyTorch tensörü olarak döndür | |
| truncation=True, # Metni maksimum uzunluğa göre kes | |
| max_length=128, # Maksimum token uzunluğunu belirleyin | |
| padding='max_length' # Token uzunluğunu maksimuma göre doldur | |
| ) | |
| with torch.no_grad(): | |
| input_ids = inputs['input_ids'] | |
| attention_mask = inputs['attention_mask'] | |
| outputs = model(input_ids, attention_mask=attention_mask) | |
| logits = outputs.logits | |
| # Tahmin edilen sınıfı alın | |
| predicted_class = torch.argmax(logits, dim=1).item() | |
| sentiment_dict = { | |
| 0: "Mild Negative", | |
| 1: "Mild Positive", | |
| 2: "Neutral", | |
| 3: "Strong Negative", | |
| 4: "Strong Positive" | |
| } | |
| # Tahmini kullanıcıya gösterin | |
| st.write(f"Predicted class: {sentiment_dict[predicted_class]}") | |