Update app.py
Browse files
app.py
CHANGED
|
@@ -32,10 +32,6 @@ logger = logging.getLogger(__name__)
|
|
| 32 |
app = Flask(__name__)
|
| 33 |
init_db(app)
|
| 34 |
|
| 35 |
-
# Static dosyalar için route
|
| 36 |
-
@app.route('/assets/images/<filename>')
|
| 37 |
-
def serve_image(filename):
|
| 38 |
-
return send_from_directory('assets/images', filename)
|
| 39 |
|
| 40 |
# Ana sayfa
|
| 41 |
@app.route('/')
|
|
@@ -62,26 +58,6 @@ def handle_get_generate_list():
|
|
| 62 |
"error": str(e)
|
| 63 |
}), 500
|
| 64 |
|
| 65 |
-
@app.route('/generate_list', methods=['POST'])
|
| 66 |
-
def handle_create_generate_item():
|
| 67 |
-
try:
|
| 68 |
-
data = request.get_json()
|
| 69 |
-
if not all(k in data for k in ['title', 'image_url', 'contour']):
|
| 70 |
-
return jsonify({'error': 'Eksik alanlar'}), 400
|
| 71 |
-
|
| 72 |
-
db = get_db()
|
| 73 |
-
item_id = add_to_generate_list(
|
| 74 |
-
db,
|
| 75 |
-
data['title'],
|
| 76 |
-
data['image_url'],
|
| 77 |
-
int(data['contour'])
|
| 78 |
-
)
|
| 79 |
-
return jsonify({'id': item_id}), 201
|
| 80 |
-
except ValueError:
|
| 81 |
-
return jsonify({'error': 'Geçersiz contour değeri'}), 400
|
| 82 |
-
except Exception as e:
|
| 83 |
-
logger.error(f"Hata: {str(e)}")
|
| 84 |
-
return jsonify({'error': str(e)}), 500
|
| 85 |
|
| 86 |
# Anime dönüştürme endpoint'i
|
| 87 |
@app.route('/demo_generate/generate', methods=['POST'])
|
|
@@ -163,50 +139,11 @@ def add_user_route():
|
|
| 163 |
from post_methods import add_user
|
| 164 |
return add_user()
|
| 165 |
|
| 166 |
-
@app.route('/consume/<string:udid>', methods=['POST'])
|
| 167 |
-
def consume_user_route(udid):
|
| 168 |
-
from consume_method import consume_user
|
| 169 |
-
return consume_user(udid)
|
| 170 |
|
| 171 |
# Kapatma
|
| 172 |
@app.teardown_appcontext
|
| 173 |
def shutdown_session(exception=None):
|
| 174 |
close_db()
|
| 175 |
|
| 176 |
-
if __name__ == '__main__':
|
| 177 |
-
db_path = get_db_path()
|
| 178 |
-
os.makedirs(os.path.dirname(db_path), exist_ok=True)
|
| 179 |
-
|
| 180 |
-
# Default modelleri ekle
|
| 181 |
-
with app.app_context():
|
| 182 |
-
db = get_db()
|
| 183 |
-
|
| 184 |
-
# Tablo yoksa oluştur ve default verileri ekle
|
| 185 |
-
cursor = db.cursor()
|
| 186 |
-
cursor.execute('''
|
| 187 |
-
CREATE TABLE IF NOT EXISTS generate_list (
|
| 188 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 189 |
-
title TEXT NOT NULL,
|
| 190 |
-
image_url TEXT NOT NULL,
|
| 191 |
-
contour INTEGER NOT NULL,
|
| 192 |
-
item_order INTEGER NOT NULL DEFAULT 0
|
| 193 |
-
)
|
| 194 |
-
''')
|
| 195 |
-
|
| 196 |
-
cursor.execute('SELECT COUNT(*) FROM generate_list')
|
| 197 |
-
if cursor.fetchone()[0] == 0:
|
| 198 |
-
default_models = [
|
| 199 |
-
("REALISTIC", "assets/images/0.jpg", 0, 0),
|
| 200 |
-
("DRAWING", "assets/images/1.jpg", 10, 1),
|
| 201 |
-
("TOY FIGURE", "assets/images/2.jpg", 10, 2),
|
| 202 |
-
("3D", "assets/images/3.jpg", 40, 3),
|
| 203 |
-
("ANIMATION", "assets/images/4.jpg", 50, 4)
|
| 204 |
-
]
|
| 205 |
-
cursor.executemany('''
|
| 206 |
-
INSERT INTO generate_list (title, image_url, contour, item_order)
|
| 207 |
-
VALUES (?, ?, ?, ?)
|
| 208 |
-
''', default_models)
|
| 209 |
-
|
| 210 |
-
db.commit()
|
| 211 |
|
| 212 |
-
|
|
|
|
| 32 |
app = Flask(__name__)
|
| 33 |
init_db(app)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# Ana sayfa
|
| 37 |
@app.route('/')
|
|
|
|
| 58 |
"error": str(e)
|
| 59 |
}), 500
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
# Anime dönüştürme endpoint'i
|
| 63 |
@app.route('/demo_generate/generate', methods=['POST'])
|
|
|
|
| 139 |
from post_methods import add_user
|
| 140 |
return add_user()
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
# Kapatma
|
| 144 |
@app.teardown_appcontext
|
| 145 |
def shutdown_session(exception=None):
|
| 146 |
close_db()
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
+
app.run(host='0.0.0.0', port=7860, debug=True)
|