Spaces:
Runtime error
Runtime error
AbdelrahmanZeidan
commited on
Commit
•
e990086
1
Parent(s):
80cd728
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,20 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
classifier = pipeline(task="zero-shot-classification", model = "MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli")
|
|
|
5 |
|
6 |
+
def classify(text):
|
7 |
+
candidate_labels = ["positive", "negative", "neutral"]
|
8 |
+
output = classifier(text, candidate_labels)
|
9 |
+
# Process the output to match Gradio's expected input format for gr.Label
|
10 |
+
labels = output['labels']
|
11 |
+
scores = output['scores']
|
12 |
+
# Construct a simple string representation of top classifications
|
13 |
+
top_classes = ', '.join([f"{labels[i]}: {scores[i]:.2f}" for i in range(len(labels))])
|
14 |
+
return top_classes
|
15 |
+
|
16 |
+
demo = gr.Interface(fn=classify,
|
17 |
+
inputs=gr.Textbox(label="Enter something"),
|
18 |
+
outputs=gr.Label())
|
19 |
+
|
20 |
+
demo.launch()
|