Spaces:
Sleeping
Sleeping
Download app.py from samet214/tr-sentiment-api: direct link, hf CLI and curl.
- Browser
- Download file 750 Bytes
-
https://huggingface.co/spaces/samet214/tr-sentiment-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/samet214/tr-sentiment-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/samet214/tr-sentiment-api/resolve/main/app.py
750 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| # Modeli yükle | |
| classifier = pipeline( | |
| "sentiment-analysis", | |
| model="saribasmetehan/bert-base-turkish-sentiment-analysis" | |
| ) | |
| # Fonksiyon | |
| def analyze_sentiment(text): | |
| result = classifier(text)[0] | |
| label_map = { | |
| "LABEL_0": "Nötr", | |
| "LABEL_1": "Pozitif", | |
| "LABEL_2": "Negatif" | |
| } | |
| return label_map.get(result['label'], result['label']) | |
| # Gradio arayüzü | |
| iface = gr.Interface( | |
| fn=analyze_sentiment, | |
| inputs=gr.Textbox(lines=3, placeholder="Metni buraya yazın..."), | |
| outputs="text", | |
| title="Türkçe Duygu Analizi", | |
| description="Bu uygulama verilen Türkçe metni Pozitif, Nötr veya Negatif olarak sınıflandırır." | |
| ) | |
| iface.launch() | |