abdalraheemdmd commited on
Commit
43cfc3a
Β·
verified Β·
1 Parent(s): 151afba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -2,30 +2,24 @@ 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
 
2
  import torch
3
  from fastapi import FastAPI, HTTPException
4
  from pydantic import BaseModel
5
+ import story_generator
6
  from diffusers import DiffusionPipeline
7
  import io
8
  import base64
9
  from PIL import Image
 
10
 
11
  app = FastAPI()
12
 
13
+ # βœ… Set Hugging Face cache directory to /tmp (Fixes cache write errors)
14
  os.environ["HF_HOME"] = "/tmp/huggingface"
15
  os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface"
16
  os.environ["HF_HUB_CACHE"] = "/tmp/huggingface"
17
 
18
+ # βœ… Load Public Image Generation Model (No Token Needed)
19
+ IMAGE_MODEL = "stabilityai/sdxl-turbo" # Fastest model for public access
 
 
 
 
20
  pipeline = DiffusionPipeline.from_pretrained(
21
  IMAGE_MODEL,
22
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
 
23
  ).to("cuda" if torch.cuda.is_available() else "cpu")
24
 
25
  # βœ… Define the input request format