aysan98 commited on
Commit
8e2bc07
·
verified ·
1 Parent(s): bf6c190

Create validator.py

Browse files
Files changed (1) hide show
  1. validator.py +100 -0
validator.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def is_weak_answer(answer, min_words=5):
2
+ """
3
+ Check if answer is weak using simple rules
4
+ Returns: (is_weak, reason)
5
+ """
6
+ if not answer or not answer.strip():
7
+ return True, "empty"
8
+
9
+ answer_clean = answer.strip().lower()
10
+ words = answer_clean.split()
11
+
12
+ # خیلی کوتاه
13
+ if len(words) < min_words:
14
+ return True, "too_short"
15
+
16
+ # کلمات ممنوع
17
+ weak_phrases = [
18
+ "idk", "i don't know", "dont know", "نمیدونم", "نمی دونم",
19
+ "nice", "good", "ok", "okay", "fine", "خوب", "خوبه"
20
+ ]
21
+
22
+ if answer_clean in weak_phrases:
23
+ return True, "generic"
24
+
25
+ # تکرار یک کلمه
26
+ if len(set(words)) == 1:
27
+ return True, "repetitive"
28
+
29
+ return False, None
30
+
31
+
32
+ def generate_follow_up(original_question, attempt_number, section):
33
+ """
34
+ Generate follow-up question based on attempt number
35
+ attempt_number: 1 (first retry) or 2 (second retry)
36
+ """
37
+
38
+ if attempt_number == 1:
39
+ # تلاش 2: ساده‌تر + مثال
40
+ examples = {
41
+ "see": "For example: colors, designs, brands, prices, customer reviews?",
42
+ "say": "For example: comfort, durability, style, performance features?",
43
+ "do": "For example: running, gym workouts, casual wear, sports activities?",
44
+ "hear": "For example: from friends, social media, advertisements, athletes?",
45
+ "think & feel": "For example: confidence, performance improvement, status, comfort?"
46
+ }
47
+
48
+ example = examples.get(section, "For example: specific details about your experience?")
49
+
50
+ return f"Let me ask this in a simpler way: {original_question}\n\n{example}"
51
+
52
+ elif attempt_number == 2:
53
+ # تلاش 3: چندگزینه‌ای
54
+ choices = {
55
+ "see": [
56
+ "Brand names and logos",
57
+ "Price tags and discounts",
58
+ "Product reviews and ratings",
59
+ "Shoe design and colors",
60
+ "Other (please specify)"
61
+ ],
62
+ "say": [
63
+ "Comfort and fit",
64
+ "Durability and quality",
65
+ "Style and appearance",
66
+ "Performance features",
67
+ "Other (please specify)"
68
+ ],
69
+ "do": [
70
+ "Running or jogging",
71
+ "Gym and fitness training",
72
+ "Sports activities",
73
+ "Casual everyday wear",
74
+ "Other (please specify)"
75
+ ],
76
+ "hear": [
77
+ "Friends and family recommendations",
78
+ "Social media influencers",
79
+ "Professional athletes",
80
+ "Online reviews",
81
+ "Other (please specify)"
82
+ ],
83
+ "think & feel": [
84
+ "Improved performance",
85
+ "Increased confidence",
86
+ "Better comfort",
87
+ "Status and image",
88
+ "Other (please specify)"
89
+ ]
90
+ }
91
+
92
+ section_choices = choices.get(section, [
93
+ "Option 1", "Option 2", "Option 3", "Other"
94
+ ])
95
+
96
+ choices_text = "\n".join([f"{i+1}. {choice}" for i, choice in enumerate(section_choices)])
97
+
98
+ return f"To help us understand better, please choose one or more:\n\n{choices_text}\n\nYou can also add more details if you'd like!"
99
+
100
+ return original_question