File size: 1,159 Bytes
fa66a12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gradio as gr
import torch
import torch.nn.functional as F
from transformers import AutoTokenizer, AutoModelForSequenceClassification

# HuggingFace repo’sundaki modeli kullan
MODEL_NAME = "eneser/Nasilsin_ai_model"

tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
model.eval()

id2label = model.config.id2label

def predict(text):
    if not text.strip():
        return {"error": "Metin girin"}

    inputs = tokenizer(
        text,
        return_tensors="pt",
        truncation=True,
        padding=True,
        max_length=128
    )

    with torch.no_grad():
        logits = model(**inputs).logits

    probs = F.softmax(logits, dim=1)[0]

    results = {id2label[i]: round(float(probs[i]), 4) for i in range(len(probs))}
    best = max(results, key=results.get)

    return {
        "tahmin": best,
        "guven": results[best],
        "tum_sonuclar": results
    }

demo = gr.Interface(
    fn=predict,
    inputs=gr.Textbox(lines=4, placeholder="Duygunu anlat..."),
    outputs=gr.JSON(),
    title="Nasilsin_AI – Türkçe Duygu Analizi"
)

demo.launch()