File size: 1,238 Bytes
8e98345
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

# Define label dictionary (adjust based on your data and model)
label_dict = {
    0: "Yanlış Anlama Değil",
    1: "Yanlış Anlama",
    # ... other labels (add more if needed)
}

# Load model and tokenizer
model_name = "your_model_directory"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

# Select device (GPU if available)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)

# User input
text = st.text_input("Yanlış anlama olup olmadığını kontrol etmek istediğiniz metni girin:")

# Prediction (if text is provided)
if text:
    inputs = tokenizer(text, return_tensors='pt').to(device)
    outputs = model(**inputs)
    logits = outputs.logits
    predicted_class_id = torch.argmax(logits, dim=1).item()

    # Handle predicted class ID
    if predicted_class_id in label_dict:
        st.write("Tahmin edilen sonuç:", label_dict[predicted_class_id])
    else:
        st.write("Tahmin edilen sonuç:", "Model tarafından bilinmeyen bir yanlış anlama türü")