Luca Latini
commited on
Commit
·
81f7e58
1
Parent(s):
0b5661c
replace with create enrollment rule
Browse files- app.py +128 -150
- requirements.txt +1 -6
app.py
CHANGED
@@ -1,154 +1,132 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
import random
|
4 |
|
5 |
-
|
6 |
-
from
|
7 |
-
import
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
"
|
57 |
-
"
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
#
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
)
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
)
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
maximum=MAX_IMAGE_SIZE,
|
115 |
-
step=32,
|
116 |
-
value=1024, # Replace with defaults that work for your model
|
117 |
-
)
|
118 |
-
|
119 |
-
with gr.Row():
|
120 |
-
guidance_scale = gr.Slider(
|
121 |
-
label="Guidance scale",
|
122 |
-
minimum=0.0,
|
123 |
-
maximum=10.0,
|
124 |
-
step=0.1,
|
125 |
-
value=0.0, # Replace with defaults that work for your model
|
126 |
-
)
|
127 |
-
|
128 |
-
num_inference_steps = gr.Slider(
|
129 |
-
label="Number of inference steps",
|
130 |
-
minimum=1,
|
131 |
-
maximum=50,
|
132 |
-
step=1,
|
133 |
-
value=2, # Replace with defaults that work for your model
|
134 |
-
)
|
135 |
-
|
136 |
-
gr.Examples(examples=examples, inputs=[prompt])
|
137 |
-
gr.on(
|
138 |
-
triggers=[run_button.click, prompt.submit],
|
139 |
-
fn=infer,
|
140 |
-
inputs=[
|
141 |
-
prompt,
|
142 |
-
negative_prompt,
|
143 |
-
seed,
|
144 |
-
randomize_seed,
|
145 |
-
width,
|
146 |
-
height,
|
147 |
-
guidance_scale,
|
148 |
-
num_inference_steps,
|
149 |
-
],
|
150 |
-
outputs=[result, seed],
|
151 |
)
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import pydantic
|
3 |
import random
|
4 |
|
5 |
+
from pydantic import Field, field_validator, BaseModel
|
6 |
+
from enum import Enum
|
7 |
+
from typing import List
|
8 |
+
|
9 |
+
class Group(str, Enum):
|
10 |
+
onboarding = "onboarding"
|
11 |
+
sales_enablement = "sales enablement"
|
12 |
+
marketing = "marketing"
|
13 |
+
leadership = "leadership"
|
14 |
+
|
15 |
+
GROUPS = ["onboarding", "sales enablement", "marketing", "leadership"]
|
16 |
+
|
17 |
+
class Course(str, Enum):
|
18 |
+
company_culture_and_values = "company culture and values"
|
19 |
+
product_knowledge_and_features = "product knowledge and features"
|
20 |
+
sales_process_and_methodology = "sales process and methodology"
|
21 |
+
customer_relationship_management_system_training = "customer relationship management system training"
|
22 |
+
sales_enablement_strategy_and_planning = "sales enablement strategy and planning"
|
23 |
+
content_creation_and_curation = "content creation and curation"
|
24 |
+
sales_coaching_and_mentoring = "sales coaching and mentoring"
|
25 |
+
sales_metrics_and_analytics = "sales metrics and analytics"
|
26 |
+
digital_marketing_fundamentals = "digital marketing fundamentals"
|
27 |
+
content_marketing_strategy = "content marketing strategy"
|
28 |
+
social_media_marketing = "social media marketing"
|
29 |
+
search_engine_optimization = "search engine optimization"
|
30 |
+
leadership_development_and_coaching = "leadership development and coaching"
|
31 |
+
strategic_planning_and_decision_making = "strategic planning and decision making"
|
32 |
+
change_management_and_organizational_development = "change management and organizational development"
|
33 |
+
emotional_intelligence_and_communication_skills = "emotional intelligence and communication skills"
|
34 |
+
|
35 |
+
COURSES = ["company culture and values",
|
36 |
+
"product knowledge and features",
|
37 |
+
"sales process and methodology",
|
38 |
+
"customer relationship management system training",
|
39 |
+
"sales enablement strategy and planning",
|
40 |
+
"content creation and curation",
|
41 |
+
"sales coaching and mentoring",
|
42 |
+
"sales metrics and analytics",
|
43 |
+
"digital marketing fundamentals",
|
44 |
+
"content marketing strategy",
|
45 |
+
"social media marketing",
|
46 |
+
"search engine optimization",
|
47 |
+
"leadership development and coaching",
|
48 |
+
"strategic planning and decision making",
|
49 |
+
"change management and organizational development",
|
50 |
+
"emotional intelligence and communication skills"
|
51 |
+
]
|
52 |
+
|
53 |
+
class EnrollmentRule(BaseModel):
|
54 |
+
rule_code: str = Field(description="unique identifier code for the rule", default="")
|
55 |
+
rule_name: str = Field(description="name of the rule", default="")
|
56 |
+
group: Group = Field(description="group to apply the rule to", default=Group.onboarding)
|
57 |
+
courses: List[Course] = Field(description="list of courses that the members of the group will follow", default=[course.value for course in Course])
|
58 |
+
|
59 |
+
@field_validator("rule_code")
|
60 |
+
def rule_code_max_length(cls, rule_code):
|
61 |
+
# Check if empty
|
62 |
+
if not rule_code.strip():
|
63 |
+
raise ValueError("The rule code cannot be empty.")
|
64 |
+
# Check length
|
65 |
+
if len(rule_code) > 50:
|
66 |
+
raise ValueError("The rule code must contain less than 50 characters.")
|
67 |
+
return rule_code
|
68 |
+
@field_validator("rule_name")
|
69 |
+
def rule_name_max_length(cls, rule_name):
|
70 |
+
# Check if empty
|
71 |
+
if not rule_name.strip():
|
72 |
+
raise ValueError("The rule name cannot be empty.")
|
73 |
+
# Check length
|
74 |
+
if len(rule_name) > 255:
|
75 |
+
raise ValueError("The rule name must contain less than 255 characters.")
|
76 |
+
return rule_name
|
77 |
+
@field_validator("group")
|
78 |
+
def group_is_valid(cls, group):
|
79 |
+
# Check if empty
|
80 |
+
if not group or not group.strip():
|
81 |
+
raise ValueError("Group cannot be empty.")
|
82 |
+
# Validate group value
|
83 |
+
if group.lower().strip() not in GROUPS:
|
84 |
+
raise ValueError(f"group '{group}' is not a valid value for field 'group'. 'group' must be one of the following: '{', '.join(GROUPS)}'")
|
85 |
+
return group
|
86 |
+
@field_validator("courses")
|
87 |
+
def course_list_is_valid(cls, courses):
|
88 |
+
# Ensure at least one course is selected
|
89 |
+
if not courses:
|
90 |
+
raise ValueError("At least one course must be provided.")
|
91 |
+
|
92 |
+
# Validate all listed courses
|
93 |
+
invalid_courses = []
|
94 |
+
for course in courses:
|
95 |
+
if course.lower().strip() not in COURSES:
|
96 |
+
invalid_courses.append(course)
|
97 |
+
if invalid_courses:
|
98 |
+
raise ValueError(f"course(s) '{', '.join(invalid_courses)}' is not a valid value for field 'courses'. 'course' must be one or more of the following: '{', '.join(COURSES)}'")
|
99 |
+
return courses
|
100 |
+
|
101 |
+
def create_enrollment_rule(enrollment_rule: EnrollmentRule) -> dict:
|
102 |
+
"""Create an enrollment rule, based on the rule parameters provided by the user"""
|
103 |
+
payload = enrollment_rule.model_dump(mode="json")
|
104 |
+
return payload
|
105 |
+
|
106 |
+
# A small Gradio-friendly wrapper that converts user inputs into an EnrollmentRule
|
107 |
+
def gr_create_enrollment_rule(rule_code, rule_name, group, courses):
|
108 |
+
# Build the Pydantic model from the raw inputs
|
109 |
+
enrollment_rule = EnrollmentRule(
|
110 |
+
rule_code=rule_code,
|
111 |
+
rule_name=rule_name,
|
112 |
+
group=group,
|
113 |
+
courses=courses
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
)
|
115 |
+
return create_enrollment_rule(enrollment_rule)
|
116 |
+
|
117 |
+
# Define the Gradio interface
|
118 |
+
demo = gr.Interface(
|
119 |
+
fn=gr_create_enrollment_rule,
|
120 |
+
inputs=[
|
121 |
+
gr.Textbox(label="Rule Code", placeholder="Enter a unique identifier (max 50 characters)"),
|
122 |
+
gr.Textbox(label="Rule Name", placeholder="Enter a descriptive name (max 255 characters)"),
|
123 |
+
gr.Dropdown(label="Group", choices=GROUPS, value=GROUPS[0]),
|
124 |
+
gr.CheckboxGroup(label="Courses", choices=COURSES, value=[], info="Select one or more courses")
|
125 |
+
],
|
126 |
+
outputs="json",
|
127 |
+
title="Enrollment Rule Creator",
|
128 |
+
description="Create an enrollment rule, based on the rule parameters provided by the user",
|
129 |
+
allow_flagging="never"
|
130 |
+
)
|
131 |
+
|
132 |
+
demo.launch()
|
requirements.txt
CHANGED
@@ -1,6 +1 @@
|
|
1 |
-
|
2 |
-
diffusers
|
3 |
-
invisible_watermark
|
4 |
-
torch
|
5 |
-
transformers
|
6 |
-
xformers
|
|
|
1 |
+
gradio
|
|
|
|
|
|
|
|
|
|