Spaces:
Runtime error
Runtime error
DarwinAnim8or
commited on
Commit
•
318e432
1
Parent(s):
1ca0df8
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,25 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import TextClassificationPipeline, AutoTokenizer, AutoModelForSequenceClassification
|
3 |
|
4 |
+
# Load a pre-trained text classification model
|
5 |
+
model_name = "KoalaAI/Text-Moderation"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Create a TextClassificationPipeline
|
10 |
+
pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer)
|
11 |
+
|
12 |
+
# Define the classify_text function using the pipeline
|
13 |
+
def classify_text(text):
|
14 |
+
prediction = pipe(text)[0]["label"]
|
15 |
+
return prediction
|
16 |
+
|
17 |
+
# Create a Gradio interface
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=classify_text,
|
20 |
+
inputs=gr.inputs.Textbox(label="Enter text"),
|
21 |
+
outputs=gr.outputs.Label(label="Predicted classes"),
|
22 |
+
)
|
23 |
+
|
24 |
+
# Launch the Gradio app
|
25 |
+
iface.launch()
|