Spaces:
Sleeping
Sleeping
AdityaAdaki
commited on
Commit
·
443465b
1
Parent(s):
2b43b1f
app
Browse files
app.py
CHANGED
|
@@ -133,41 +133,48 @@ def process_certificate(image_path, cert_name):
|
|
| 133 |
@app.route("/", methods=["GET", "POST"])
|
| 134 |
def home():
|
| 135 |
if request.method == "POST":
|
| 136 |
-
cert_name = "Affiliation Certificate"
|
| 137 |
-
|
| 138 |
-
# Check if the post request has the file part
|
| 139 |
-
if 'certificate' not in request.files:
|
| 140 |
-
return render_template("index.html", error="No file part in the request")
|
| 141 |
-
|
| 142 |
-
file = request.files['certificate']
|
| 143 |
-
|
| 144 |
-
# If user does not select file, browser also submits an empty part without filename
|
| 145 |
-
if file.filename == '':
|
| 146 |
-
return render_template("index.html", error="No file selected")
|
| 147 |
-
|
| 148 |
-
# Check if the file type is allowed (you may want to add more types)
|
| 149 |
-
allowed_extensions = {'png', 'jpg', 'jpeg', 'pdf'}
|
| 150 |
-
if not file.filename.lower().endswith(tuple(allowed_extensions)):
|
| 151 |
-
return render_template("index.html", error="Invalid file type. Please upload an image or PDF file.")
|
| 152 |
-
|
| 153 |
try:
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
upload_dir = app.config['UPLOAD_FOLDER']
|
| 156 |
os.makedirs(upload_dir, exist_ok=True)
|
| 157 |
|
| 158 |
-
# Secure the filename and save the file
|
| 159 |
filename = secure_filename(file.filename)
|
| 160 |
image_path = os.path.join(upload_dir, filename)
|
| 161 |
file.save(image_path)
|
| 162 |
|
| 163 |
-
#
|
|
|
|
|
|
|
| 164 |
try:
|
|
|
|
| 165 |
gemini_output = process_certificate(image_path, cert_name)
|
|
|
|
| 166 |
return render_template("index.html", gemini_output=gemini_output)
|
| 167 |
except Exception as e:
|
|
|
|
| 168 |
return render_template("index.html", error=f"Error processing certificate: {str(e)}")
|
| 169 |
|
| 170 |
except Exception as e:
|
|
|
|
| 171 |
return render_template("index.html", error=f"Error saving file: {str(e)}")
|
| 172 |
|
| 173 |
return render_template("index.html")
|
|
|
|
| 133 |
@app.route("/", methods=["GET", "POST"])
|
| 134 |
def home():
|
| 135 |
if request.method == "POST":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
try:
|
| 137 |
+
cert_name = "Affiliation Certificate"
|
| 138 |
+
|
| 139 |
+
# Debug print
|
| 140 |
+
print("File received in request:", request.files)
|
| 141 |
+
|
| 142 |
+
if 'certificate' not in request.files:
|
| 143 |
+
return render_template("index.html", error="No file part in the request")
|
| 144 |
+
|
| 145 |
+
file = request.files['certificate']
|
| 146 |
+
|
| 147 |
+
if file.filename == '':
|
| 148 |
+
return render_template("index.html", error="No file selected")
|
| 149 |
+
|
| 150 |
+
# Debug print
|
| 151 |
+
print("Processing file:", file.filename)
|
| 152 |
+
|
| 153 |
+
allowed_extensions = {'png', 'jpg', 'jpeg', 'pdf'}
|
| 154 |
+
if not file.filename.lower().endswith(tuple(allowed_extensions)):
|
| 155 |
+
return render_template("index.html", error="Invalid file type. Please upload an image or PDF file.")
|
| 156 |
+
|
| 157 |
upload_dir = app.config['UPLOAD_FOLDER']
|
| 158 |
os.makedirs(upload_dir, exist_ok=True)
|
| 159 |
|
|
|
|
| 160 |
filename = secure_filename(file.filename)
|
| 161 |
image_path = os.path.join(upload_dir, filename)
|
| 162 |
file.save(image_path)
|
| 163 |
|
| 164 |
+
# Debug print
|
| 165 |
+
print("File saved at:", image_path)
|
| 166 |
+
|
| 167 |
try:
|
| 168 |
+
print("Starting Gemini processing...")
|
| 169 |
gemini_output = process_certificate(image_path, cert_name)
|
| 170 |
+
print("Gemini processing completed")
|
| 171 |
return render_template("index.html", gemini_output=gemini_output)
|
| 172 |
except Exception as e:
|
| 173 |
+
print(f"Error in Gemini processing: {str(e)}")
|
| 174 |
return render_template("index.html", error=f"Error processing certificate: {str(e)}")
|
| 175 |
|
| 176 |
except Exception as e:
|
| 177 |
+
print(f"Error in file handling: {str(e)}")
|
| 178 |
return render_template("index.html", error=f"Error saving file: {str(e)}")
|
| 179 |
|
| 180 |
return render_template("index.html")
|