File size: 1,119 Bytes
cfab31c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd89b0b
1ad05aa
cfab31c
 
 
 
 
bd89b0b
 
cfab31c
 
 
 
 
 
 
 
 
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
import torch
import transformers

from transformers import pipeline


classifier = pipeline(task='sentiment-analysis', model='nlptown/bert-base-multilingual-uncased-sentiment')

examples = [
            ["This is a Nice presentation "],
            ["This experience is not as much as i expected "],
            ["I love this product! It's amazing!"],
            ["I am very disappointed with the service."]
           ]


import gradio as gr

def analyze_sentiment(text):
    result = pipeline(text)[0]
    label = result["label"]
    score = result["score"].range(1,6)
    return f"Sentiment: {label}\nConfidence: {score}"

# Create the Gradio interface
iface = gr.Interface(
      fn=analyze_sentiment,
      inputs=gr.Textbox(placeholder="Enter text to analyze..."),
      outputs=[gr.Textbox(label="Sentiment"),
               gr.Number(label="Confidence"),
              ], 
      title="Sentiment Analysis App",
      description="Enter a sentence to determine its sentiment (positive or negative).",
      examples=examples 
                    )

# Launch the app
if __name__ == "__main__":
    iface.launch()