reddym10 commited on
Commit
50582e8
1 Parent(s): 24ac53c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -21
app.py CHANGED
@@ -1,31 +1,20 @@
1
  import gradio as gr
2
-
3
  from transformers import pipeline
4
 
5
-
6
 
7
  def classify(text):
8
-
9
- classifier = pipeline("zero-shot-classification")
10
-
11
  candidate_labels = ["positive", "negative", "neutral"]
12
-
13
  output = classifier(text, candidate_labels)
14
-
15
- return output
16
-
17
-
18
-
19
-
20
 
21
  demo = gr.Interface(fn=classify,
 
 
22
 
23
- inputs=gr.Textbox(label="Enter something"),
24
-
25
- outputs=gr.Label(num_top_classes=3))
26
-
27
-
28
-
29
-
30
-
31
- demo.launch()
 
1
  import gradio as gr
 
2
  from transformers import pipeline
3
 
4
+ classifier = pipeline("zero-shot-classification")
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()