Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,23 @@
|
|
|
|
|
|
|
|
|
|
1 |
from diffusers import DiffusionPipeline
|
2 |
import torch
|
3 |
-
import matplotlib.pyplot as plt
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
|
8 |
# Charger le modèle
|
9 |
-
|
10 |
-
|
11 |
-
# Définir le prompt
|
12 |
-
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
|
13 |
|
14 |
-
#
|
15 |
-
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
+
from fastapi import FastAPI
|
4 |
+
from pydantic import BaseModel
|
5 |
from diffusers import DiffusionPipeline
|
6 |
import torch
|
|
|
7 |
|
8 |
+
# Initialiser l'application FastAPI
|
9 |
+
app = FastAPI()
|
10 |
|
11 |
# Charger le modèle
|
12 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
13 |
+
pipe = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4").to(device)
|
|
|
|
|
14 |
|
15 |
+
# Définir le modèle de requête
|
16 |
+
class Prompt(BaseModel):
|
17 |
+
text: str
|
18 |
|
19 |
+
@app.post("/generate")
|
20 |
+
def generate_image(prompt: Prompt):
|
21 |
+
image = pipe(prompt.text).images[0]
|
22 |
+
image.save("output.png") # Enregistrer l'image générée
|
23 |
+
return {"message": "Image generated", "image_path": "output.png"}
|