Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| import torch # Bu satırı ekledim | |
| # Eğer GPU varsa ve yeterli bellek yoksa, CPU'ya zorlayabiliriz | |
| # device = 0 (GPU için) veya -1 (CPU için) | |
| clf = pipeline("sentiment-analysis", | |
| model="distilbert-base-uncased-finetuned-sst-2-english", | |
| device=-1) # Burayı -1 yaparak CPU'da çalışmaya zorluyoruz | |
| def analyze(text): | |
| text = (text or "").strip() | |
| if not text: | |
| return {"NEGATIVE": 0, "POSITIVE": 0} # Boş girdi için varsayılan dönüş | |
| out = clf(text)[0] | |
| if out["label"] == "POSITIVE": | |
| return {"POSITIVE": out["score"], "NEGATIVE": (1 - out["score"])} | |
| else: | |
| return {"NEGATIVE": out["score"], "POSITIVE": (1 - out["score"])} | |
| demo = gr.Interface(fn=analyze, | |
| inputs=gr.Textbox(lines=4, label="Metin"), | |
| outputs="label", # Çıktıyı label olarak değiştirdim, daha iyi görünebilir. | |
| title="Metin Duygu Analizi") | |
| demo.launch(server_name="0.0.0.0", server_port=7860) |