hasanmustafa0503 commited on
Commit
51dbb8f
·
verified ·
1 Parent(s): 061be41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -1,12 +1,28 @@
 
1
  from transformers import pipeline
2
 
 
3
  sentiment_pipeline = pipeline(
4
  "text-classification",
5
  model="hasanmustafa0503/SentimentModel",
6
  tokenizer="hasanmustafa0503/SentimentModel"
7
  )
8
 
9
- text = "I absolutely love this new feature! Great job 👍"
10
- result = sentiment_pipeline(text)
11
- print(result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
 
1
+ import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Initialize the sentiment analysis pipeline
5
  sentiment_pipeline = pipeline(
6
  "text-classification",
7
  model="hasanmustafa0503/SentimentModel",
8
  tokenizer="hasanmustafa0503/SentimentModel"
9
  )
10
 
11
+ # Function to classify sentiment of text
12
+ def classify_sentiment(text):
13
+ result = sentiment_pipeline(text)
14
+ return result[0]['label'], result[0]['score']
15
+
16
+ # Define Gradio interface
17
+ iface = gr.Interface(
18
+ fn=classify_sentiment, # Function to call
19
+ inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), # Text input box
20
+ outputs=[gr.Label(), gr.Number()], # Label for sentiment and score
21
+ title="Sentiment Analysis", # Title for the app
22
+ description="Enter some text, and this tool will predict the sentiment as POSITIVE or NEGATIVE along with the confidence score.", # Description
23
+ )
24
+
25
+ # Launch the app
26
+ iface.launch()
27
+
28