1c1 commited on
Commit
4b2b4ad
·
verified ·
1 Parent(s): ad4a177

Upload ba.txt

Browse files

from fastapi import FastAPI
from fastapi.responses import FileResponse
from diffusers import StableDiffusionPipeline
import torch, uuid, os

app = FastAPI()
os.makedirs("generated_images", exist_ok=True)

# Modeli yükle
pipe = StableDiffusionPipeline.from_pretrained(
"username/Z-Image-Auto", torch_dtype=torch.float16
)
pipe = pipe.to("cuda") # GPU varsa hızlanır

# Örnek tüm kategoriler (dilediğin kadar ekleyebilirsin)
categories = [
"cat", "dog", "lion", "forest", "mountain", "river",
"robot", "spaceship", "cyberpunk city", "anime character",
"fantasy castle", "dragon", "car", "plane", "historical scene",
"3D render", "pixel art", "digital painting"
]

@app .get("/generate_all/")
def generate_all():
results = []
for cat in categories:
file_id = str(uuid.uuid4())
file_path = f"generated_images/{file_id}.png"
image = pipe(cat).images[0]
image.save(file_path)
results.append({
"category": cat,
"url": f"/image/{file_id}.png"
})
return results

@app .get("/image/{file_id}.png")
def get_image(file_id: str):
return FileResponse(f"generated_images/{file_id}.png")

Files changed (1) hide show
  1. ba.txt +39 -0
ba.txt ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.responses import FileResponse
3
+ from diffusers import StableDiffusionPipeline
4
+ import torch, uuid, os
5
+
6
+ app = FastAPI()
7
+ os.makedirs("generated_images", exist_ok=True)
8
+
9
+ # Modeli yükle
10
+ pipe = StableDiffusionPipeline.from_pretrained(
11
+ "username/Z-Image-Auto", torch_dtype=torch.float16
12
+ )
13
+ pipe = pipe.to("cuda") # GPU varsa hızlanır
14
+
15
+ # Örnek tüm kategoriler (dilediğin kadar ekleyebilirsin)
16
+ categories = [
17
+ "cat", "dog", "lion", "forest", "mountain", "river",
18
+ "robot", "spaceship", "cyberpunk city", "anime character",
19
+ "fantasy castle", "dragon", "car", "plane", "historical scene",
20
+ "3D render", "pixel art", "digital painting"
21
+ ]
22
+
23
+ @app.get("/generate_all/")
24
+ def generate_all():
25
+ results = []
26
+ for cat in categories:
27
+ file_id = str(uuid.uuid4())
28
+ file_path = f"generated_images/{file_id}.png"
29
+ image = pipe(cat).images[0]
30
+ image.save(file_path)
31
+ results.append({
32
+ "category": cat,
33
+ "url": f"/image/{file_id}.png"
34
+ })
35
+ return results
36
+
37
+ @app.get("/image/{file_id}.png")
38
+ def get_image(file_id: str):
39
+ return FileResponse(f"generated_images/{file_id}.png")