Irfanarshad commited on
Commit
bebe01a
·
verified ·
1 Parent(s): 29101b8

Upload 7 files

Browse files
Files changed (7) hide show
  1. Dockerfile +0 -0
  2. app.py +64 -0
  3. requirements.txt +0 -0
  4. runtime.txt +1 -0
  5. sketch_processor.py +55 -0
  6. static.zip +3 -0
  7. templates.zip +3 -0
Dockerfile ADDED
File without changes
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ from flask import Flask, render_template, request, send_file, jsonify
4
+ from werkzeug.utils import secure_filename
5
+ import uuid
6
+
7
+ # Get the absolute path to the project root
8
+ PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
9
+
10
+ app = Flask(__name__)
11
+ app.config['UPLOAD_FOLDER'] = os.path.join(PROJECT_ROOT, 'static', 'uploads')
12
+ app.config['OUTPUT_FOLDER'] = os.path.join(PROJECT_ROOT, 'static', 'outputs')
13
+
14
+ # Add project root to Python path
15
+ sys.path.append(PROJECT_ROOT)
16
+
17
+ try:
18
+ from sketch_processor import generate_all_sketches
19
+ print("✅ Import successful!")
20
+ except ImportError as e:
21
+ print(f"❌ Import error: {e}")
22
+ print("Python path:", sys.path)
23
+ print("Files in directory:", [f for f in os.listdir(PROJECT_ROOT) if f.endswith('.py')])
24
+ raise
25
+
26
+
27
+ @app.route('/')
28
+ def index():
29
+ return render_template('index.html')
30
+
31
+ @app.route('/upload', methods=['POST'])
32
+ def upload_file():
33
+ if 'file' not in request.files:
34
+ return jsonify({'error': 'No file uploaded'}), 400
35
+
36
+ file = request.files['file']
37
+ if file.filename == '':
38
+ return jsonify({'error': 'No file selected'}), 400
39
+
40
+ # Generate unique filename
41
+ unique_id = str(uuid.uuid4())[:8]
42
+ filename = secure_filename(f"{unique_id}_{file.filename}")
43
+ input_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
44
+ file.save(input_path)
45
+
46
+ # Process image
47
+ output_files = generate_all_sketches(input_path, app.config['OUTPUT_FOLDER'], unique_id)
48
+
49
+ return jsonify({
50
+ 'original': f"static/uploads/{filename}",
51
+ 'sketches': {
52
+ 'classic': f"static/outputs/{unique_id}_classic.jpg",
53
+ 'light': f"static/outputs/{unique_id}_light.jpg",
54
+ 'dark': f"static/outputs/{unique_id}_dark.jpg",
55
+ 'edge': f"static/outputs/{unique_id}_edge.jpg"
56
+ }
57
+ })
58
+
59
+ @app.route('/download/<path:filename>')
60
+ def download_file(filename):
61
+ return send_file(filename, as_attachment=True)
62
+
63
+ if __name__ == "__main__":
64
+ app.run(host="0.0.0.0", port=7860)
requirements.txt ADDED
Binary file (108 Bytes). View file
 
runtime.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ python-3.10
sketch_processor.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import os
3
+
4
+ def classic_sketch(gray):
5
+ inverted = 255 - gray
6
+ blurred = cv2.GaussianBlur(inverted, (21, 21), 0)
7
+ inverted_blur = 255 - blurred
8
+ return cv2.divide(gray, inverted_blur, scale=256.0)
9
+
10
+ def light_sketch(gray):
11
+ inverted = 255 - gray
12
+ blurred = cv2.GaussianBlur(inverted, (31, 31), 0)
13
+ inverted_blur = 255 - blurred
14
+ return cv2.divide(gray, inverted_blur, scale=256.0)
15
+
16
+ def dark_sketch(gray):
17
+ inverted = 255 - gray
18
+ blurred = cv2.GaussianBlur(inverted, (11, 11), 0)
19
+ inverted_blur = 255 - blurred
20
+ return cv2.divide(gray, inverted_blur, scale=256.0)
21
+
22
+ def edge_sketch(gray):
23
+ return cv2.Canny(gray, 50, 150)
24
+
25
+ def generate_all_sketches(input_path, output_folder, unique_id):
26
+ # Verify input exists
27
+ if not os.path.exists(input_path):
28
+ raise FileNotFoundError(f"Input image not found at {input_path}")
29
+
30
+ image = cv2.imread(input_path)
31
+ if image is None:
32
+ raise ValueError("Failed to read image (might be corrupted or wrong format)")
33
+
34
+ # Process image
35
+ image = cv2.resize(image, (600, 600), interpolation=cv2.INTER_AREA)
36
+ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
37
+
38
+ sketches = {
39
+ 'classic': classic_sketch(gray),
40
+ 'light': light_sketch(gray),
41
+ 'dark': dark_sketch(gray),
42
+ 'edge': edge_sketch(gray)
43
+ }
44
+
45
+ # Ensure output directory exists
46
+ os.makedirs(output_folder, exist_ok=True)
47
+
48
+ # Save all sketches
49
+ output_files = {}
50
+ for name, img in sketches.items():
51
+ output_path = os.path.join(output_folder, f"{unique_id}_{name}.jpg")
52
+ cv2.imwrite(output_path, img)
53
+ output_files[name] = output_path
54
+
55
+ return output_files
static.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ad553e93fb3212ccec0116962519febefa1a8a3338651ac6cbaca50d5cf17d8e
3
+ size 5465086
templates.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ffa3289502d0b8feffd9e587ba4a245eeb28351412b71cb3bc75069515e7549
3
+ size 3774