Update README.md
Browse files
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
|
|
|
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 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
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)
|