YosefAyele commited on
Commit
d38e058
Β·
1 Parent(s): 6934d2a

add the gradion interface

Browse files
Files changed (3) hide show
  1. README.md +29 -1
  2. app.py +111 -0
  3. requirements.txt +5 -0
README.md CHANGED
@@ -10,4 +10,32 @@ pinned: false
10
  license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  license: mit
11
  ---
12
 
13
+ # Ad Comments Intent Classifier
14
+
15
+ This Space provides an interface for classifying the intent of comments related to advertisements using the `YosefA/adfluence-intent-model`.
16
+
17
+ ## Features
18
+
19
+ - 🎯 **Intent Classification**: Analyze comment text to determine the underlying intent
20
+ - πŸ“Š **Confidence Scores**: Get probability scores for each predicted label
21
+ - πŸ’‘ **Easy to Use**: Simple interface with example comments provided
22
+ - ⚑ **Fast Inference**: Optimized for quick classification results
23
+
24
+ ## How to Use
25
+
26
+ 1. Enter your comment text in the input box
27
+ 2. Click "πŸ” Classify Intent" or press Enter
28
+ 3. View the classification results with confidence scores
29
+
30
+ ## Model Information
31
+
32
+ This app uses the `YosefA/adfluence-intent-model` from Hugging Face, which is trained to classify the intent of comments in advertising contexts.
33
+
34
+ ## Examples
35
+
36
+ Try these example comments to see how the classifier works:
37
+ - "This product looks amazing! Where can I buy it?"
38
+ - "This is clearly a scam, don't trust it."
39
+ - "I love this brand, they make quality products."
40
+ - "The price seems too high for what you get."
41
+ - "Has anyone tried this? I'm curious about reviews."
app.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import torch
4
+
5
+ # Load the model from Hugging Face
6
+ @gr.cache
7
+ def load_model():
8
+ """Load the intent classification model"""
9
+ try:
10
+ classifier = pipeline(
11
+ "text-classification",
12
+ model="YosefA/adfluence-intent-model",
13
+ return_all_scores=True
14
+ )
15
+ return classifier
16
+ except Exception as e:
17
+ print(f"Error loading model: {e}")
18
+ return None
19
+
20
+ def classify_intent(comment):
21
+ """
22
+ Classify the intent of a comment
23
+
24
+ Args:
25
+ comment (str): The input comment text
26
+
27
+ Returns:
28
+ dict: Classification results with labels and scores
29
+ """
30
+ if not comment.strip():
31
+ return "Please enter a comment to classify."
32
+
33
+ classifier = load_model()
34
+ if classifier is None:
35
+ return "Error: Could not load the model. Please try again later."
36
+
37
+ try:
38
+ # Get predictions
39
+ results = classifier(comment)
40
+
41
+ # Format results for display
42
+ formatted_results = []
43
+ for result in results:
44
+ for item in result:
45
+ label = item['label']
46
+ score = item['score']
47
+ formatted_results.append(f"{label}: {score:.4f} ({score*100:.2f}%)")
48
+
49
+ return "\n".join(formatted_results)
50
+
51
+ except Exception as e:
52
+ return f"Error during classification: {str(e)}"
53
+
54
+ # Create the Gradio interface
55
+ with gr.Blocks(title="Ad Comments Intent Classifier") as demo:
56
+ gr.Markdown("""
57
+ # 🎯 Ad Comments Intent Classifier
58
+
59
+ This app classifies the intent of comments related to advertisements using the **YosefA/adfluence-intent-model**.
60
+
61
+ Simply enter a comment below and get the classification results with confidence scores.
62
+ """)
63
+
64
+ with gr.Row():
65
+ with gr.Column():
66
+ comment_input = gr.Textbox(
67
+ label="Comment Text",
68
+ placeholder="Enter your comment here...",
69
+ lines=3,
70
+ max_lines=10
71
+ )
72
+
73
+ classify_btn = gr.Button("πŸ” Classify Intent", variant="primary")
74
+
75
+ with gr.Column():
76
+ output = gr.Textbox(
77
+ label="Classification Results",
78
+ lines=5,
79
+ max_lines=10,
80
+ interactive=False
81
+ )
82
+
83
+ # Example inputs
84
+ gr.Examples(
85
+ examples=[
86
+ ["This product looks amazing! Where can I buy it?"],
87
+ ["This is clearly a scam, don't trust it."],
88
+ ["I love this brand, they make quality products."],
89
+ ["The price seems too high for what you get."],
90
+ ["Has anyone tried this? I'm curious about reviews."]
91
+ ],
92
+ inputs=comment_input,
93
+ label="πŸ“ Example Comments"
94
+ )
95
+
96
+ # Set up the event handlers
97
+ classify_btn.click(
98
+ fn=classify_intent,
99
+ inputs=comment_input,
100
+ outputs=output
101
+ )
102
+
103
+ comment_input.submit(
104
+ fn=classify_intent,
105
+ inputs=comment_input,
106
+ outputs=output
107
+ )
108
+
109
+ # Launch the app
110
+ if __name__ == "__main__":
111
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio==4.44.0
2
+ transformers==4.36.0
3
+ torch==2.1.0
4
+ tokenizers==0.15.0
5
+ huggingface_hub==0.19.4