akhaliq HF staff commited on
Commit
8b45d37
1 Parent(s): ffec905

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -1,11 +1,23 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- nlp = pipeline('text-generation')
5
 
6
- def generate_text(prompt):
7
- response = nlp(prompt, max_length=100, num_return_sequences=1)[0]
8
- return response['generated_text']
9
 
10
- iface = gr.Interface(generate_text, gr.inputs.Textbox(), gr.outputs.Textbox())
11
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ nlp = pipeline("text-classification")
5
 
6
+ def classify_text(input_text):
7
+ result = nlp(input_text)[0]
8
+ return result["label"], result["score"]
9
 
10
+ with gr.Blocks() as demo:
11
+ with gr.Row():
12
+ with gr.Column():
13
+ text_input = gr.Textbox(label="Enter text to classify")
14
+ classify_btn = gr.Button(value="Classify")
15
+ with gr.Column():
16
+ label_output = gr.Textbox(label="Predicted label")
17
+ score_output = gr.Textbox(label="Score")
18
+
19
+ classify_btn.click(classify_text, inputs=text_input, outputs=[label_output, score_output], api_name="classify-text")
20
+ examples = gr.Examples(examples=["This is a positive review.", "This is a negative review."],
21
+ inputs=[text_input])
22
+
23
+ demo.launch()