woletee
this is the update with adding the port number so that the application can be displayed on the hugging face
398a491
| from flask import Flask, render_template, request | |
| from markupsafe import Markup | |
| import os | |
| import glob | |
| from gp1 import run_task # Make sure run_task returns all required data | |
| app = Flask(__name__) | |
| # Helper function to render a grid as HTML using CSS classes | |
| def render_grid(grid): | |
| html = '<div class="grid">' | |
| for row in grid: | |
| html += '<div class="grid-row">' | |
| for cell in row: | |
| html += f'<div class="cell color-{cell}"></div>' | |
| html += '</div>' | |
| html += '</div>' | |
| return Markup(html) | |
| def index(): | |
| task_folder = './training/' | |
| task_files = sorted(glob.glob(os.path.join(task_folder, '*.json'))) | |
| task_names = [os.path.basename(f) for f in task_files] | |
| result = None | |
| if request.method == 'POST': | |
| selected_task = request.form.get('task') | |
| task_path = os.path.join(task_folder, selected_task) | |
| # run_task should return: best_program, correct, input_grid, target_grid, output_grid | |
| best_program, correct, input_grid, target_grid, output_grid = run_task(task_path) | |
| result = { | |
| "task": selected_task, | |
| "program": best_program, | |
| "success": correct, | |
| "input": input_grid, | |
| "target": target_grid, | |
| "output": output_grid | |
| } | |
| return render_template('index.html', tasks=task_names, result=result, render_grid=render_grid) | |
| import os | |
| port = int(os.environ.get("PORT", 7860)) | |
| app.run(host='0.0.0.0', port=port) | |
| if __name__ == '__main__': | |
| import os | |
| port = int(os.environ.get("PORT", 7860)) | |
| app.run(host='0.0.0.0', port=port) | |