nadzo commited on
Commit
a17197d
·
verified ·
1 Parent(s): ae79a16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  sentiment_pipeline = pipeline(
5
  "sentiment-analysis",
6
  model="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis"
@@ -8,17 +9,16 @@ sentiment_pipeline = pipeline(
8
 
9
  def analyze(text):
10
  result = sentiment_pipeline(text)[0]
11
- return f"{result['label']} (Confidence: {result['score']:.2f})"
12
 
13
- # Explicitly define the Gradio interface with API support
14
  gr.Interface(
15
  fn=analyze,
16
- inputs="text",
17
- outputs="text",
18
  title="Crypto News Sentiment Analysis",
19
- allow_flagging="never"
20
  ).launch(
21
  server_name="0.0.0.0",
22
- server_port=7860,
23
- share=True # Generates a public URL
24
  )
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the financial sentiment model
5
  sentiment_pipeline = pipeline(
6
  "sentiment-analysis",
7
  model="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis"
 
9
 
10
  def analyze(text):
11
  result = sentiment_pipeline(text)[0]
12
+ return {"label": result["label"], "score": result["score"]} # Return JSON-serializable output
13
 
14
+ # Configure Gradio with API support
15
  gr.Interface(
16
  fn=analyze,
17
+ inputs=gr.Textbox(placeholder="Enter crypto news headline..."),
18
+ outputs=gr.Label(),
19
  title="Crypto News Sentiment Analysis",
20
+ flagging_mode="never" # Fixes deprecated `allow_flagging` warning
21
  ).launch(
22
  server_name="0.0.0.0",
23
+ server_port=7860
 
24
  )