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