Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,13 +2,9 @@ import streamlit as st
|
|
| 2 |
from docx import Document
|
| 3 |
import requests
|
| 4 |
import io
|
| 5 |
-
import os
|
| 6 |
-
|
| 7 |
-
HF_API_KEY = os.getenv("HF_API_KEY")
|
| 8 |
|
| 9 |
# Hugging Face API details
|
| 10 |
API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-large"
|
| 11 |
-
HEADERS = {"Authorization": "Bearer HF_API_KEY"}
|
| 12 |
|
| 13 |
# Department and Role mapping
|
| 14 |
DEPARTMENT_ROLES = {
|
|
@@ -56,11 +52,22 @@ def generate_jd_with_hf(department, role):
|
|
| 56 |
}
|
| 57 |
}
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
# Function to create Word document
|
| 66 |
def create_word_document(role, content):
|
|
@@ -111,10 +118,10 @@ with col2:
|
|
| 111 |
# Generate JD button
|
| 112 |
if st.button("✨ Generate Job Description"):
|
| 113 |
with st.spinner("Generating professional job description using AI..."):
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
# Create Word document
|
| 119 |
doc_buffer = create_word_document(role, jd_content)
|
| 120 |
|
|
@@ -131,9 +138,6 @@ if st.button("✨ Generate Job Description"):
|
|
| 131 |
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
| 132 |
help="Download the job description in Word format"
|
| 133 |
)
|
| 134 |
-
|
| 135 |
-
except Exception as e:
|
| 136 |
-
st.error(f"Error generating job description: {str(e)}")
|
| 137 |
|
| 138 |
# Instructions
|
| 139 |
st.markdown("""
|
|
|
|
| 2 |
from docx import Document
|
| 3 |
import requests
|
| 4 |
import io
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Hugging Face API details
|
| 7 |
API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-large"
|
|
|
|
| 8 |
|
| 9 |
# Department and Role mapping
|
| 10 |
DEPARTMENT_ROLES = {
|
|
|
|
| 52 |
}
|
| 53 |
}
|
| 54 |
|
| 55 |
+
try:
|
| 56 |
+
# Get API key from Streamlit secrets (for Hugging Face Spaces) or environment variable
|
| 57 |
+
api_key = st.secrets.get("HUGGINGFACE_API_KEY", "YOUR_HUGGINGFACE_API_KEY")
|
| 58 |
+
headers = {"Authorization": f"Bearer {api_key}"}
|
| 59 |
+
|
| 60 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 61 |
+
|
| 62 |
+
# Check for API errors
|
| 63 |
+
if response.status_code == 200:
|
| 64 |
+
return response.json()[0]['generated_text']
|
| 65 |
+
else:
|
| 66 |
+
st.error(f"API Error: {response.status_code} - {response.text}")
|
| 67 |
+
return None
|
| 68 |
+
except Exception as e:
|
| 69 |
+
st.error(f"Failed to connect to Hugging Face API: {str(e)}")
|
| 70 |
+
return None
|
| 71 |
|
| 72 |
# Function to create Word document
|
| 73 |
def create_word_document(role, content):
|
|
|
|
| 118 |
# Generate JD button
|
| 119 |
if st.button("✨ Generate Job Description"):
|
| 120 |
with st.spinner("Generating professional job description using AI..."):
|
| 121 |
+
# Generate JD content
|
| 122 |
+
jd_content = generate_jd_with_hf(department, role)
|
| 123 |
+
|
| 124 |
+
if jd_content:
|
| 125 |
# Create Word document
|
| 126 |
doc_buffer = create_word_document(role, jd_content)
|
| 127 |
|
|
|
|
| 138 |
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
| 139 |
help="Download the job description in Word format"
|
| 140 |
)
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
# Instructions
|
| 143 |
st.markdown("""
|