import gradio as gr from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification import torch MODEL_NAME = "kaixkhazaki/turkish-sentiment" device = 0 if torch.cuda.is_available() else -1 tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME) sentiment = pipeline("text-classification", model=model, tokenizer=tokenizer, return_all_scores=True, device=device) def analyze(text): results = sentiment(text)[0] results_sorted = sorted(results, key=lambda x: x["score"], reverse=True) formatted = "\n".join([f"{r['label']}: {r['score']:.3f}" for r in results_sorted]) return formatted demo = gr.Interface( fn=analyze, inputs=gr.Textbox(lines=3, placeholder="Bir metin yazın..."), outputs=gr.Textbox(label="Duygu ve Skorlar"), title="Türkçe Duygu Analizi (Skorlarla)", description="Her etiket için olasılık skorlarını gösterir." ) demo.launch()