Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -164,45 +164,57 @@ def unzip_and_process(zip_file, model_choice, openai_classifier, questions_strin
|
|
| 164 |
|
| 165 |
def run_interface(questions_json, resumes_zip):
|
| 166 |
try:
|
| 167 |
-
# Handle the questions.json file
|
| 168 |
-
if isinstance(questions_json,
|
|
|
|
|
|
|
|
|
|
| 169 |
# If it's a file path
|
| 170 |
with open(questions_json, 'r') as f:
|
| 171 |
questions_string = f.read()
|
| 172 |
else:
|
| 173 |
-
|
| 174 |
-
questions_string = questions_json.name
|
| 175 |
-
with open(questions_string, 'r') as f:
|
| 176 |
-
questions_string = f.read()
|
| 177 |
|
| 178 |
# Handle the ZIP file
|
| 179 |
-
if isinstance(resumes_zip,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
zip_path = resumes_zip
|
| 181 |
else:
|
| 182 |
-
|
| 183 |
-
zip_path = resumes_zip.name
|
| 184 |
|
| 185 |
openai_classifier = OpenAIClassifier(api_key="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")
|
| 186 |
output_file = unzip_and_process(zip_path, "openai", openai_classifier, questions_string)
|
| 187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
return output_file
|
| 189 |
|
| 190 |
except Exception as e:
|
| 191 |
print(f"Error in run_interface: {str(e)}")
|
|
|
|
|
|
|
|
|
|
| 192 |
raise gr.Error(f"Processing failed: {str(e)}")
|
| 193 |
|
| 194 |
-
# Set up the Gradio interface
|
| 195 |
interface = gr.Interface(
|
| 196 |
fn=run_interface,
|
| 197 |
inputs=[
|
| 198 |
gr.File(
|
| 199 |
label="Upload questions.json",
|
| 200 |
-
type="binary",
|
| 201 |
file_types=[".json"]
|
| 202 |
),
|
| 203 |
gr.File(
|
| 204 |
label="Upload ZIP of Resumes",
|
| 205 |
-
type="binary",
|
| 206 |
file_types=[".zip"]
|
| 207 |
)
|
| 208 |
],
|
|
@@ -212,5 +224,5 @@ interface = gr.Interface(
|
|
| 212 |
allow_flagging="never",
|
| 213 |
)
|
| 214 |
|
| 215 |
-
# Launch with debugging enabled
|
| 216 |
-
interface.launch(debug=True)
|
|
|
|
| 164 |
|
| 165 |
def run_interface(questions_json, resumes_zip):
|
| 166 |
try:
|
| 167 |
+
# Handle the questions.json file content
|
| 168 |
+
if isinstance(questions_json, bytes):
|
| 169 |
+
# Parse bytes directly as JSON string
|
| 170 |
+
questions_string = questions_json.decode('utf-8')
|
| 171 |
+
elif isinstance(questions_json, str):
|
| 172 |
# If it's a file path
|
| 173 |
with open(questions_json, 'r') as f:
|
| 174 |
questions_string = f.read()
|
| 175 |
else:
|
| 176 |
+
raise ValueError("Unexpected questions_json type")
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
# Handle the ZIP file
|
| 179 |
+
if isinstance(resumes_zip, bytes):
|
| 180 |
+
# Write bytes to a temporary zip file
|
| 181 |
+
temp_zip_path = "temp_uploaded_resumes.zip"
|
| 182 |
+
with open(temp_zip_path, "wb") as f:
|
| 183 |
+
f.write(resumes_zip)
|
| 184 |
+
zip_path = temp_zip_path
|
| 185 |
+
elif isinstance(resumes_zip, str):
|
| 186 |
zip_path = resumes_zip
|
| 187 |
else:
|
| 188 |
+
raise ValueError("Unexpected resumes_zip type")
|
|
|
|
| 189 |
|
| 190 |
openai_classifier = OpenAIClassifier(api_key="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")
|
| 191 |
output_file = unzip_and_process(zip_path, "openai", openai_classifier, questions_string)
|
| 192 |
|
| 193 |
+
# Clean up temporary zip file if it was created
|
| 194 |
+
if isinstance(resumes_zip, bytes) and os.path.exists(temp_zip_path):
|
| 195 |
+
os.remove(temp_zip_path)
|
| 196 |
+
|
| 197 |
return output_file
|
| 198 |
|
| 199 |
except Exception as e:
|
| 200 |
print(f"Error in run_interface: {str(e)}")
|
| 201 |
+
# Clean up temporary files in case of error
|
| 202 |
+
if 'temp_zip_path' in locals() and os.path.exists(temp_zip_path):
|
| 203 |
+
os.remove(temp_zip_path)
|
| 204 |
raise gr.Error(f"Processing failed: {str(e)}")
|
| 205 |
|
| 206 |
+
# Set up the Gradio interface
|
| 207 |
interface = gr.Interface(
|
| 208 |
fn=run_interface,
|
| 209 |
inputs=[
|
| 210 |
gr.File(
|
| 211 |
label="Upload questions.json",
|
| 212 |
+
type="binary",
|
| 213 |
file_types=[".json"]
|
| 214 |
),
|
| 215 |
gr.File(
|
| 216 |
label="Upload ZIP of Resumes",
|
| 217 |
+
type="binary",
|
| 218 |
file_types=[".zip"]
|
| 219 |
)
|
| 220 |
],
|
|
|
|
| 224 |
allow_flagging="never",
|
| 225 |
)
|
| 226 |
|
| 227 |
+
# Launch with debugging and sharing enabled
|
| 228 |
+
interface.launch(debug=True, share=True)
|