Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,8 +140,18 @@ def visualize_path(start_x, start_y, goal_x, goal_y, algorithm):
|
|
| 140 |
color = '#FF0000'
|
| 141 |
title = "Bellman-Ford Algorithm"
|
| 142 |
|
| 143 |
-
# Arka plan resmini yükle
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
bg_width, bg_height = bg_img.size
|
| 146 |
|
| 147 |
# Her hücrenin piksel boyutu
|
|
@@ -209,22 +219,28 @@ def index():
|
|
| 209 |
|
| 210 |
@app.route('/find_path', methods=['POST'])
|
| 211 |
def find_path():
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
if __name__ == "__main__":
|
| 230 |
-
app.run(host="0.0.0.0", port=7860, debug=
|
|
|
|
| 140 |
color = '#FF0000'
|
| 141 |
title = "Bellman-Ford Algorithm"
|
| 142 |
|
| 143 |
+
# Arka plan resmini yükle - absolute path
|
| 144 |
+
import os
|
| 145 |
+
base_dir = os.path.dirname(os.path.abspath(__file__))
|
| 146 |
+
img_path = os.path.join(base_dir, 'static', 'images', 'map.jpg')
|
| 147 |
+
|
| 148 |
+
if not os.path.exists(img_path):
|
| 149 |
+
print(f"Image not found at: {img_path}")
|
| 150 |
+
print(f"Current dir: {os.getcwd()}")
|
| 151 |
+
print(f"Files in current dir: {os.listdir('.')}")
|
| 152 |
+
raise FileNotFoundError(f"Map image not found at {img_path}")
|
| 153 |
+
|
| 154 |
+
bg_img = Image.open(img_path)
|
| 155 |
bg_width, bg_height = bg_img.size
|
| 156 |
|
| 157 |
# Her hücrenin piksel boyutu
|
|
|
|
| 219 |
|
| 220 |
@app.route('/find_path', methods=['POST'])
|
| 221 |
def find_path():
|
| 222 |
+
try:
|
| 223 |
+
data = request.json
|
| 224 |
+
start_x = int(data['start_x'])
|
| 225 |
+
start_y = int(data['start_y'])
|
| 226 |
+
goal_x = int(data['goal_x'])
|
| 227 |
+
goal_y = int(data['goal_y'])
|
| 228 |
+
algorithm = data['algorithm']
|
| 229 |
+
|
| 230 |
+
img = visualize_path(start_x, start_y, goal_x, goal_y, algorithm)
|
| 231 |
+
|
| 232 |
+
# PIL Image'i base64'e çevir
|
| 233 |
+
buf = io.BytesIO()
|
| 234 |
+
img.save(buf, format='PNG')
|
| 235 |
+
buf.seek(0)
|
| 236 |
+
img_base64 = base64.b64encode(buf.getvalue()).decode('utf-8')
|
| 237 |
+
|
| 238 |
+
return jsonify({'image': f'data:image/png;base64,{img_base64}'})
|
| 239 |
+
except Exception as e:
|
| 240 |
+
print(f"Error: {str(e)}")
|
| 241 |
+
import traceback
|
| 242 |
+
traceback.print_exc()
|
| 243 |
+
return jsonify({'error': str(e)}), 500
|
| 244 |
|
| 245 |
if __name__ == "__main__":
|
| 246 |
+
app.run(host="0.0.0.0", port=7860, debug=True)
|