man08man commited on
Commit
4398c5e
Β·
verified Β·
1 Parent(s): 791565b

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +20 -0
  2. dockerfile +5 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import StableDiffusionPipeline
2
+ import torch
3
+ import random
4
+
5
+ def generate_image(prompt):
6
+ # Use updated model loading syntax
7
+ pipe = StableDiffusionPipeline.from_pretrained(
8
+ "stabilityai/stable-diffusion-2-1",
9
+ torch_dtype=torch.float16, # Add this for better performance
10
+ use_auth_token="YOUR_HF_TOKEN", # Replace with your token
11
+ safety_checker=None # Optional: disable safety filter
12
+ )
13
+
14
+ # Generate random seed
15
+ seed = random.randint(0, 1000000)
16
+ generator = torch.Generator().manual_seed(seed)
17
+
18
+ # Generate image
19
+ image = pipe(prompt, generator=generator).images[0]
20
+ return image
dockerfile ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ FROM python:3.9-slim # Use Python 3.9 instead of 3.10
2
+ WORKDIR /app
3
+ COPY . .
4
+ RUN pip install -r requirements.txt
5
+ CMD ["python", "app.py"]
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio>=3.50.0
2
+ diffusers>=0.24.0
3
+ torch>=2.1.0
4
+ huggingface_hub==0.19.4 # Explicit version with cached_download
5
+ accelerate>=0.26.0