Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,7 +33,7 @@ def query(payload):
|
|
| 33 |
def generate_image():
|
| 34 |
try:
|
| 35 |
# Send a request to the Hugging Face model
|
| 36 |
-
image_bytes = query({"inputs": "
|
| 37 |
|
| 38 |
# Open the image
|
| 39 |
image = Image.open(io.BytesIO(image_bytes))
|
|
@@ -47,19 +47,3 @@ def generate_image():
|
|
| 47 |
|
| 48 |
except Exception as e:
|
| 49 |
raise HTTPException(status_code=500, detail=str(e))
|
| 50 |
-
|
| 51 |
-
# Event handler to generate the image on startup
|
| 52 |
-
@app.on_event("startup")
|
| 53 |
-
async def startup_event():
|
| 54 |
-
try:
|
| 55 |
-
# Automatically call the generate image logic on startup
|
| 56 |
-
print("Generating image on startup...")
|
| 57 |
-
image_bytes = query({"inputs": "dog with cat"})
|
| 58 |
-
|
| 59 |
-
# Save the image locally as 'generated_image.png' for verification
|
| 60 |
-
with open("generated_image.png", "wb") as f:
|
| 61 |
-
f.write(image_bytes)
|
| 62 |
-
print("Image generated and saved as 'generated_image.png'.")
|
| 63 |
-
|
| 64 |
-
except Exception as e:
|
| 65 |
-
print(f"Error during image generation: {e}")
|
|
|
|
| 33 |
def generate_image():
|
| 34 |
try:
|
| 35 |
# Send a request to the Hugging Face model
|
| 36 |
+
image_bytes = query({"inputs": "cat with dog"})
|
| 37 |
|
| 38 |
# Open the image
|
| 39 |
image = Image.open(io.BytesIO(image_bytes))
|
|
|
|
| 47 |
|
| 48 |
except Exception as e:
|
| 49 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|