codermert commited on
Commit
26f0892
1 Parent(s): 86c4da5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +26 -23
README.md CHANGED
@@ -27,35 +27,38 @@ You should use `tugce` to trigger the image generation.
27
  ## Use it with the [🧨 diffusers library](https://github.com/huggingface/diffusers)
28
 
29
  ```py
30
- from diffusers import AutoPipelineForText2Image
 
31
  import torch
 
 
 
 
32
 
33
  # Model ve LoRA'yı yükle
34
  pipeline = AutoPipelineForText2Image.from_pretrained('black-forest-labs/FLUX.1-dev', torch_dtype=torch.float16).to('cuda')
35
  pipeline.load_lora_weights('codermert/tugce2-lora', weight_name='flux_train_replicate.safetensors')
36
 
37
- # Farklı boyutlar
38
- sizes = [
39
- (512, 512), # 1:1
40
- (768, 512), # 3:2
41
- (640, 480), # 4:3
42
- (896, 504), # 16:9
43
- ]
44
-
45
- # Prompt
46
- prompt = "tugce in a beautiful garden"
47
-
48
- # Her boyut için görüntü oluştur
49
- for width, height in sizes:
50
- image = pipeline(
51
- prompt,
52
- width=width,
53
- height=height
54
- ).images[0]
55
-
56
- # Görüntüyü kaydet
57
- image.save(f"tugce_{width}x{height}.png")
58
- print(f"Oluşturuldu: tugce_{width}x{height}.png")
59
  ```
60
 
61
  For more details, including weighting, merging and fusing LoRAs, check the [documentation on loading LoRAs in diffusers](https://huggingface.co/docs/diffusers/main/en/using-diffusers/loading_adapters)
 
27
  ## Use it with the [🧨 diffusers library](https://github.com/huggingface/diffusers)
28
 
29
  ```py
30
+ from fastapi import FastAPI, HTTPException
31
+ from fastapi.responses import FileResponse
32
  import torch
33
+ from diffusers import AutoPipelineForText2Image
34
+ import io
35
+
36
+ app = FastAPI()
37
 
38
  # Model ve LoRA'yı yükle
39
  pipeline = AutoPipelineForText2Image.from_pretrained('black-forest-labs/FLUX.1-dev', torch_dtype=torch.float16).to('cuda')
40
  pipeline.load_lora_weights('codermert/tugce2-lora', weight_name='flux_train_replicate.safetensors')
41
 
42
+ @app.post("/generate_image")
43
+ async def generate_image(prompt: str, width: int, height: int):
44
+ try:
45
+ image = pipeline(
46
+ prompt,
47
+ width=width,
48
+ height=height
49
+ ).images[0]
50
+
51
+ img_byte_arr = io.BytesIO()
52
+ image.save(img_byte_arr, format='PNG')
53
+ img_byte_arr.seek(0)
54
+
55
+ return FileResponse(img_byte_arr, media_type="image/png")
56
+ except Exception as e:
57
+ raise HTTPException(status_code=500, detail=str(e))
58
+
59
+ if __name__ == "__main__":
60
+ import uvicorn
61
+ uvicorn.run(app, host="0.0.0.0", port=8000)
 
 
62
  ```
63
 
64
  For more details, including weighting, merging and fusing LoRAs, check the [documentation on loading LoRAs in diffusers](https://huggingface.co/docs/diffusers/main/en/using-diffusers/loading_adapters)