Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
|
| 4 |
+
# Manually load tokenizer from base model
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
|
| 6 |
+
model = AutoModelForSequenceClassification.from_pretrained("King-8/interview_statements")
|
| 7 |
+
|
| 8 |
+
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
| 9 |
+
|
| 10 |
+
def classify_statement(statement):
|
| 11 |
+
prediction = classifier(statement)[0]
|
| 12 |
+
label = prediction["label"]
|
| 13 |
+
score = round(prediction["score"] * 100, 2)
|
| 14 |
+
return f"Category: {label} (Confidence: {score}%)"
|
| 15 |
+
|
| 16 |
+
gr.Interface(
|
| 17 |
+
fn=classify_statement,
|
| 18 |
+
inputs=gr.Textbox(label="Enter a community statement"),
|
| 19 |
+
outputs=gr.Textbox(label="Predicted Category"),
|
| 20 |
+
title="Interview Statement Categorizer",
|
| 21 |
+
description="This app predicts the category of a community statement based on trained data from community interviews."
|
| 22 |
+
).launch()
|