Spaces:
Sleeping
Sleeping
Download app.py from samet214/turkish-sentiment-api: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/samet214/turkish-sentiment-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/samet214/turkish-sentiment-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/samet214/turkish-sentiment-api/resolve/main/app.py
1.07 kB
| 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() | |