MySafeCode commited on
Commit
a2427a6
·
verified ·
1 Parent(s): 088ce17

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from flask import Flask, request, jsonify
3
+ from flask_cors import CORS
4
+ import requests
5
+
6
+ app = Flask(__name__)
7
+ CORS(app) # Enable CORS for all routes
8
+
9
+ # Load API key from Hugging Face secrets
10
+ API_KEY = os.environ.get("PIXAZO_API_KEY")
11
+
12
+ @app.route('/api/generate', methods=['POST'])
13
+ def generate_image():
14
+ try:
15
+ if not API_KEY:
16
+ return jsonify({"error": "API key not configured"}), 500
17
+
18
+ # Get data from frontend
19
+ data = request.json
20
+
21
+ # Call Pixazo API
22
+ headers = {
23
+ 'Content-Type': 'application/json',
24
+ 'Cache-Control': 'no-cache',
25
+ 'Ocp-Apim-Subscription-Key': API_KEY,
26
+ }
27
+
28
+ response = requests.post(
29
+ 'https://gateway.pixazo.ai/flux-1-schnell/v1/getData',
30
+ json=data,
31
+ headers=headers,
32
+ timeout=30
33
+ )
34
+
35
+ # Return the response from Pixazo
36
+ return jsonify(response.json()), response.status_code
37
+
38
+ except Exception as e:
39
+ return jsonify({"error": str(e)}), 500
40
+
41
+ if __name__ == '__main__':
42
+ app.run(host='0.0.0.0', port=7860)