arjunanand13 commited on
Commit
ecad0ee
·
verified ·
1 Parent(s): 598fbac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -14
app.py CHANGED
@@ -163,26 +163,46 @@ def unzip_and_process(zip_file, model_choice, openai_classifier, questions_strin
163
  return excel_file # Return the path to the Excel file
164
 
165
  def run_interface(questions_json, resumes_zip):
166
- # Load questions.json content
167
- questions_string = questions_json.read().decode("utf-8")
168
-
169
- # Write the ZIP file to disk
170
- with open("uploaded_resumes.zip", "wb") as f:
171
- f.write(resumes_zip.read())
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
- openai_classifier = OpenAIClassifier(api_key="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")
174
- output_file = unzip_and_process("uploaded_resumes.zip", "openai", openai_classifier, questions_string)
 
 
175
 
176
- return output_file # Return the Excel file path as Gradio output
 
 
177
 
178
- # Set up the Gradio interface
179
  interface = gr.Interface(
180
  fn=run_interface,
181
  inputs=[
182
- gr.File(label="Upload questions.json"),
183
- gr.File(label="Upload ZIP of Resumes")
184
  ],
185
- outputs=gr.File(label="Processed Results Excel")
 
 
 
186
  )
187
 
188
- interface.launch()
 
 
163
  return excel_file # Return the path to the Excel file
164
 
165
  def run_interface(questions_json, resumes_zip):
166
+ try:
167
+ # Handle the questions.json file
168
+ if isinstance(questions_json, str):
169
+ # If it's a file path
170
+ with open(questions_json, 'r') as f:
171
+ questions_string = f.read()
172
+ else:
173
+ # If it's a temporary file object from Gradio
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, str):
180
+ zip_path = resumes_zip
181
+ else:
182
+ # If it's a temporary file object from Gradio
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 with better error handling
195
  interface = gr.Interface(
196
  fn=run_interface,
197
  inputs=[
198
+ gr.File(label="Upload questions.json", type="file"),
199
+ gr.File(label="Upload ZIP of Resumes", type="file")
200
  ],
201
+ outputs=gr.File(label="Processed Results Excel"),
202
+ title="Resume Analysis System",
203
+ description="Upload a questions.json file and a ZIP file containing resumes to process.",
204
+ allow_flagging="never",
205
  )
206
 
207
+ # Launch with debugging enabled
208
+ interface.launch(debug=True)