Spaces:
Running
Running
Update utility/image_generator.py
Browse files- utility/image_generator.py +12 -1
utility/image_generator.py
CHANGED
@@ -27,12 +27,23 @@ def generate_image_prompts(script):
|
|
27 |
|
28 |
return prompts
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def generate_images(prompts):
|
31 |
image_files = []
|
32 |
for idx, prompt in enumerate(prompts):
|
33 |
print(f"Generating image for prompt: {prompt}")
|
34 |
# Ensure the prompt is processed on the correct device
|
35 |
-
image =
|
36 |
filename = f"generated_image_{idx}.png"
|
37 |
image.save(filename)
|
38 |
image_files.append(filename)
|
|
|
27 |
|
28 |
return prompts
|
29 |
|
30 |
+
def hf_pipeline(prompt):
|
31 |
+
API_URL = "https://api-inference.huggingface.co/models/Shakker-Labs/AWPortrait-FL"
|
32 |
+
headers = {"Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}"}
|
33 |
+
|
34 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
|
35 |
+
|
36 |
+
if response.status_code == 200:
|
37 |
+
return Image.open(io.BytesIO(response.content)) # Return the image directly
|
38 |
+
else:
|
39 |
+
raise Exception(f"Failed to generate image. Status code: {response.status_code}, {response.text}")
|
40 |
+
|
41 |
def generate_images(prompts):
|
42 |
image_files = []
|
43 |
for idx, prompt in enumerate(prompts):
|
44 |
print(f"Generating image for prompt: {prompt}")
|
45 |
# Ensure the prompt is processed on the correct device
|
46 |
+
image = hf_pipeline(prompt).images[0]
|
47 |
filename = f"generated_image_{idx}.png"
|
48 |
image.save(filename)
|
49 |
image_files.append(filename)
|