CesarLeblanc commited on
Commit
7e0319c
1 Parent(s): f24a452

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -1,22 +1,25 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
3
 
4
  classifier = pipeline("text-classification", model="CesarLeblanc/test_model")
 
5
 
6
  def text_classification(text):
7
  result = classifier(text)
8
  habitat_label = result[0]['label']
 
9
  habitat_score = result[0]['score']
10
- formatted_output = f"This sentiment is {habitat_label} with the probability {habitat_score*100:.2f}%"
11
  return formatted_output
12
 
13
- examples=["Vegetation Plot 1", "Vegetation Plot 2"]
14
 
15
  io = gr.Interface(fn=text_classification,
16
- inputs= gr.Textbox(lines=2, label="Text", placeholder="Enter title here..."),
17
  outputs=gr.Textbox(lines=2, label="Text Classification Result"),
18
- title="Text Classification",
19
- description="Enter a text and see the text classification result!",
20
  examples=examples)
21
 
22
- io.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ from datasets import load_dataset
4
 
5
  classifier = pipeline("text-classification", model="CesarLeblanc/test_model")
6
+ dataset = load_dataset("CesarLeblanc/text_classification_dataset")
7
 
8
  def text_classification(text):
9
  result = classifier(text)
10
  habitat_label = result[0]['label']
11
+ habitat_label = dataset['train'].features['label'].names[int(habitat_label.split('_')[1])]
12
  habitat_score = result[0]['score']
13
+ formatted_output = f"This vegetation plot is {habitat_label} with the probability {habitat_score*100:.2f}%"
14
  return formatted_output
15
 
16
+ examples=["quercus robur, betula pendula, holcus lanatus, lonicera periclymenum, carex arenaria, poa trivialis", "thinopyrum junceum, cakile maritima"]
17
 
18
  io = gr.Interface(fn=text_classification,
19
+ inputs= gr.Textbox(lines=2, label="Text", placeholder="Enter species here..."),
20
  outputs=gr.Textbox(lines=2, label="Text Classification Result"),
21
+ title="Vegetation Plot Classification",
22
+ description="Enter the species and see the vegetation plot classification result!",
23
  examples=examples)
24
 
25
+ io.launch()