Spaces:
Sleeping
Sleeping
File size: 1,070 Bytes
74b8900 ad38d4c 74b8900 ad38d4c 74b8900 ad38d4c 74b8900 ad38d4c 74b8900 ad38d4c |
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 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
# Türkçe duygu analizi modeli
model_name = "savasy/bert-base-turkish-sentiment-cased"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
sentiment_model = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
def analyze_text(text):
if not text.strip():
return "Lütfen bir metin girin."
result = sentiment_model(text)[0]
label = result["label"]
score = round(result["score"], 2)
# Model etiketleri: 1 = Olumlu, 0 = Olumsuz
if label == "LABEL_1":
label_text = "Pozitif 😊"
else:
label_text = "Negatif 😞"
return f"{label_text} ({score})"
iface = gr.Interface(
fn=analyze_text,
inputs=gr.Textbox(label="Mesaj Girin"),
outputs=gr.Textbox(label="Duygu Sonucu"),
title="Türkçe Chat Sentiment AI",
description="Girilen Türkçe metnin pozitif veya negatif duygu analizini yapar."
)
iface.launch()
|