pradanaadn commited on
Commit
71dafc2
·
verified ·
1 Parent(s): ffcfdd3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -1,16 +1,26 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- classifier = pipeline("sentiment-analysis", model="Tirendaz/my_distilbert_model")
5
 
6
  def text_classification(text):
 
 
 
 
 
 
 
 
 
 
7
  result= classifier(text)
8
- sentiment_label = result[0]['label']
9
  sentiment_score = result[0]['score']
10
  formatted_output = f"This sentiment is {sentiment_label} with the probability {sentiment_score*100:.2f}%"
11
  return formatted_output
12
 
13
- examples=["This is wonderful movie!", "The movie was really bad; I didn't like it."]
14
 
15
  io = gr.Interface(fn=text_classification,
16
  inputs= gr.Textbox(lines=2, label="Text", placeholder="Enter title here..."),
@@ -18,5 +28,5 @@ io = gr.Interface(fn=text_classification,
18
  title="Text Classification",
19
  description="Enter a text and see the text classification result!",
20
  examples=examples)
21
- print('test')
22
  io.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ classifier = pipeline("sentiment-analysis", model="pradanaadn/sucidal-text-classification-distillbert")
5
 
6
  def text_classification(text):
7
+ label_mapping = {
8
+ 'LABEL_0': 'Anxiety',
9
+ 'LABEL_1': 'Bipolar',
10
+ 'LABEL_2': 'Depression',
11
+ 'LABEL_3': 'Normal',
12
+ 'LABEL_4': 'Personality disorder',
13
+ 'LABEL_5': 'Stress',
14
+ 'LABEL_6': 'Suicidal',
15
+
16
+ }
17
  result= classifier(text)
18
+ sentiment_label = label_mapping[result[0]['label']]
19
  sentiment_score = result[0]['score']
20
  formatted_output = f"This sentiment is {sentiment_label} with the probability {sentiment_score*100:.2f}%"
21
  return formatted_output
22
 
23
+ examples=["It's been a rollercoaster lately. One moment I'm on top of the world, full of energy, and the next, I'm down in the dumps, feeling hopeless", "I've noticed that my reactions and feelings often don't match what others expect. It creates tension in my relationships, and sometimes I feel like I'm not in control of myself."]
24
 
25
  io = gr.Interface(fn=text_classification,
26
  inputs= gr.Textbox(lines=2, label="Text", placeholder="Enter title here..."),
 
28
  title="Text Classification",
29
  description="Enter a text and see the text classification result!",
30
  examples=examples)
31
+
32
  io.launch()