GoshawkVortexAI commited on
Commit
78e64c8
·
verified ·
1 Parent(s): 6aed91a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -11
app.py CHANGED
@@ -1,8 +1,9 @@
1
  import feedparser
2
  from transformers import pipeline
 
3
 
4
- # FinBERT modelini yükle (CPU kullanmak için device=-1)
5
- model = pipeline("sentiment-analysis", model="yiyanghkust/finbert-tone", device=-1)
6
 
7
  # Bitcoin haberleri için RSS feed URL'si
8
  rss_url = "https://news.google.com/rss/search?q=Bitcoin&hl=en-US&gl=US&ceid=US:en"
@@ -14,28 +15,39 @@ feed = feedparser.parse(rss_url)
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 (POSITIVE = +1, NEGATIVE = -1, NEUTRAL = 0)
22
  label = sentiment['label'].upper()
23
- score = sentiment['score'] # güven skorunu ağırlık olarak kullan
24
 
 
25
  if label == "POSITIVE":
26
- total_score += score # ağırlıklı pozitif
27
  elif label == "NEGATIVE":
28
- total_score -= score # ağırlıklı negatif
29
- else:
30
- total_score += 0 # nötr = 0
31
 
32
  count += 1
33
 
34
- # Ortalama skor hesapla
35
  average_score = total_score / count if count > 0 else 0
36
 
37
  # Long / Short / Neutral kararı
38
- threshold = 0.05 # küçük değişimleri nötr say
39
  if average_score > threshold:
40
  signal = "LONG 🟢"
41
  elif average_score < -threshold:
 
1
  import feedparser
2
  from transformers import pipeline
3
+ import re
4
 
5
+ # DistilBERT modelini yükle (CPU üzerinde)
6
+ model = pipeline("sentiment-analysis", model="distilbert-base-uncased", device=-1)
7
 
8
  # Bitcoin haberleri için RSS feed URL'si
9
  rss_url = "https://news.google.com/rss/search?q=Bitcoin&hl=en-US&gl=US&ceid=US:en"
 
15
  total_score = 0
16
  count = 0
17
 
18
+ # Ön işleme fonksiyonu
19
+ def preprocess_title(title):
20
+ # % -> percent, $ -> USD
21
+ title = title.replace("%", " percent").replace("$", " USD")
22
+ # Gereksiz sembolleri temizle
23
+ title = re.sub(r"[^a-zA-Z0-9\s]", "", title)
24
+ return title
25
+
26
+ # Her başlığı analiz et
27
  for entry in feed.entries:
28
+ raw_title = entry.title
29
+ title = preprocess_title(raw_title)
30
+
31
  sentiment = model(title)[0]
32
 
 
33
  label = sentiment['label'].upper()
34
+ score = sentiment['score'] # modelin güven skorunu kullan
35
 
36
+ # Ağırlıklı puanlama
37
  if label == "POSITIVE":
38
+ total_score += score
39
  elif label == "NEGATIVE":
40
+ total_score -= score
41
+ else: # NEUTRAL
42
+ total_score += 0
43
 
44
  count += 1
45
 
46
+ # Ortalama skor
47
  average_score = total_score / count if count > 0 else 0
48
 
49
  # Long / Short / Neutral kararı
50
+ threshold = 0.05 # küçük dalgalanmaları görmezden gel
51
  if average_score > threshold:
52
  signal = "LONG 🟢"
53
  elif average_score < -threshold: