Snigdhapaul2003 commited on
Commit
118809a
·
verified ·
1 Parent(s): 85ca105

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -36,15 +36,17 @@ def pdf_page_to_image(pdf_path, page_num=0):
36
  # Process PDFs and generate a question paper
37
  def process_pdfs_and_generate_question_paper(uploaded_files, name, number_of_sections, sections, difficulty_level, calculated_marks):
38
  # Save uploaded files locally
39
- folder_path = "uploaded_pdfs"
40
- if not os.path.exists(folder_path):
41
- os.makedirs(folder_path)
 
 
42
 
43
 
44
  # Save uploaded files locally
45
  for file in uploaded_files:
46
 
47
- file_path = os.path.join(folder_path, os.path.basename(file)) # Use only the filename
48
  with open(file, "rb") as input_file: # Read the file from its original path
49
  with open(file_path, "wb") as f: # Save it to the target folder
50
  f.write(input_file.read())
@@ -52,7 +54,7 @@ def process_pdfs_and_generate_question_paper(uploaded_files, name, number_of_sec
52
 
53
  # Extract text from PDFs
54
  full_ocr_text = ""
55
- pdf_files = [os.path.join(folder_path, f) for f in os.listdir(folder_path) if f.endswith('.pdf')]
56
 
57
 
58
  for pdf_file in pdf_files:
 
36
  # Process PDFs and generate a question paper
37
  def process_pdfs_and_generate_question_paper(uploaded_files, name, number_of_sections, sections, difficulty_level, calculated_marks):
38
  # Save uploaded files locally
39
+ # folder_path = "uploaded_pdfs"
40
+ temp_dir = tempfile.mkdtemp()
41
+
42
+ # if not os.path.exists(folder_path):
43
+ # os.makedirs(folder_path)
44
 
45
 
46
  # Save uploaded files locally
47
  for file in uploaded_files:
48
 
49
+ file_path = os.path.join(temp_dir, os.path.basename(file)) # Use only the filename
50
  with open(file, "rb") as input_file: # Read the file from its original path
51
  with open(file_path, "wb") as f: # Save it to the target folder
52
  f.write(input_file.read())
 
54
 
55
  # Extract text from PDFs
56
  full_ocr_text = ""
57
+ pdf_files = [os.path.join(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith('.pdf')]
58
 
59
 
60
  for pdf_file in pdf_files: