Skip to content

Commit

Permalink
fix indentation
Browse files Browse the repository at this point in the history
jeromehardaway committed Nov 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 330ef48 commit aa46802
Showing 1 changed file with 46 additions and 156 deletions.
202 changes: 46 additions & 156 deletions app.py
Original file line number Diff line number Diff line change
@@ -28,18 +28,18 @@
/* Main app styling */
code {
code {
padding: 0.2em 0.4em;
margin: 0px;
border-radius: 0.25rem;
background: rgb(132, 143, 160);
color: #ffffff; /* Changed to white for better contrast */
color: #ffffff;
}
/* For inline code */
.markdown-text-container code {
background: #091f40; /* Navy blue background */
color: #ffffff; /* White text */
background: #091f40;
color: #ffffff;
padding: 0.2em 0.4em;
border-radius: 0.25rem;
}
@@ -106,7 +106,7 @@
border-color: var(--navy-blue);
}
/* Chat input text color */
/* Chat input text color */
.st-bt {
color: var(--white) !important;
}
@@ -160,7 +160,6 @@

# Load environment variables
load_dotenv()

openai.api_key = st.secrets["openai"]["OPENAI_API_KEY"]

# Optionally, load the model name if needed
@@ -171,44 +170,28 @@
raise ValueError("OpenAI API key not found in Streamlit secrets.")

def parse_mos_file(file_content: str) -> dict:
"""
Parse military job code text file content into a structured dictionary.
Args:
file_content: Raw text content of the MOS file
Returns:
dict: Structured data including title, category, and skills
"""
"""Parse military job code text file content into a structured dictionary."""
lines = file_content.strip().split('\n')

job_code = ""
title = ""
description = []
job_code, title, description = "", "", []
parsing_description = False

for line in lines:
line = line.strip()
if not line:
continue

if line.startswith("Job Code:"):
job_code = line.replace("Job Code:", "").strip()
elif line.startswith("Description:"):
parsing_description = True
elif parsing_description:
description.append(line)

# Get the first non-empty description line as title
for line in description:
if line:
title = line
break

# Combine all description text for category analysis
full_text = ' '.join(description).lower()

# More comprehensive category detection
category = "general"
category_keywords = {
"information_technology": ["technology", "computer", "network", "data", "software", "hardware", "system", "database"],
@@ -218,7 +201,6 @@ def parse_mos_file(file_content: str) -> dict:
"cyber": ["cyber", "security", "information assurance", "cryptographic"]
}

# Check for category keywords in the full text
for cat, keywords in category_keywords.items():
if any(keyword in full_text for keyword in keywords):
category = cat
@@ -233,8 +215,6 @@ def parse_mos_file(file_content: str) -> dict:
def load_military_job_codes() -> dict:
base_path = "data/employment_transitions/job_codes"
job_codes = {}

# Map of service branches to their file paths and code prefixes
branches = {
"army": {"path": "army", "prefix": "MOS"},
"air_force": {"path": "air_force", "prefix": "AFSC"},
@@ -247,16 +227,13 @@ def load_military_job_codes() -> dict:
branch_path = os.path.join(base_path, info["path"])
if os.path.exists(branch_path):
for file in os.listdir(branch_path):
if file.endswith('.txt'): # Changed from .json to .txt
if file.endswith('.txt'):
try:
with open(os.path.join(branch_path, file), 'r') as f:
content = f.read()
code = file.replace('.txt', '')
details = parse_mos_file(content)

# Add VWC specific development paths
vwc_mapping = map_to_vwc_path(details.get('category', ''),
details.get('skills', []))
vwc_mapping = map_to_vwc_path(details.get('category', ''), details.get('skills', []))
details.update({
'vwc_path': vwc_mapping['path'],
'tech_focus': vwc_mapping['tech_focus'],
@@ -267,12 +244,10 @@ def load_military_job_codes() -> dict:
except Exception as e:
logger.error(f"Error loading {file}: {e}")
continue

return job_codes

def map_to_vwc_path(category: str, skills: List[str]) -> dict:
"""Map military job categories and skills to VWC tech stack paths."""

# Default full stack path
default_path = {
"path": "Full Stack Development",
"tech_focus": [
@@ -282,7 +257,6 @@ def map_to_vwc_path(category: str, skills: List[str]) -> dict:
]
}

# Category-based mappings
tech_paths = {
"information_technology": {
"path": "Full Stack Development",
@@ -326,7 +300,6 @@ def map_to_vwc_path(category: str, skills: List[str]) -> dict:
}
}

# Skill-based adjustments
skill_keywords = {
"programming": "software",
"database": "data",
@@ -335,11 +308,9 @@ def map_to_vwc_path(category: str, skills: List[str]) -> dict:
"analysis": "intelligence"
}

# Determine best path based on category and skills
if category.lower() in tech_paths:
return tech_paths[category.lower()]

# Check skills for keywords
for skill in skills:
skill_lower = skill.lower()
for keyword, category in skill_keywords.items():
@@ -350,21 +321,13 @@ def map_to_vwc_path(category: str, skills: List[str]) -> dict:

def translate_military_code(code: str, job_codes: dict) -> dict:
"""Translate military code to VWC development path."""
# Clean and standardize input
code = code.upper().strip()

# Remove common prefixes if provided
prefixes = ["MOS", "AFSC", "RATE"]
for prefix in prefixes:
if code.startswith(prefix):
code = code.replace(prefix, "").strip()

# Try different prefix combinations
possible_codes = [
f"MOS_{code}",
f"AFSC_{code}",
f"RATE_{code}"
]
possible_codes = [f"MOS_{code}", f"AFSC_{code}", f"RATE_{code}"]

for possible_code in possible_codes:
if possible_code in job_codes:
@@ -380,7 +343,6 @@ def translate_military_code(code: str, job_codes: dict) -> dict:
}
}

# Default response for unknown codes
return {
"found": False,
"data": {
@@ -403,8 +365,8 @@ def translate_military_code(code: str, job_codes: dict) -> dict:
def get_chat_response(messages: List[Dict]) -> str:
"""Get response from OpenAI chat completion."""
try:
response = openai.chat.completions.create(
model="gpt-4o",
response = openai.ChatCompletion.create(
model="gpt-4",
messages=messages,
temperature=0.7,
)
@@ -428,12 +390,10 @@ def save_feedback(feedback: Dict):
"""Save user feedback to file."""
feedback_dir = "feedback"
os.makedirs(feedback_dir, exist_ok=True)

feedback_file = os.path.join(
feedback_dir,
f"feedback_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
)

with open(feedback_file, 'w') as f:
json.dump(feedback, f, indent=2)

@@ -500,11 +460,8 @@ def main():

# Initialize session
if 'session_id' not in st.session_state:
st.session_state.session_id = hashlib.md5(
str(time.time()).encode()
).hexdigest()
st.session_state.session_id = hashlib.md5(str(time.time()).encode()).hexdigest()

# Load military job codes
if 'job_codes' not in st.session_state:
try:
st.session_state.job_codes = load_military_job_codes()
@@ -515,44 +472,22 @@ def main():
if 'messages' not in st.session_state:
st.session_state.messages = initialize_chat()

# Add sidebar with VWC tech stack resources
# Sidebar with VWC tech stack resources
with st.sidebar:
st.markdown("""
### VWC Tech Stack
🌐 **Frontend**
- JavaScript/TypeScript
- CSS & Tailwind
- Next.js
⚙️ **Backend**
- Python
- FastAPI
- Flask
- Django
🤖 **AI/ML Integration**
- Machine Learning
- AI Applications
🎖️ **Military Translation**
`/mos [code]` - Army/Marines
`/afsc [code]` - Air Force
`/rate [code]` - Navy/Coast Guard
""")

# Chat interface
st.markdown("### VWC Tech Stack\n- JavaScript/TypeScript\n- Python\n...")

# Display chat messages
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])


# Chat input
if prompt := st.chat_input():
# Add user message
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
# Check for commands first

# Check for commands
if prompt.startswith('/'):
command_response = handle_command(prompt)
if command_response:
@@ -563,83 +498,38 @@ def main():
"content": command_response
})
return

# Generate and display assistant response
with st.chat_message("assistant"):
try:
messages = st.session_state.messages.copy()
messages.insert(0, {
"role": "system",
"content": (
"You are a specialized AI assistant for Vets Who Code members, designed to provide clear, practical technical guidance "
"to veterans transitioning into software development careers.\n\n"

"CORE TECH STACK:\n"
"- Frontend: JavaScript, TypeScript, React, Next.js\n"
"- Styling: CSS, Tailwind CSS\n"
"- Backend: Python, FastAPI\n"
"- Data & Visualization: Streamlit\n"
"- Advanced: AI/ML fundamentals\n"
"- Development Tools: Git, GitHub, VS Code\n"
"- Testing: Jest, Pytest\n\n"

"CAREER TRANSITION GUIDANCE:\n"
"1. Resume Development:\n"
" - Technical Skills: Programming Languages, Frameworks, Tools, Cloud, Testing\n"
" - Military Experience Translation: Leadership, Problem-solving, Team Collaboration\n\n"

"2. Portfolio Development:\n"
" - Clean code and documentation\n"
" - Version control and API integration\n"
" - Responsive design and performance\n"
" - Testing and TypeScript implementation\n"
" - Security and accessibility standards\n\n"

"LEARNING PATHS:\n"
"1. Fundamentals: HTML, CSS, JavaScript, Git\n"
"2. Intermediate: TypeScript, React, Python\n"
"3. Advanced: Next.js, FastAPI, Streamlit, AI/ML\n\n"

"PROJECT FOCUS:\n"
"1. Portfolio Projects: Personal website, APIs, Data visualization\n"
"2. Technical Skills: Code quality, Testing, Security, Performance\n"
"3. Career Materials: GitHub profile, Technical blog, Documentation\n\n"

"Remember: Provide practical guidance for building technical skills and transitioning to software development careers. "
"Focus on concrete examples and best practices."
)
})

response = get_chat_response(messages)
st.markdown(response)
with st.chat_message("assistant"):
try:
messages = st.session_state.messages.copy()
messages.insert(0, {
"role": "system",
"content": (
"You are a specialized AI assistant for Vets Who Code members, "
"designed to provide clear, practical technical guidance for veterans."
)
})

st.session_state.messages.append({
"role": "assistant",
"content": response
})
except Exception as e:
st.error(f"Error generating response: {str(e)}")

response = get_chat_response(messages)
st.markdown(response)
st.session_state.messages.append({
"role": "assistant",
"content": response
})
except Exception as e:
st.error(f"Error generating response: {str(e)}")

# Export chat history
if st.button("Export Chat History"):
chat_export = export_chat_history(st.session_state.messages)
st.download_button(
"Download Chat History",
chat_export,
"vetsai_chat_history.json",
"application/json"
)

st.download_button("Download Chat History", chat_export, "vetsai_chat_history.json", "application/json")

# Feedback mechanism
with st.expander("Provide Feedback"):
feedback_rating = st.slider(
"Rate your experience (1-5)",
min_value=1,
max_value=5,
value=5
)
feedback_rating = st.slider("Rate your experience (1-5)", min_value=1, max_value=5, value=5)
feedback_text = st.text_area("Additional feedback")

if st.button("Submit Feedback"):
feedback = {
"timestamp": datetime.now().isoformat(),

0 comments on commit aa46802

Please sign in to comment.