Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,30 +10,30 @@ classifier = pipeline(
|
|
10 |
)
|
11 |
|
12 |
# Define the prediction function
|
13 |
-
def
|
14 |
# Perform classification
|
15 |
results = classifier(text)
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
# Create the Gradio interface
|
26 |
with gr.Blocks() as demo:
|
27 |
-
gr.Markdown("# Text Classification with
|
28 |
-
gr.Markdown("Enter text to classify
|
29 |
with gr.Row():
|
30 |
with gr.Column():
|
31 |
input_text = gr.Textbox(label="Input Text", lines=3, placeholder="Type something...")
|
32 |
classify_button = gr.Button("Classify")
|
33 |
with gr.Column():
|
34 |
-
|
35 |
|
36 |
-
classify_button.click(
|
37 |
|
38 |
# Launch the app
|
39 |
demo.launch()
|
|
|
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 |
+
|
24 |
|
25 |
# Create the Gradio interface
|
26 |
with gr.Blocks() as demo:
|
27 |
+
gr.Markdown("# Text Classification with Hugging Face Transformers")
|
28 |
+
gr.Markdown("Enter text to classify using the model: **Karzan/user_profile_skills_model**.")
|
29 |
with gr.Row():
|
30 |
with gr.Column():
|
31 |
input_text = gr.Textbox(label="Input Text", lines=3, placeholder="Type something...")
|
32 |
classify_button = gr.Button("Classify")
|
33 |
with gr.Column():
|
34 |
+
output_text = gr.JSON(label="Classification Results")
|
35 |
|
36 |
+
classify_button.click(classify_text, inputs=input_text, outputs=output_text)
|
37 |
|
38 |
# Launch the app
|
39 |
demo.launch()
|