ryanheida commited on
Commit
f548fd8
·
1 Parent(s): db03ff0

Initialize

Browse files
Files changed (2) hide show
  1. app.py +37 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the Sentiment Analysis pipeline...
5
+ classifier = pipeline(
6
+ "sentiment-analysis",
7
+ model="distilbert-base-uncased-finetuned-sst-2-english"
8
+ )
9
+
10
+ # Define the prediction function...
11
+ def sentiment_predictor(text):
12
+ if not text:
13
+ return "Please enter some text.", 0.0
14
+
15
+ result = classifier(text)[0]
16
+ label = result['label']
17
+ score = result['score']
18
+
19
+ output_text = f"Predicted Sentiment: **{label}**"
20
+
21
+ return output_text, score
22
+
23
+ # Create the Gradio Interface
24
+ iface = gr.Interface(
25
+ fn=sentiment_predictor,
26
+ inputs=gr.Textbox(lines=5, placeholder="Type a sentence here...", label="Enter Text for Sentiment Analysis"),
27
+ outputs=[
28
+ gr.Markdown(label="Analysis Result"),
29
+ gr.Number(label="Confidence Score")
30
+ ],
31
+ title="🤗 Simple Sentiment Analyzer on Hugging Face Spaces",
32
+ description="A demonstration of deploying a DistilBERT-based model for sentiment classification using Gradio and Hugging Face Spaces. Type in any sentence and see the prediction!",
33
+ # The allow_flagging argument is now obsolete and removed.
34
+ )
35
+
36
+ # Launch the interface
37
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch