Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,26 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Load pre-trained sentiment-analysis pipeline
|
5 |
+
classifier = pipeline('text-classification', model="wcyat/bert-suicide-detection-hk")
|
6 |
+
|
7 |
+
def classify_text(text):
|
8 |
+
# Get predictions
|
9 |
+
results = classifier(text)
|
10 |
+
# Extract and format the results
|
11 |
+
output = {result['label']: result['score'] for result in results}
|
12 |
+
return output
|
13 |
+
|
14 |
+
import gradio as gr
|
15 |
+
|
16 |
+
# Define Gradio interface
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=classify_text, # function to use for prediction
|
19 |
+
inputs="text", # input type
|
20 |
+
outputs="label", # output type
|
21 |
+
title="Text Classification with BERT",
|
22 |
+
description="Enter a sentence to classify whether it is suicidal."
|
23 |
+
)
|
24 |
+
|
25 |
+
# Launch the interface
|
26 |
+
iface.launch()
|