kingslin commited on
Commit
a26e419
·
verified ·
1 Parent(s): 1ed276b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -1,15 +1,20 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
5
 
 
6
  def predict(text):
7
  result = classifier(text)[0]
8
  return result["label"], round(result["score"], 3)
9
 
 
10
  app = gr.Interface(
11
  fn=predict,
12
  inputs=gr.Textbox(label="Enter text"),
13
  outputs=[gr.Text(label="Sentiment"), gr.Number(label="Confidence Score")]
14
  )
15
 
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load sentiment analysis pipeline
5
  classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
6
 
7
+ # Define prediction function
8
  def predict(text):
9
  result = classifier(text)[0]
10
  return result["label"], round(result["score"], 3)
11
 
12
+ # Create Gradio interface
13
  app = gr.Interface(
14
  fn=predict,
15
  inputs=gr.Textbox(label="Enter text"),
16
  outputs=[gr.Text(label="Sentiment"), gr.Number(label="Confidence Score")]
17
  )
18
 
19
+ # 🚀 This is required in Spaces
20
+ app.launch()