File size: 1,131 Bytes
f595f0b
 
639d13b
 
 
 
f595f0b
 
 
 
 
 
 
639d13b
 
 
f595f0b
 
 
 
 
 
639d13b
 
 
 
 
 
 
 
 
 
 
 
 
f595f0b
 
 
 
 
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
40
41
import gradio as gr
from huggingface_hub import InferenceClient
from transformers import pipeline

# Sentiment pipeline
sentiment = pipeline("text-classification", model="tabularisai/multilingual-sentiment-analysis")

"""
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
"""
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")


def get_sentiment(text):
  output = sentiment(text)
  return f'The sentence was classified as "{output[0]["label"]}" with {output[0]["score"]*100}% confidence'



"""
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
"""

title = "Get a sentiment on you text"
description = """
The bot was takes your text and classify it as either 'Positive' or 'Negative'
"""

demo = gr.Interface(
    fn=get_sentiment,
    inputs="text",
    outputs="text",
    title=title,
    description=description,
    examples=[["I really enjoyed my stay !"], ["Worst rental I ever got"]],
)


if __name__ == "__main__":
    demo.launch()