Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,32 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
-
|
4 |
-
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
# Launch the
|
32 |
-
iface.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the model from Hugging Face Hub
|
5 |
+
model_repo = "Ahmed-El-Sharkawy/my-sentiment-model" # Replace with your actual repo name
|
6 |
+
nlp_pipeline = pipeline("text-classification", model=model_repo)
|
7 |
+
|
8 |
+
# Gradio app function
|
9 |
+
def classify_text(input_text):
|
10 |
+
if input_text.strip() == "":
|
11 |
+
return "Please enter some text."
|
12 |
+
result = nlp_pipeline(input_text)
|
13 |
+
label = result[0]['label']
|
14 |
+
score = result[0]['score']
|
15 |
+
|
16 |
+
# Map Hugging Face labels to readable format
|
17 |
+
label_map = {'LABEL_0': "Negative", 'LABEL_1': "Positive"}
|
18 |
+
mapped_label = label_map.get(label, label)
|
19 |
+
|
20 |
+
return f"Prediction: {mapped_label}, Confidence Score: {score:.4f}"
|
21 |
+
|
22 |
+
# Gradio interface
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=classify_text,
|
25 |
+
inputs="text",
|
26 |
+
outputs="text",
|
27 |
+
title="Text Classification App",
|
28 |
+
description="Classify text as Positive (1) or Negative (0)"
|
29 |
+
)
|
30 |
+
|
31 |
+
# Launch the app
|
32 |
+
iface.launch()
|