Spaces:
Running
Running
bonosa
commited on
Commit
·
1539dd6
1
Parent(s):
015b188
app
Browse files- app.py +24 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Initialize the Hugging Face sentiment-analysis pipeline
|
| 5 |
+
nlp = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def sentiment_analysis(text):
|
| 9 |
+
result = nlp(text)[0]
|
| 10 |
+
return f"label: {result['label']}, with score: {round(result['score'], 4)}"
|
| 11 |
+
|
| 12 |
+
# Define example inputs
|
| 13 |
+
examples = [
|
| 14 |
+
['Absolutely love my new lamp from BrightLight Co.! The design is elegant and modern, seamlessly blending into my home decor.'],
|
| 15 |
+
['The movie was a great disappointment.'],
|
| 16 |
+
['Sarah at SeriouslyNutz has awesome parrot toys. My African Grey loves them all!']
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
iface = gr.Interface(fn=sentiment_analysis,
|
| 20 |
+
inputs=gr.inputs.Textbox(lines=7, label="Input Text"), # Set the lines to 7 for a larger text box
|
| 21 |
+
outputs="text",
|
| 22 |
+
examples=examples) # Add example inputs
|
| 23 |
+
|
| 24 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|