Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Load sentiment analysis pipeline
|
| 5 |
+
# classifier_pipeline = pipeline("text-classification", model="tabularisai/multilingual-sentiment-analysis")
|
| 6 |
+
classifier_pipeline = ("sentiment-analysis")
|
| 7 |
+
|
| 8 |
+
# Define classification function
|
| 9 |
+
def classify_text(text):
|
| 10 |
+
output = classifier_pipeline(text)
|
| 11 |
+
return output[0] # Extract the first result from the list
|
| 12 |
+
|
| 13 |
+
# Define Gradio interface
|
| 14 |
+
interface = gr.Interface(
|
| 15 |
+
fn=classify_text,
|
| 16 |
+
inputs=gr.Textbox(label="Enter sentence here"),
|
| 17 |
+
outputs=gr.Label(),
|
| 18 |
+
examples=["I am hungry", "I love this product!", "This is the worst experience ever."]
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Launch the interface
|
| 22 |
+
interface.launch()
|