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(job_profile): 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, asterisks, or bullet points. Keep the text structured but in simple plain text format. """ user_message = f"""Provide a game card for the career: {job_profile}. Include: - Title: The job title. - Overview: A short description of the role. - Pros & Cons: List 3-4 key pros and cons in full sentences. - Dual Impact Highlights: Explain how this career affects personal growth (skills, satisfaction) and community impact (society, economy). """ 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()