nadzo commited on
Commit
fb7320b
·
verified ·
1 Parent(s): 4be3c71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -4,12 +4,12 @@ from transformers import pipeline, AutoModelForSequenceClassification, AutoToken
4
  # Model name
5
  model_name = "ElKulako/cryptobert"
6
 
7
- # Load model and tokenizer explicitly to prevent errors
8
  try:
9
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
10
  tokenizer = AutoTokenizer.from_pretrained(model_name)
11
 
12
- # Load the pipeline
13
  sentiment_pipeline = pipeline(
14
  "text-classification",
15
  model=model,
@@ -25,10 +25,10 @@ def analyze(text):
25
  return {"error": "No text provided."}
26
 
27
  try:
28
- # Get the model's initial prediction
29
  result = sentiment_pipeline(text)[0]
30
 
31
- # Override logic for crypto-specific keywords (case-insensitive)
32
  text_lower = text.lower()
33
 
34
  # Force "positive" for bullish terms
@@ -52,11 +52,11 @@ gr.Interface(
52
  fn=analyze,
53
  inputs=gr.Textbox(placeholder="Enter crypto news headline..."),
54
  outputs=gr.JSON(),
55
- title="Crypto-Specific Sentiment Analysis",
56
- description="Analyzes sentiment of crypto news headlines. Overrides neutral predictions for key terms like 'ETF approved' or 'SEC lawsuit'.",
57
- allow_flagging="never"
58
  ).launch(
59
  server_name="0.0.0.0",
60
- server_port=7860,
61
- enable_queue=True # Ensures API requests are handled properly
62
  )
 
 
4
  # Model name
5
  model_name = "ElKulako/cryptobert"
6
 
7
+ # Load model and tokenizer explicitly
8
  try:
9
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
10
  tokenizer = AutoTokenizer.from_pretrained(model_name)
11
 
12
+ # Load sentiment pipeline
13
  sentiment_pipeline = pipeline(
14
  "text-classification",
15
  model=model,
 
25
  return {"error": "No text provided."}
26
 
27
  try:
28
+ # Get model's prediction
29
  result = sentiment_pipeline(text)[0]
30
 
31
+ # Override logic for crypto-related keywords (case-insensitive)
32
  text_lower = text.lower()
33
 
34
  # Force "positive" for bullish terms
 
52
  fn=analyze,
53
  inputs=gr.Textbox(placeholder="Enter crypto news headline..."),
54
  outputs=gr.JSON(),
55
+ title="Crypto Sentiment Analysis",
56
+ description="Analyzes sentiment of crypto-related news headlines.",
57
+ flagging_mode="never" # Fixed deprecated warning
58
  ).launch(
59
  server_name="0.0.0.0",
60
+ server_port=7860
 
61
  )
62
+