Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,31 @@
|
|
|
|
|
|
1 |
from fastapi import FastAPI, HTTPException
|
2 |
from pydantic import BaseModel
|
3 |
import story_generator # β
Import Story Generator
|
4 |
-
import torch
|
5 |
from diffusers import DiffusionPipeline
|
6 |
import io
|
7 |
import base64
|
8 |
from PIL import Image
|
|
|
9 |
|
10 |
app = FastAPI()
|
11 |
|
12 |
-
# β
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
pipeline = DiffusionPipeline.from_pretrained(
|
15 |
-
IMAGE_MODEL,
|
|
|
|
|
16 |
).to("cuda" if torch.cuda.is_available() else "cpu")
|
17 |
|
18 |
# β
Define the input request format
|
|
|
1 |
+
import os
|
2 |
+
import torch
|
3 |
from fastapi import FastAPI, HTTPException
|
4 |
from pydantic import BaseModel
|
5 |
import story_generator # β
Import Story Generator
|
|
|
6 |
from diffusers import DiffusionPipeline
|
7 |
import io
|
8 |
import base64
|
9 |
from PIL import Image
|
10 |
+
from huggingface_hub import login
|
11 |
|
12 |
app = FastAPI()
|
13 |
|
14 |
+
# β
Set Hugging Face cache directory to /tmp
|
15 |
+
os.environ["HF_HOME"] = "/tmp/huggingface"
|
16 |
+
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface"
|
17 |
+
os.environ["HF_HUB_CACHE"] = "/tmp/huggingface"
|
18 |
+
|
19 |
+
# β
Hugging Face Authentication (Only needed if model is private)
|
20 |
+
HF_TOKEN = "your_huggingface_token_here" # Replace this with your actual token
|
21 |
+
login(token=HF_TOKEN)
|
22 |
+
|
23 |
+
# β
Load Image Generation Model (Use a fast, public model)
|
24 |
+
IMAGE_MODEL = "stabilityai/sdxl-turbo" # Replace with "stabilityai/sdxl-lightning" if needed
|
25 |
pipeline = DiffusionPipeline.from_pretrained(
|
26 |
+
IMAGE_MODEL,
|
27 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
28 |
+
use_auth_token=HF_TOKEN # Required for private models
|
29 |
).to("cuda" if torch.cuda.is_available() else "cpu")
|
30 |
|
31 |
# β
Define the input request format
|