Spaces:
No application file
No application file
Commit
·
5c7a09c
1
Parent(s):
dc5ecd1
sentimet.py
Browse filesimport gradio as gr
from transformers import pipeline
# Load pre-trained model from Hugging Face
classifier = pipeline('sentiment-analysis')
def classify_text(text):
result = classifier(text)[0]
label = result['label']
score = result['score']
return f"{label} (confidence: {score:.2f})"
# Create the Gradio interface
iface = gr.Interface(fn=classify_text, inputs=["text"], outputs=["prediction"])
# Launch the Gradio app
iface.launch()
- sentiment.py +17 -0
sentiment.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load pre-trained model from Hugging Face
|
| 5 |
+
classifier = pipeline('sentiment-analysis')
|
| 6 |
+
|
| 7 |
+
def classify_text(text):
|
| 8 |
+
result = classifier(text)[0]
|
| 9 |
+
label = result['label']
|
| 10 |
+
score = result['score']
|
| 11 |
+
return f"{label} (confidence: {score:.2f})"
|
| 12 |
+
|
| 13 |
+
# Create the Gradio interface
|
| 14 |
+
iface = gr.Interface(fn=classify_text, inputs=["text"], outputs=["prediction"])
|
| 15 |
+
|
| 16 |
+
# Launch the Gradio app
|
| 17 |
+
iface.launch()
|