nadzo commited on
Commit
f5e51d8
·
verified ·
1 Parent(s): 27cda04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -1,22 +1,40 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load the crypto-specific sentiment model
5
  sentiment_pipeline = pipeline(
6
  "text-classification",
7
- model="ElKulako/cryptobert", # Crypto-optimized model
8
  tokenizer="ElKulako/cryptobert"
9
  )
10
 
11
  def analyze(text):
 
12
  result = sentiment_pipeline(text)[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  return {"label": result["label"], "score": result["score"]}
14
 
 
15
  gr.Interface(
16
  fn=analyze,
17
  inputs=gr.Textbox(placeholder="Enter crypto news headline..."),
18
- outputs=gr.JSON(),
19
  title="Crypto-Specific Sentiment Analysis",
 
20
  flagging_mode="never"
21
  ).launch(
22
  server_name="0.0.0.0",
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load a crypto-specific sentiment model (e.g., ElKulako/cryptobert)
5
  sentiment_pipeline = pipeline(
6
  "text-classification",
7
+ model="ElKulako/cryptobert", # Pre-trained on crypto data
8
  tokenizer="ElKulako/cryptobert"
9
  )
10
 
11
  def analyze(text):
12
+ # Get the model's initial prediction
13
  result = sentiment_pipeline(text)[0]
14
+
15
+ # Override logic for crypto-specific keywords (case-insensitive)
16
+ text_lower = text.lower()
17
+
18
+ # Force "positive" for bullish terms
19
+ bullish_keywords = ["etf approved", "bullish", "halving", "burn", "greenlighted"]
20
+ if any(keyword in text_lower for keyword in bullish_keywords):
21
+ return {"label": "positive", "score": 0.99}
22
+
23
+ # Force "negative" for bearish terms
24
+ bearish_keywords = ["sec lawsuit", "hack", "fud", "sell-off", "delist"]
25
+ if any(keyword in text_lower for keyword in bearish_keywords):
26
+ return {"label": "negative", "score": 0.99}
27
+
28
+ # Return original prediction if no keywords matched
29
  return {"label": result["label"], "score": result["score"]}
30
 
31
+ # Configure Gradio interface for API compatibility
32
  gr.Interface(
33
  fn=analyze,
34
  inputs=gr.Textbox(placeholder="Enter crypto news headline..."),
35
+ outputs=gr.JSON(), # JSON output for n8n integration
36
  title="Crypto-Specific Sentiment Analysis",
37
+ description="Analyzes sentiment of crypto news headlines. Overrides neutral predictions for key terms like 'ETF approved' or 'SEC lawsuit'.",
38
  flagging_mode="never"
39
  ).launch(
40
  server_name="0.0.0.0",