Spaces:
Sleeping
Sleeping
| 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() | |