ophillia commited on
Commit
08af1d7
Β·
verified Β·
1 Parent(s): 37b9eac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +130 -0
app.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import random
4
+
5
+ # --- Smart mapping of common keywords to career categories
6
+ keyword_to_category = {
7
+ "coding": "technology", "programming": "technology", "computers": "technology",
8
+ "software": "technology", "math": "technology", "ai": "technology",
9
+
10
+ "biology": "science", "chemistry": "science", "physics": "science",
11
+ "environment": "science", "lab": "science",
12
+
13
+ "health": "health", "nurse": "health", "medical": "health", "nutrition": "health",
14
+
15
+ "art": "art", "drawing": "art", "music": "art", "design": "art", "fashion": "art",
16
+
17
+ "business": "business", "management": "business", "finance": "business",
18
+ "entrepreneur": "business", "marketing": "business",
19
+
20
+ "teach": "education", "school": "education", "history": "education",
21
+
22
+ "law": "law", "legal": "law", "justice": "law",
23
+
24
+ "plumber": "skilled", "electrician": "skilled", "welding": "skilled", "tools": "skilled",
25
+ }
26
+
27
+ career_map = {
28
+ "technology": ["Software Developer", "Cybersecurity Analyst", "UI/UX Designer", "Cloud Engineer"],
29
+ "science": ["Biologist", "Environmental Scientist", "Physicist", "Bioinformatician"],
30
+ "health": ["Nurse", "Public Health Educator", "Medical Lab Scientist", "Nutritionist"],
31
+ "art": ["Graphic Designer", "Music Producer", "Art Director", "Fashion Stylist"],
32
+ "business": ["Business Analyst", "Project Manager", "E-commerce Specialist", "HR Manager"],
33
+ "education": ["Teacher", "Career Counselor", "Educational Technologist", "Historian"],
34
+ "law": ["Lawyer", "Legal Advisor", "Compliance Officer"],
35
+ "skilled": ["Electrician", "Plumber", "Welder", "Carpenter"]
36
+ }
37
+
38
+ fallback_careers = [
39
+ "AI Prompt Engineer", "Data Analyst", "Entrepreneur", "Content Creator", "Digital Marketer",
40
+ "Social Media Manager", "Mobile App Developer", "Game Designer", "Robotics Technician",
41
+ "3D Animator", "Financial Planner", "Clinical Data Manager", "Health Tech Support",
42
+ "E-learning Designer", "Ethical Hacker", "SEO Specialist", "Tech Sales Consultant",
43
+ "Virtual Reality Developer", "Sustainability Analyst", "Product Designer", "Freelance Writer",
44
+ "Voiceover Artist", "Customer Success Manager", "Technical Recruiter"
45
+ ]
46
+
47
+ def suggest_careers(name, interests, skills, subject):
48
+ if not name.strip() or not interests.strip() or not skills.strip() or not subject.strip():
49
+ return "⚠️ Please fill in all fields before submitting."
50
+
51
+ combined_input = f"{interests} {skills} {subject}".lower()
52
+ matched_categories = set()
53
+
54
+ # Match keywords to categories
55
+ for keyword, category in keyword_to_category.items():
56
+ if keyword in combined_input:
57
+ matched_categories.add(category)
58
+
59
+ suggested = set()
60
+ for category in matched_categories:
61
+ suggested.update(career_map.get(category, []))
62
+
63
+ if not suggested:
64
+ suggested.update(random.sample(fallback_careers, k=6))
65
+
66
+ suggestions = "\n".join(f"πŸŽ“ {career}" for career in sorted(suggested))
67
+
68
+ return f"""
69
+ Hi <span style='color:#2E86AB; font-weight:bold;'>{name}</span>, based on your input:<br>
70
+ βœ… <b>Interests</b>: <span style='color:#117A65'>{interests}</span><br>
71
+ βœ… <b>Skills</b>: <span style='#AF601A'>{skills}</span><br>
72
+ βœ… <b>Favorite Subject</b>: <span style='color:#6C3483'>{subject}</span><br><br>
73
+
74
+ Here are some career suggestions for you:<br><br>
75
+ {suggestions}
76
+ """
77
+
78
+ # --- Gradio UI
79
+ with gr.Blocks(title="🎯 Career Path Finder") as demo:
80
+ gr.HTML("""
81
+ <style>
82
+ body {
83
+ background-color: #E6F2FF;
84
+ }
85
+ .gr-box {
86
+ background-color: #ffffff !important;
87
+ border-radius: 12px;
88
+ padding: 20px;
89
+ box-shadow: 0 4px 12px rgba(0,0,0,0.1);
90
+ }
91
+ input[type="text"], textarea {
92
+ background-color: #F0FAFF !important;
93
+ color: #003366 !important;
94
+ border: 1px solid #b3d9ff !important;
95
+ font-weight: 500;
96
+ border-radius: 8px !important;
97
+ }
98
+ textarea:disabled {
99
+ background-color: #f9f9f9 !important;
100
+ color: #333333 !important;
101
+ }
102
+ </style>
103
+ """)
104
+
105
+ gr.Markdown("## 🎯 Career Path Finder")
106
+ gr.Markdown("Fill out the form below to get personalized career suggestions!")
107
+
108
+ with gr.Group():
109
+ with gr.Row():
110
+ name = gr.Textbox(label="Your Name", placeholder="e.g., Ophillia")
111
+ subject = gr.Textbox(label="Favorite Subject", placeholder="e.g., Mathematics, Life Sciences")
112
+
113
+ with gr.Group():
114
+ with gr.Row():
115
+ interests = gr.Textbox(label="Your Interests", placeholder="e.g., problem solving, creativity")
116
+ skills = gr.Textbox(label="Your Skills", placeholder="e.g., coding, teamwork, communication")
117
+
118
+ output = gr.HTML(label="πŸŽ“ Career Suggestions") # Use HTML output for formatting
119
+
120
+ with gr.Row():
121
+ submit_btn = gr.Button(" Submit", variant="primary")
122
+ clear_btn = gr.Button(" Clear", variant="stop")
123
+
124
+ def clear_all():
125
+ return "", "", "", "", ""
126
+
127
+ submit_btn.click(fn=suggest_careers, inputs=[name, interests, skills, subject], outputs=output)
128
+ clear_btn.click(fn=clear_all, inputs=[], outputs=[name, interests, skills, subject, output])
129
+
130
+ demo.launch()