Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def analyze(text):
|
| 8 |
text = (text or "").strip()
|
| 9 |
-
if not text:
|
|
|
|
| 10 |
out = clf(text)[0]
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
demo = gr.Interface(fn=analyze,
|
| 15 |
inputs=gr.Textbox(lines=4, label="Metin"),
|
| 16 |
-
outputs="
|
| 17 |
-
title="
|
|
|
|
| 18 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import torch # Bu satırı ekledim
|
| 4 |
|
| 5 |
+
# Eğer GPU varsa ve yeterli bellek yoksa, CPU'ya zorlayabiliriz
|
| 6 |
+
# device = 0 (GPU için) veya -1 (CPU için)
|
| 7 |
+
clf = pipeline("sentiment-analysis",
|
| 8 |
+
model="distilbert-base-uncased-finetuned-sst-2-english",
|
| 9 |
+
device=-1) # Burayı -1 yaparak CPU'da çalışmaya zorluyoruz
|
| 10 |
|
| 11 |
def analyze(text):
|
| 12 |
text = (text or "").strip()
|
| 13 |
+
if not text:
|
| 14 |
+
return {"NEGATIVE": 0, "POSITIVE": 0} # Boş girdi için varsayılan dönüş
|
| 15 |
out = clf(text)[0]
|
| 16 |
+
if out["label"] == "POSITIVE":
|
| 17 |
+
return {"POSITIVE": out["score"], "NEGATIVE": (1 - out["score"])}
|
| 18 |
+
else:
|
| 19 |
+
return {"NEGATIVE": out["score"], "POSITIVE": (1 - out["score"])}
|
| 20 |
|
| 21 |
demo = gr.Interface(fn=analyze,
|
| 22 |
inputs=gr.Textbox(lines=4, label="Metin"),
|
| 23 |
+
outputs="label", # Çıktıyı label olarak değiştirdim, daha iyi görünebilir.
|
| 24 |
+
title="Metin Duygu Analizi")
|
| 25 |
+
|
| 26 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|