Spaces:
Runtime error
Runtime error
HamidBekam
commited on
Commit
•
1d68b97
1
Parent(s):
23adb8f
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
3 |
+
|
4 |
+
# Load model and tokenizer
|
5 |
+
model_name = "nlptown/bert-base-multilingual-uncased-sentiment"
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Define pipeline for sentiment analysis
|
10 |
+
classifier = pipeline('text-classification', model=model, tokenizer=tokenizer)
|
11 |
+
|
12 |
+
# Define Gradio interface
|
13 |
+
def predict_sentiment(text):
|
14 |
+
result = classifier(text)[0]
|
15 |
+
label = result['label']
|
16 |
+
score = result['score']
|
17 |
+
return f"Prediction: {label} with confidence {score}"
|
18 |
+
|
19 |
+
iface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text",
|
20 |
+
title="Sentiment Analysis with Hugging Face and Gradio",
|
21 |
+
description="Enter text to get sentiment prediction.")
|
22 |
+
|
23 |
+
# Launch Gradio interface
|
24 |
+
iface.launch()
|