Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import feedparser
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# DistilBERT modelini yükle
|
| 5 |
model = pipeline("sentiment-analysis", model="distilbert-base-uncased", device=-1)
|
| 6 |
|
| 7 |
# Bitcoin haberleri için RSS feed URL'si
|
|
@@ -10,13 +10,39 @@ rss_url = "https://news.google.com/rss/search?q=Bitcoin&hl=en-US&gl=US&ceid=US:e
|
|
| 10 |
# RSS feed'i al
|
| 11 |
feed = feedparser.parse(rss_url)
|
| 12 |
|
| 13 |
-
#
|
|
|
|
|
|
|
|
|
|
| 14 |
for entry in feed.entries:
|
| 15 |
-
title = entry.title
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import feedparser
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# DistilBERT modelini yükle (CPU üzerinde)
|
| 5 |
model = pipeline("sentiment-analysis", model="distilbert-base-uncased", device=-1)
|
| 6 |
|
| 7 |
# Bitcoin haberleri için RSS feed URL'si
|
|
|
|
| 10 |
# RSS feed'i al
|
| 11 |
feed = feedparser.parse(rss_url)
|
| 12 |
|
| 13 |
+
# Toplam skor ve haber sayısı
|
| 14 |
+
total_score = 0
|
| 15 |
+
count = 0
|
| 16 |
+
|
| 17 |
for entry in feed.entries:
|
| 18 |
+
title = entry.title
|
| 19 |
+
sentiment = model(title)[0]
|
| 20 |
+
|
| 21 |
+
# Etiketi puana çevir
|
| 22 |
+
label = sentiment['label'].upper()
|
| 23 |
+
if label == "POSITIVE":
|
| 24 |
+
score = 1
|
| 25 |
+
elif label == "NEGATIVE":
|
| 26 |
+
score = -1
|
| 27 |
+
else:
|
| 28 |
+
score = 0
|
| 29 |
+
|
| 30 |
+
total_score += score
|
| 31 |
+
count += 1
|
| 32 |
+
|
| 33 |
+
# Ortalama skor hesapla
|
| 34 |
+
average_score = total_score / count if count > 0 else 0
|
| 35 |
+
|
| 36 |
+
# Long / Short / Neutral kararı
|
| 37 |
+
threshold = 0.1
|
| 38 |
+
if average_score > threshold:
|
| 39 |
+
signal = "LONG 🟢"
|
| 40 |
+
elif average_score < -threshold:
|
| 41 |
+
signal = "SHORT 🔴"
|
| 42 |
+
else:
|
| 43 |
+
signal = "NEUTRAL ⚪️"
|
| 44 |
+
|
| 45 |
+
# Sonuçları yazdır
|
| 46 |
+
print(f"Toplam Başlık Sayısı: {count}")
|
| 47 |
+
print(f"Ortalama Duygu Skoru: {average_score:.2f}")
|
| 48 |
+
print(f"Tahmini Piyasa Sinyali: {signal}")
|