Spaces:
Runtime error
Runtime error
File size: 645 Bytes
d89926a 4453755 d89926a 4453755 d89926a 4453755 d89926a 4453755 d89926a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# app.py
from fastapi import FastAPI
from pydantic import BaseModel
from diffusers import DiffusionPipeline
import torch
# Initialiser l'application FastAPI
app = FastAPI()
# Charger le modèle
device = "cuda" if torch.cuda.is_available() else "cpu"
pipe = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4").to(device)
# Définir le modèle de requête
class Prompt(BaseModel):
text: str
@app.post("/generate")
def generate_image(prompt: Prompt):
image = pipe(prompt.text).images[0]
image.save("output.png") # Enregistrer l'image générée
return {"message": "Image generated", "image_path": "output.png"}
|