abdalraheemdmd commited on
Commit
a950115
Β·
verified Β·
1 Parent(s): 20567a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
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
- # βœ… Load Image Generation Model
13
- IMAGE_MODEL = "stabilityai/sdxl-lightning"
 
 
 
 
 
 
 
 
 
14
  pipeline = DiffusionPipeline.from_pretrained(
15
- IMAGE_MODEL, torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
 
 
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