seawolf2357
commited on
Commit
•
57dc30c
1
Parent(s):
98c1b1b
Update app.py
Browse files
app.py
CHANGED
@@ -51,13 +51,25 @@ class MyClient(discord.Client):
|
|
51 |
self.is_processing = False
|
52 |
|
53 |
async def generate_image(prompt):
|
54 |
-
"""
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
async def send_image(channel, image_path):
|
63 |
"""Send an image to the specified Discord channel."""
|
|
|
51 |
self.is_processing = False
|
52 |
|
53 |
async def generate_image(prompt):
|
54 |
+
"""
|
55 |
+
Generate an image using the Stable Diffusion model from Hugging Face.
|
56 |
+
"""
|
57 |
+
try:
|
58 |
+
# Using the Inference API correctly
|
59 |
+
response = hf_client(inputs={"prompt": prompt}, parameters={"num_images": 1}, model_id="stabilityai/stable-diffusion-3-medium")
|
60 |
+
image_data = response['images'][0] # Assuming the response contains image data
|
61 |
+
|
62 |
+
# Save image data to a file
|
63 |
+
image_bytes = io.BytesIO(base64.b64decode(image_data))
|
64 |
+
image = Image.open(image_bytes)
|
65 |
+
image_path = "output.png"
|
66 |
+
image.save(image_path)
|
67 |
+
return image_path
|
68 |
+
|
69 |
+
except Exception as e:
|
70 |
+
logging.error(f"Failed to generate image: {str(e)}")
|
71 |
+
return None
|
72 |
+
|
73 |
|
74 |
async def send_image(channel, image_path):
|
75 |
"""Send an image to the specified Discord channel."""
|