Spaces:
Sleeping
Sleeping
import gradio as gr | |
from openai import OpenAI | |
from dotenv import load_dotenv | |
import os | |
# Load API key | |
load_dotenv() | |
api_key = os.getenv("openai_api_key") | |
client = OpenAI(api_key=api_key) | |
# Function to generate game cards based on job profile | |
def generate_game_cards(JobProfileName): | |
system_message = """You are an interactive career card developer. | |
Generate a plain-text game card for any career. | |
The response should NOT contain Markdown formatting. | |
Add points wherever required. | |
Keep the text structured but in simple plain text format. | |
""" | |
user_message = f""" | |
Generate a complete set of game cards for the career {JobProfileName}. The output should include the following: | |
Career Card: | |
Title: {JobProfileName} | |
Overview: Provide a brief description explaining the role, responsibilities, and significance of a {JobProfileName}. | |
Pros & Cons: List 3β4 key pros and cons. | |
Dual Impact Highlights: Summarize how this career affects personal growth (e.g., satisfaction, skill development) and community impact (e.g., societal contributions, local development). | |
Level 1 Scenario Cards: (Entry-Level Challenges) | |
Scenario Card 1: | |
Title: e.g., 'Initial Challenge 1' | |
Description: Describe a basic challenge or opportunity typical for an entry-level {JobProfileName}. | |
Decision Cards: | |
Option A: Describe an action choice, then include outcomes (e.g., 'Personal Impact: +X, Community Impact: +Y'). | |
Option B: Describe an alternative action choice, then include outcomes (e.g., 'Personal Impact: +A, Community Impact: +B'). | |
Scenario Card 2: | |
Title: e.g., 'Initial Challenge 2' | |
Description: Describe a second basic scenario for a beginner-level {JobProfileName}. | |
Decision Cards: | |
Option A: Provide an action choice with outcomes (e.g., 'Personal Impact: +X2, Community Impact: +Y2'). | |
Option B: Provide an alternative action choice with outcomes (e.g., 'Personal Impact: +A2, Community Impact: +B2'). | |
Level 2 Scenario Cards: (Advanced-Level Challenges) | |
Scenario Card 1: | |
Title: e.g., 'Advanced Challenge 1' | |
Description: Describe a more complex challenge that a {JobProfileName} might face as responsibilities increase. | |
Decision Cards: | |
Option A: Provide an action choice with outcomes (e.g., 'Personal Impact: +X3, Community Impact: +Y3'). | |
Option B: Provide an alternative action choice with outcomes (e.g., 'Personal Impact: +A3, Community Impact: +B3'). | |
Scenario Card 2: | |
Title: e.g., 'Advanced Challenge 2' | |
Description: Describe a second complex scenario for an advanced-level {JobProfileName}. | |
Decision Cards: | |
Option A: Provide an action choice with outcomes (e.g., 'Personal Impact: +X4, Community Impact: +Y4'). | |
Option B: Provide an alternative action choice with outcomes (e.g., 'Personal Impact: +A4, Community Impact: +B4'). | |
Ensure that the design includes clear labels (such as 'Career Card', 'Level 1 Scenario', 'Level 2 Scenario', 'Decision Card'), along with visual cues like icons for Personal Impact (e.g., a star) and Community Impact (e.g., a group or community icon). The tone should be engaging and accessible for a 12β16-year-old audience. | |
""" | |
response = client.chat.completions.create( | |
model="gpt-4o-mini", | |
messages=[ | |
{"role": "system", "content": system_message}, # System instructions | |
{"role": "user", "content": user_message} # User query with job details | |
] | |
) | |
return response.choices[0].message.content | |
# Gradio UI | |
def game_interface(job_profile): | |
return generate_game_cards(job_profile) | |
app = gr.Interface(fn=game_interface, inputs=gr.Textbox(label="Enter a Job Profile"), | |
outputs=gr.Textbox(label="Game Card Output"), | |
title="Career Simulation Game") | |
app.launch() | |