Spaces:
Sleeping
Sleeping
import gradio as gr # ---------------------- # Dummy database users = [] jobs = [] # ---------------------- # Functions def register_user(user_id, name, skills): if any(u['id'] == user_id for u in users): return f"User ID {user_id} already exists!" users.append({"id": user_id, "name": name, "skills": skills.split(",")}) return f"User {name} registered successfully!" def post_job(job_id, title, skill_required): if any(j['id'] == job_id for j in jobs): return f"Job ID {job_id} already exists!" jobs.append({"id": job_id, "title": title, "skill_required": skill_required}) return f"Job '{title}' posted successfully!" def match_jobs(user_id): user = next((u for u in users if u['id'] == int(user_id)), None) if not user: return "User not found" matched = [job["title"] for job in jobs if job["skill_required"] in user["skills"]] return matched if matched else "No jobs matched" # ---------------------- # Gradio Interfaces with gr.Blocks() as demo: gr.Markdown("## Smart Gig Platform MVP") with gr.Tab("Register User"): user_id_input = gr.Number(label="User ID") user_name_input = gr.Textbox(label="Name") user_skills_input = gr.Textbox(label="Skills (comma separated)") register_btn = gr.Button("Register") register_output = gr.Textbox(label="Output") register_btn.click(register_user, inputs=[user_id_input, user_name_input, user_skills_input], outputs=register_output) with gr.Tab("Post Job"): job_id_input = gr.Number(label="Job ID") job_title_input = gr.Textbox(label="Job Title") job_skill_input = gr.Textbox(label="Required Skill") post_btn = gr.Button("Post Job") post_output = gr.Textbox(label="Output") post_btn.click(post_job, inputs=[job_id_input, job_title_input, job_skill_input], outputs=post_output) with gr.Tab("Match Jobs"): match_user_id_input = gr.Number(label="User ID") match_output = gr.Textbox(label="Matched Jobs") match_btn = gr.Button("Find Jobs") match_btn.click(match_jobs, inputs=[match_user_id_input], outputs=match_output) # ---------------------- demo.launch()
bd8ea8d verified | import gradio as gr | |
| # ---------------------- | |
| # Dummy database | |
| users = [] | |
| jobs = [] | |
| # ---------------------- | |
| # Functions | |
| def register_user(user_id, name, skills): | |
| if any(u['id'] == user_id for u in users): | |
| return f"User ID {user_id} already exists!" | |
| users.append({"id": user_id, "name": name, "skills": skills.split(",")}) | |
| return f"User {name} registered successfully!" | |
| def post_job(job_id, title, skill_required): | |
| if any(j['id'] == job_id for j in jobs): | |
| return f"Job ID {job_id} already exists!" | |
| jobs.append({"id": job_id, "title": title, "skill_required": skill_required}) | |
| return f"Job '{title}' posted successfully!" | |
| def match_jobs(user_id): | |
| user = next((u for u in users if u['id'] == int(user_id)), None) | |
| if not user: | |
| return "User not found" | |
| matched = [job["title"] for job in jobs if job["skill_required"] in user["skills"]] | |
| return matched if matched else "No jobs matched" | |
| # ---------------------- | |
| # Gradio Interfaces | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## Smart Gig Platform MVP") | |
| with gr.Tab("Register User"): | |
| user_id_input = gr.Number(label="User ID") | |
| user_name_input = gr.Textbox(label="Name") | |
| user_skills_input = gr.Textbox(label="Skills (comma separated)") | |
| register_btn = gr.Button("Register") | |
| register_output = gr.Textbox(label="Output") | |
| register_btn.click(register_user, | |
| inputs=[user_id_input, user_name_input, user_skills_input], | |
| outputs=register_output) | |
| with gr.Tab("Post Job"): | |
| job_id_input = gr.Number(label="Job ID") | |
| job_title_input = gr.Textbox(label="Job Title") | |
| job_skill_input = gr.Textbox(label="Required Skill") | |
| post_btn = gr.Button("Post Job") | |
| post_output = gr.Textbox(label="Output") | |
| post_btn.click(post_job, | |
| inputs=[job_id_input, job_title_input, job_skill_input], | |
| outputs=post_output) | |
| with gr.Tab("Match Jobs"): | |
| match_user_id_input = gr.Number(label="User ID") | |
| match_output = gr.Textbox(label="Matched Jobs") | |
| match_btn = gr.Button("Find Jobs") | |
| match_btn.click(match_jobs, inputs=[match_user_id_input], outputs=match_output) | |
| # ---------------------- | |
| demo.launch() |