Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -52,11 +52,7 @@ def index():
|
|
52 |
@app.route('/process', methods=['GET','POST'])
|
53 |
def upload_file():
|
54 |
try:
|
55 |
-
|
56 |
-
#print("Request headers:", request.headers)
|
57 |
-
#print("Request form:", request.form)
|
58 |
-
#print("Request files:", request.files)
|
59 |
-
|
60 |
# Check if the 'files' part exists in the request
|
61 |
if 'files' not in request.files:
|
62 |
print("No 'files' part in the request")
|
@@ -87,7 +83,7 @@ def upload_file():
|
|
87 |
|
88 |
session['uploaded_files'] = uploaded_files # Store uploaded files in session
|
89 |
logging.info(f"Files successfully uploaded: {uploaded_files}")
|
90 |
-
return process_file(uploaded_files)
|
91 |
|
92 |
except Exception as e:
|
93 |
logging.error(f"An error occurred during file upload: {e}")
|
@@ -118,8 +114,6 @@ def process_file(filename):
|
|
118 |
logging.warning("No files selected for processing")
|
119 |
return redirect(url_for('index'))
|
120 |
|
121 |
-
BASE_DIR = 'uploads/'
|
122 |
-
|
123 |
# Joining the base and the requested path
|
124 |
file_paths = [os.path.join(app.config['UPLOAD_FOLDER'], filename) for filename in uploaded_files]
|
125 |
logging.info(f"Processing files: {file_paths}")
|
@@ -133,12 +127,17 @@ def process_file(filename):
|
|
133 |
logging.info(f"Extracted text: {extracted_text}")
|
134 |
logging.info(f"Processed images: {processed_Img}")
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
except Exception as model_error:
|
144 |
logging.error(f"Error during LLM processing: {model_error}")
|
|
|
52 |
@app.route('/process', methods=['GET','POST'])
|
53 |
def upload_file():
|
54 |
try:
|
55 |
+
|
|
|
|
|
|
|
|
|
56 |
# Check if the 'files' part exists in the request
|
57 |
if 'files' not in request.files:
|
58 |
print("No 'files' part in the request")
|
|
|
83 |
|
84 |
session['uploaded_files'] = uploaded_files # Store uploaded files in session
|
85 |
logging.info(f"Files successfully uploaded: {uploaded_files}")
|
86 |
+
return process_file(uploaded_files), 200
|
87 |
|
88 |
except Exception as e:
|
89 |
logging.error(f"An error occurred during file upload: {e}")
|
|
|
114 |
logging.warning("No files selected for processing")
|
115 |
return redirect(url_for('index'))
|
116 |
|
|
|
|
|
117 |
# Joining the base and the requested path
|
118 |
file_paths = [os.path.join(app.config['UPLOAD_FOLDER'], filename) for filename in uploaded_files]
|
119 |
logging.info(f"Processing files: {file_paths}")
|
|
|
127 |
logging.info(f"Extracted text: {extracted_text}")
|
128 |
logging.info(f"Processed images: {processed_Img}")
|
129 |
|
130 |
+
#run the model code only if the text is extracted.
|
131 |
+
if extracted_text:
|
132 |
+
llmText = json_to_llm_str(extracted_text)
|
133 |
+
logging.info(f"LLM text: {llmText}")
|
134 |
+
|
135 |
+
#run the model code only if the text is extracted.
|
136 |
+
LLMdata = Data_Extractor(llmText)
|
137 |
+
print("Json Output from model------------>",LLMdata)
|
138 |
+
logging.info(f"LLM data: {LLMdata}")
|
139 |
+
else:
|
140 |
+
raise ('The text is not detected in the OCR')
|
141 |
|
142 |
except Exception as model_error:
|
143 |
logging.error(f"Error during LLM processing: {model_error}")
|