Spaces:
Sleeping
Sleeping
Arjun Singh
commited on
Commit
·
2a4aef9
1
Parent(s):
e2feb9e
Added random seed
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from PIL import Image
|
|
| 5 |
import io
|
| 6 |
import json
|
| 7 |
import os
|
|
|
|
| 8 |
#from dotenv import load_dotenv
|
| 9 |
|
| 10 |
#dotenv_path = '/.env'
|
|
@@ -14,7 +15,7 @@ import os
|
|
| 14 |
API_KEY = os.getenv('BASETEN_API_KEY')
|
| 15 |
API_url = os.getenv('BASETEN_COMFY_MODEL_URL')
|
| 16 |
|
| 17 |
-
def call_api_and_generate_image(negative_prompt, positive_prompt):
|
| 18 |
if not API_KEY:
|
| 19 |
return None, "Error: API key not found in environment variables. Please set BASETEN_API_KEY."
|
| 20 |
|
|
@@ -24,7 +25,8 @@ def call_api_and_generate_image(negative_prompt, positive_prompt):
|
|
| 24 |
json={
|
| 25 |
'workflow_values': {
|
| 26 |
'negative_prompt': negative_prompt,
|
| 27 |
-
'positive_prompt': positive_prompt
|
|
|
|
| 28 |
}
|
| 29 |
}
|
| 30 |
)
|
|
@@ -36,8 +38,9 @@ def call_api_and_generate_image(negative_prompt, positive_prompt):
|
|
| 36 |
return image, json.dumps(result, indent=2)
|
| 37 |
|
| 38 |
def generate_image(positive_prompt, negative_prompt):
|
|
|
|
| 39 |
try:
|
| 40 |
-
return call_api_and_generate_image(negative_prompt, positive_prompt)
|
| 41 |
except Exception as e:
|
| 42 |
return None, f"Error: {str(e)}"
|
| 43 |
|
|
|
|
| 5 |
import io
|
| 6 |
import json
|
| 7 |
import os
|
| 8 |
+
import numpy
|
| 9 |
#from dotenv import load_dotenv
|
| 10 |
|
| 11 |
#dotenv_path = '/.env'
|
|
|
|
| 15 |
API_KEY = os.getenv('BASETEN_API_KEY')
|
| 16 |
API_url = os.getenv('BASETEN_COMFY_MODEL_URL')
|
| 17 |
|
| 18 |
+
def call_api_and_generate_image(negative_prompt, positive_prompt,seed):
|
| 19 |
if not API_KEY:
|
| 20 |
return None, "Error: API key not found in environment variables. Please set BASETEN_API_KEY."
|
| 21 |
|
|
|
|
| 25 |
json={
|
| 26 |
'workflow_values': {
|
| 27 |
'negative_prompt': negative_prompt,
|
| 28 |
+
'positive_prompt': positive_prompt,
|
| 29 |
+
'seed': seed
|
| 30 |
}
|
| 31 |
}
|
| 32 |
)
|
|
|
|
| 38 |
return image, json.dumps(result, indent=2)
|
| 39 |
|
| 40 |
def generate_image(positive_prompt, negative_prompt):
|
| 41 |
+
seed = numpy.random.randint(0, 2**32 - 1)
|
| 42 |
try:
|
| 43 |
+
return call_api_and_generate_image(negative_prompt, positive_prompt,seed)
|
| 44 |
except Exception as e:
|
| 45 |
return None, f"Error: {str(e)}"
|
| 46 |
|