Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from text_classifier import TextClassifier
|
| 3 |
+
|
| 4 |
+
classifier = TextClassifier()
|
| 5 |
+
|
| 6 |
+
def predict_sentiment(text):
|
| 7 |
+
result = classifier.predict(text)
|
| 8 |
+
return result['label'], result['confidence']
|
| 9 |
+
|
| 10 |
+
demo = gr.Interface(
|
| 11 |
+
fn=predict_sentiment,
|
| 12 |
+
inputs=gr.Textbox(label="Enter text for sentiment analysis", lines=3),
|
| 13 |
+
outputs=[
|
| 14 |
+
gr.Textbox(label="Sentiment"),
|
| 15 |
+
gr.Number(label="Confidence Score")
|
| 16 |
+
],
|
| 17 |
+
title="📝 Text Classification Model",
|
| 18 |
+
description="This model performs sentiment analysis using a pre-trained transformer model.",
|
| 19 |
+
examples=[
|
| 20 |
+
["I love this product! It's amazing."],
|
| 21 |
+
["This is terrible. I hate it."],
|
| 22 |
+
["It's okay, nothing special."]
|
| 23 |
+
]
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
demo.launch()
|