Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,37 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Load the classification pipeline
|
5 |
+
classifier = pipeline(
|
6 |
+
"sentiment-analysis",
|
7 |
+
model="Karzan/user_profile_skills_model",
|
8 |
+
return_all_scores=True,
|
9 |
+
top_k=10
|
10 |
+
)
|
11 |
+
|
12 |
+
# Define the prediction function
|
13 |
+
def classify_text(text):
|
14 |
+
# Perform classification
|
15 |
+
results = classifier(text)
|
16 |
+
# Format the output
|
17 |
+
formatted_results = [
|
18 |
+
{"label": item["label"], "score": round(item["score"], 4)}
|
19 |
+
for result in results for item in result
|
20 |
+
]
|
21 |
+
return formatted_results
|
22 |
+
|
23 |
+
# Create the Gradio interface
|
24 |
+
with gr.Blocks() as demo:
|
25 |
+
gr.Markdown("# Text Classification with Hugging Face Transformers")
|
26 |
+
gr.Markdown("Enter text to classify using the model: **Karzan/user_profile_skills_model**.")
|
27 |
+
with gr.Row():
|
28 |
+
with gr.Column():
|
29 |
+
input_text = gr.Textbox(label="Input Text", lines=3, placeholder="Type something...")
|
30 |
+
classify_button = gr.Button("Classify")
|
31 |
+
with gr.Column():
|
32 |
+
output_text = gr.JSON(label="Classification Results")
|
33 |
+
|
34 |
+
classify_button.click(classify_text, inputs=input_text, outputs=output_text)
|
35 |
+
|
36 |
+
# Launch the app
|
37 |
+
demo.launch()
|