Update myapp.py
Browse files
myapp.py
CHANGED
@@ -58,11 +58,11 @@ async def infer(client, prompt, seed=1, timeout=inference_timeout, model="prompt
|
|
58 |
@myapp.route('/generate_api', methods=['POST'])
|
59 |
def generate_api():
|
60 |
data = request.get_json()
|
61 |
-
|
62 |
# Extract required fields from the request
|
63 |
prompt = data.get('prompt', '')
|
64 |
seed = data.get('seed', 1)
|
65 |
-
model_name = data.get('model', 'prompthero/openjourney-v4') # Default
|
66 |
|
67 |
if not prompt:
|
68 |
return jsonify({"error": "Prompt is required"}), 400
|
@@ -74,7 +74,7 @@ def generate_api():
|
|
74 |
|
75 |
try:
|
76 |
# Create a generic InferenceClient for the model
|
77 |
-
client = InferenceClient(token=HF_TOKEN)
|
78 |
|
79 |
# Call the async inference function
|
80 |
result_path = asyncio.run(infer(client, prompt, seed, model=model))
|
@@ -83,6 +83,7 @@ def generate_api():
|
|
83 |
else:
|
84 |
return jsonify({"error": "Failed to generate image"}), 500
|
85 |
except Exception as e:
|
|
|
86 |
return jsonify({"error": str(e)}), 500
|
87 |
|
88 |
# Add this block to make sure your app runs when called
|
|
|
58 |
@myapp.route('/generate_api', methods=['POST'])
|
59 |
def generate_api():
|
60 |
data = request.get_json()
|
61 |
+
|
62 |
# Extract required fields from the request
|
63 |
prompt = data.get('prompt', '')
|
64 |
seed = data.get('seed', 1)
|
65 |
+
model_name = data.get('model', 'prompthero/openjourney-v4') # Default model
|
66 |
|
67 |
if not prompt:
|
68 |
return jsonify({"error": "Prompt is required"}), 400
|
|
|
74 |
|
75 |
try:
|
76 |
# Create a generic InferenceClient for the model
|
77 |
+
client = InferenceClient(token=HF_TOKEN)
|
78 |
|
79 |
# Call the async inference function
|
80 |
result_path = asyncio.run(infer(client, prompt, seed, model=model))
|
|
|
83 |
else:
|
84 |
return jsonify({"error": "Failed to generate image"}), 500
|
85 |
except Exception as e:
|
86 |
+
print(f"Error in generate_api: {str(e)}") # Log the error
|
87 |
return jsonify({"error": str(e)}), 500
|
88 |
|
89 |
# Add this block to make sure your app runs when called
|