arshvir commited on
Commit
073316d
·
1 Parent(s): d8677ad

Fix indentation after NBSP cleanup in app.py

Browse files
__pycache__/app.cpython-311.pyc ADDED
Binary file (12 kB). View file
 
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import os
2
  import time
3
  from flask import Flask, render_template, request, jsonify, send_from_directory
4
  from werkzeug.utils import secure_filename
@@ -32,56 +32,56 @@ utilities_service = UtilitiesService()
32
 
33
  # --- Helpers ---
34
  def allowed_file(filename):
35
-     return (
36
- '.' in filename
37
- and filename.rsplit('.',1)[1].lower() in ALLOWED_EXTENSIONS
38
  )
39
 
40
  def get_file_path(filename):
41
-     return os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(filename))
42
 
43
  def generate_output_filename(original_filename, prefix="processed"):
44
-     timestamp = int(time.time())
45
-     name, ext = os.path.splitext(original_filename)
46
-     return f"{prefix}_{timestamp}_{name}{ext}"
47
 
48
  # --- Page Routes (Frontend) ---
49
 
50
  @app.route('/')
51
  def index():
52
-     return render_template('onboarding.html')
53
 
54
  @app.route('/studio')
55
  def studio():
56
-     return render_template('studio.html')
57
 
58
  @app.route('/vision')
59
  def vision():
60
-     return render_template('vision.html')
61
 
62
  @app.route('/ai-studio')
63
  def ai_studio():
64
-     return render_template('ai_studio.html')
65
 
66
  @app.route('/utilities')
67
  def utilities():
68
-     return render_template('utilities.html')
69
 
70
  @app.route('/about')
71
  def about():
72
-     return render_template('about.html')
73
 
74
  #@app.route('/products')
75
  #def products():
76
- #    return render_template('products.html')
77
 
78
  @app.route('/docs')
79
  def docs():
80
-     return render_template('docs.html')
81
 
82
  @app.route('/download')
83
  def download():
84
-     return render_template('download.html')
85
 
86
 
87
 
@@ -91,159 +91,160 @@ def download():
91
 
92
  @app.route('/api/upload', methods=['POST'])
93
  def upload_file():
94
-     if 'file' not in request.files:
95
-         return jsonify({'success': False, 'error': 'No file part'}), 400
96
-     
97
-     file = request.files['file']
98
-     if file.filename == '':
99
-         return jsonify({'success': False, 'error': 'No selected file'}), 400
100
-     
101
-     if file and allowed_file(file.filename):
102
-         # Create unique filename
103
-         filename = secure_filename(f"{int(time.time())}_{file.filename}")
104
-         filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
105
-         file.save(filepath)
106
-         
107
-         return jsonify({
108
-             'success': True,
109
-             'filename': filename,
110
-             'url': f"/static/uploads/{filename}"
111
-         })
112
-     
113
-     return jsonify({'success': False, 'error': 'Invalid file type'}), 400
114
 
115
  # --- API: Studio (Image Editing) ---
116
 
117
  @app.route('/api/process-studio', methods=['POST'])
118
  def process_studio():
119
-     try:
120
-         data = request.json
121
-         filename = data.get('filename')
122
-         options = data.get('options') # Contains brightness, contrast, filter, etc.
123
 
124
-         if not filename or not options:
125
-             return jsonify({'success': False, 'error': 'Missing parameters'}), 400
126
 
127
-         input_path = get_file_path(filename)
128
-         output_filename = generate_output_filename(filename, "edit")
129
-         output_path = os.path.join(app.config['UPLOAD_FOLDER'], output_filename)
130
 
131
-         # Call Service
132
-         success, result = studio_service.process_request(input_path, output_path, options)
133
 
134
-         if success:
135
-             return jsonify({
136
-                 'success': True, 
137
-                 'url': f"/static/uploads/{output_filename}", 
138
-                 'filename': output_filename
139
-             })
140
-         else:
141
-             return jsonify({'success': False, 'error': str(result)}), 500
142
 
143
-     except Exception as e:
144
-         return jsonify({'success': False, 'error': str(e)}), 500
145
 
146
  # --- API: Vision (YOLO, BG Remove) ---
147
 
148
  @app.route('/api/process-vision', methods=['POST'])
149
  def process_vision():
150
-     try:
151
-         data = request.json
152
-         filename = data.get('filename')
153
-         task = data.get('task')
154
-         # extra options like 'color' for bg replacement or 'value' for blur intensity
155
-         options = data 
156
-
157
-         if not filename or not task:
158
-             return jsonify({'success': False, 'error': 'Missing parameters'}), 400
159
-
160
-         input_path = get_file_path(filename)
161
-         output_filename = generate_output_filename(filename, f"vision_{task}")
162
-         output_path = os.path.join(app.config['UPLOAD_FOLDER'], output_filename)
163
-
164
-         success, result_meta = vision_service.process_request(input_path, output_path, task, options)
165
-
166
-         if success:
167
-             response = {
168
-                 'success': True,
169
-                 'url': f"/static/uploads/{output_filename}",
170
-                 'filename': output_filename
171
-             }
172
-             # Add detections if they exist (for YOLO)
173
-             if isinstance(result_meta, dict) and 'detections' in result_meta:
174
-                 response['detections'] = result_meta['detections']
175
-             return jsonify(response)
176
-         else:
177
-             return jsonify({'success': False, 'error': str(result_meta)}), 500
178
-
179
-     except Exception as e:
180
-         return jsonify({'success': False, 'error': str(e)}), 500
181
 
182
  # --- API: AI Studio (Colorize, Upscale) ---
183
 
184
  @app.route('/api/process-ai', methods=['POST'])
185
  def process_ai():
186
-     try:
187
-         data = request.json
188
-         filename = data.get('filename')
189
-         task = data.get('task')
190
 
191
-         if not filename or not task:
192
-             return jsonify({'success': False, 'error': 'Missing parameters'}), 400
193
 
194
-         input_path = get_file_path(filename)
195
-         output_filename = generate_output_filename(filename, f"ai_{task}")
196
-         output_path = os.path.join(app.config['UPLOAD_FOLDER'], output_filename)
197
 
198
-         success, result = ai_service.process_request(input_path, output_path, task)
199
 
200
-         if success:
201
-             return jsonify({
202
-                 'success': True, 
203
-                 'url': f"/static/uploads/{output_filename}", 
204
-                 'filename': output_filename
205
-             })
206
-         else:
207
-             return jsonify({'success': False, 'error': str(result)}), 500
208
 
209
-     except Exception as e:
210
-         return jsonify({'success': False, 'error': str(e)}), 500
211
 
212
  # --- API: Utilities (Convert, Resize) ---
213
 
214
  @app.route('/api/process-utility', methods=['POST'])
215
  def process_utility():
216
-     try:
217
-         data = request.json
218
-         filename = data.get('filename')
219
-         # Service handles specific logic internally
220
-         
221
-         input_path = get_file_path(filename)
222
-         # Output directory is passed so service can generate name based on format
223
-         output_dir = app.config['UPLOAD_FOLDER']
224
-
225
-         success, result = utilities_service.process_request(input_path, output_dir, data)
226
-
227
-         if success:
228
-             if data.get('action') == 'metadata':
229
-                 return jsonify({'success': True, 'metadata': result})
230
-             else:
231
-                 return jsonify({
232
-                     'success': True, 
233
-                     'url': f"/static/uploads/{result}", 
234
-                     'filename': result
235
-                 })
236
-         else:
237
-             return jsonify({'success': False, 'error': str(result)}), 500
238
-
239
-     except Exception as e:
240
-         return jsonify({'success': False, 'error': str(e)}), 500
241
 
242
  # --- Serve Static Files (Images) ---
243
  @app.route('/static/uploads/<filename>')
244
  def uploaded_file(filename):
245
-     return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
246
 
247
  if __name__ == '__main__':
248
-     print("🚀 Radiant AI Server (local dev)")
249
-     app.run(host='0.0.0.0', port=7860)
 
 
1
+ import os
2
  import time
3
  from flask import Flask, render_template, request, jsonify, send_from_directory
4
  from werkzeug.utils import secure_filename
 
32
 
33
  # --- Helpers ---
34
  def allowed_file(filename):
35
+ return (
36
+ '.' in filename and
37
+ filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
38
  )
39
 
40
  def get_file_path(filename):
41
+ return os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(filename))
42
 
43
  def generate_output_filename(original_filename, prefix="processed"):
44
+ timestamp = int(time.time())
45
+ name, ext = os.path.splitext(original_filename)
46
+ return f"{prefix}_{timestamp}_{name}{ext}"
47
 
48
  # --- Page Routes (Frontend) ---
49
 
50
  @app.route('/')
51
  def index():
52
+ return render_template('onboarding.html')
53
 
54
  @app.route('/studio')
55
  def studio():
56
+ return render_template('studio.html')
57
 
58
  @app.route('/vision')
59
  def vision():
60
+ return render_template('vision.html')
61
 
62
  @app.route('/ai-studio')
63
  def ai_studio():
64
+ return render_template('ai_studio.html')
65
 
66
  @app.route('/utilities')
67
  def utilities():
68
+ return render_template('utilities.html')
69
 
70
  @app.route('/about')
71
  def about():
72
+ return render_template('about.html')
73
 
74
  #@app.route('/products')
75
  #def products():
76
+ # return render_template('products.html')
77
 
78
  @app.route('/docs')
79
  def docs():
80
+ return render_template('docs.html')
81
 
82
  @app.route('/download')
83
  def download():
84
+ return render_template('download.html')
85
 
86
 
87
 
 
91
 
92
  @app.route('/api/upload', methods=['POST'])
93
  def upload_file():
94
+ if 'file' not in request.files:
95
+ return jsonify({'success': False, 'error': 'No file part'}), 400
96
+
97
+ file = request.files['file']
98
+ if file.filename == '':
99
+ return jsonify({'success': False, 'error': 'No selected file'}), 400
100
+
101
+ if file and allowed_file(file.filename):
102
+ # Create unique filename
103
+ filename = secure_filename(f"{int(time.time())}_{file.filename}")
104
+ filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
105
+ file.save(filepath)
106
+
107
+ return jsonify({
108
+ 'success': True,
109
+ 'filename': filename,
110
+ 'url': f"/static/uploads/{filename}"
111
+ })
112
+
113
+ return jsonify({'success': False, 'error': 'Invalid file type'}), 400
114
 
115
  # --- API: Studio (Image Editing) ---
116
 
117
  @app.route('/api/process-studio', methods=['POST'])
118
  def process_studio():
119
+ try:
120
+ data = request.json
121
+ filename = data.get('filename')
122
+ options = data.get('options') # Contains brightness, contrast, filter, etc.
123
 
124
+ if not filename or not options:
125
+ return jsonify({'success': False, 'error': 'Missing parameters'}), 400
126
 
127
+ input_path = get_file_path(filename)
128
+ output_filename = generate_output_filename(filename, "edit")
129
+ output_path = os.path.join(app.config['UPLOAD_FOLDER'], output_filename)
130
 
131
+ # Call Service
132
+ success, result = studio_service.process_request(input_path, output_path, options)
133
 
134
+ if success:
135
+ return jsonify({
136
+ 'success': True,
137
+ 'url': f"/static/uploads/{output_filename}",
138
+ 'filename': output_filename
139
+ })
140
+ else:
141
+ return jsonify({'success': False, 'error': str(result)}), 500
142
 
143
+ except Exception as e:
144
+ return jsonify({'success': False, 'error': str(e)}), 500
145
 
146
  # --- API: Vision (YOLO, BG Remove) ---
147
 
148
  @app.route('/api/process-vision', methods=['POST'])
149
  def process_vision():
150
+ try:
151
+ data = request.json
152
+ filename = data.get('filename')
153
+ task = data.get('task')
154
+ # extra options like 'color' for bg replacement or 'value' for blur intensity
155
+ options = data
156
+
157
+ if not filename or not task:
158
+ return jsonify({'success': False, 'error': 'Missing parameters'}), 400
159
+
160
+ input_path = get_file_path(filename)
161
+ output_filename = generate_output_filename(filename, f"vision_{task}")
162
+ output_path = os.path.join(app.config['UPLOAD_FOLDER'], output_filename)
163
+
164
+ success, result_meta = vision_service.process_request(input_path, output_path, task, options)
165
+
166
+ if success:
167
+ response = {
168
+ 'success': True,
169
+ 'url': f"/static/uploads/{output_filename}",
170
+ 'filename': output_filename
171
+ }
172
+ # Add detections if they exist (for YOLO)
173
+ if isinstance(result_meta, dict) and 'detections' in result_meta:
174
+ response['detections'] = result_meta['detections']
175
+ return jsonify(response)
176
+ else:
177
+ return jsonify({'success': False, 'error': str(result_meta)}), 500
178
+
179
+ except Exception as e:
180
+ return jsonify({'success': False, 'error': str(e)}), 500
181
 
182
  # --- API: AI Studio (Colorize, Upscale) ---
183
 
184
  @app.route('/api/process-ai', methods=['POST'])
185
  def process_ai():
186
+ try:
187
+ data = request.json
188
+ filename = data.get('filename')
189
+ task = data.get('task')
190
 
191
+ if not filename or not task:
192
+ return jsonify({'success': False, 'error': 'Missing parameters'}), 400
193
 
194
+ input_path = get_file_path(filename)
195
+ output_filename = generate_output_filename(filename, f"ai_{task}")
196
+ output_path = os.path.join(app.config['UPLOAD_FOLDER'], output_filename)
197
 
198
+ success, result = ai_service.process_request(input_path, output_path, task)
199
 
200
+ if success:
201
+ return jsonify({
202
+ 'success': True,
203
+ 'url': f"/static/uploads/{output_filename}",
204
+ 'filename': output_filename
205
+ })
206
+ else:
207
+ return jsonify({'success': False, 'error': str(result)}), 500
208
 
209
+ except Exception as e:
210
+ return jsonify({'success': False, 'error': str(e)}), 500
211
 
212
  # --- API: Utilities (Convert, Resize) ---
213
 
214
  @app.route('/api/process-utility', methods=['POST'])
215
  def process_utility():
216
+ try:
217
+ data = request.json
218
+ filename = data.get('filename')
219
+ # Service handles specific logic internally
220
+
221
+ input_path = get_file_path(filename)
222
+ # Output directory is passed so service can generate name based on format
223
+ output_dir = app.config['UPLOAD_FOLDER']
224
+
225
+ success, result = utilities_service.process_request(input_path, output_dir, data)
226
+
227
+ if success:
228
+ if data.get('action') == 'metadata':
229
+ return jsonify({'success': True, 'metadata': result})
230
+ else:
231
+ return jsonify({
232
+ 'success': True,
233
+ 'url': f"/static/uploads/{result}",
234
+ 'filename': result
235
+ })
236
+ else:
237
+ return jsonify({'success': False, 'error': str(result)}), 500
238
+
239
+ except Exception as e:
240
+ return jsonify({'success': False, 'error': str(e)}), 500
241
 
242
  # --- Serve Static Files (Images) ---
243
  @app.route('/static/uploads/<filename>')
244
  def uploaded_file(filename):
245
+ return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
246
 
247
  if __name__ == '__main__':
248
+ print("🚀 Radiant AI Server (local dev)")
249
+ app.run(host='0.0.0.0', port=7860)
250
+
services/ai_studio.py CHANGED
@@ -1,4 +1,4 @@
1
- import os
2
  import cv2
3
  import numpy as np
4
  from cv2 import dnn_superres
@@ -110,4 +110,5 @@ class AIStudioService:
110
  result = cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 21)
111
 
112
  cv2.imwrite(output_path, result)
113
- return True, output_path
 
 
1
+ import os
2
  import cv2
3
  import numpy as np
4
  from cv2 import dnn_superres
 
110
  result = cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 21)
111
 
112
  cv2.imwrite(output_path, result)
113
+ return True, output_path
114
+
services/studio.py CHANGED
@@ -1,4 +1,4 @@
1
- import cv2
2
  import numpy as np
3
 
4
  class StudioService:
@@ -108,4 +108,5 @@ class StudioService:
108
  return cv2.bitwise_and(color, cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR))
109
 
110
  # Fallback for others (summer, winter, etc) or return original
111
- return img
 
 
1
+ import cv2
2
  import numpy as np
3
 
4
  class StudioService:
 
108
  return cv2.bitwise_and(color, cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR))
109
 
110
  # Fallback for others (summer, winter, etc) or return original
111
+ return img
112
+
services/utilities.py CHANGED
@@ -1,4 +1,4 @@
1
- import os
2
  from PIL import Image, ExifTags
3
 
4
  class UtilitiesService:
@@ -126,4 +126,5 @@ class UtilitiesService:
126
  if len(exif_data) <= 3: # Only basic info found
127
  exif_data['Note'] = "No advanced EXIF data found in this image."
128
 
129
- return exif_data
 
 
1
+ import os
2
  from PIL import Image, ExifTags
3
 
4
  class UtilitiesService:
 
126
  if len(exif_data) <= 3: # Only basic info found
127
  exif_data['Note'] = "No advanced EXIF data found in this image."
128
 
129
+ return exif_data
130
+
services/vision.py CHANGED
@@ -1,4 +1,4 @@
1
- import os
2
  import cv2
3
  import numpy as np
4
  from rembg import remove
@@ -176,4 +176,5 @@ class VisionService:
176
  upper = int(min(255, (1.0 + sigma) * v))
177
 
178
  edges = cv2.Canny(blurred, lower, upper)
179
- return cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
 
 
1
+ import os
2
  import cv2
3
  import numpy as np
4
  from rembg import remove
 
176
  upper = int(min(255, (1.0 + sigma) * v))
177
 
178
  edges = cv2.Canny(blurred, lower, upper)
179
+ return cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
180
+