Karzan commited on
Commit
b706990
1 Parent(s): 4ee1f87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -10,30 +10,30 @@ classifier = pipeline(
10
  )
11
 
12
  # Define the prediction function
13
- def classify_text_with_bars(text):
14
  # Perform classification
15
  results = classifier(text)
16
- # Prepare data for bar chart
17
- labels = []
18
- scores = []
19
- for result in results:
20
- for item in result:
21
- labels.append(item["label"])
22
- scores.append(item["score"])
23
- return {label: score for label, score in zip(labels, scores)}
24
 
25
  # Create the Gradio interface
26
  with gr.Blocks() as demo:
27
- gr.Markdown("# Text Classification with Bar Chart Output")
28
- gr.Markdown("Enter text to classify, and view predictions with their scores in a bar chart.")
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_chart = gr.Label(label="Classification Results (Bar Chart)", type="plot")
35
 
36
- classify_button.click(classify_text_with_bars, inputs=input_text, outputs=output_chart)
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()