skylord commited on
Commit
033d543
1 Parent(s): 99aedab

aded distilbert interface

Browse files
Files changed (1) hide show
  1. app.py +22 -7
app.py CHANGED
@@ -1,11 +1,26 @@
1
  import gradio as gr
2
- from setfit import SetFitModel
3
 
4
- def greet(text):
5
- model = SetFitModel.from_pretrained("skylord/setfit-bge-small-v1.5-sst2-8-shot-talk2loop") # Load from the Hugging Face Hub
6
- preds = model.predict([text])
7
 
8
- return "Tag: " + preds
 
 
 
 
 
 
 
 
 
9
 
10
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
11
- iface.launch()
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Load the sentiment analysis pipeline with DistilBERT
5
+ distilbert_pipeline = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
 
6
 
7
+ def predict_sentiment(text):
8
+ """
9
+ Predicts the sentiment of the input text using DistilBERT.
10
+ :param text: str, input text to analyze.
11
+ :return: str, predicted sentiment and confidence score.
12
+ """
13
+ result = distilbert_pipeline(text)[0]
14
+ label = result['label']
15
+ score = result['score']
16
+ return f"Sentiment: {label}, Confidence: {score:.2f}"
17
 
18
+ # Create a Gradio interface
19
+ iface = gr.Interface(fn=predict_sentiment,
20
+ inputs=gr.inputs.Textbox(lines=2, placeholder="Type your text here..."),
21
+ outputs="text",
22
+ title="Sentiment Analysis with DistilBERT",
23
+ description="This model predicts the sentiment of the input text. Enter a sentence to see if it's positive or negative.")
24
+
25
+ # Launch the interface
26
+ iface.launch()