Geek7 commited on
Commit
3806071
1 Parent(s): 21441f0

Update myapp.py

Browse files
Files changed (1) hide show
  1. myapp.py +4 -3
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 to "prompthero/openjourney-v4" if not provided
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) # Pass Hugging Face token if needed
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