kasper-boy commited on
Commit
ca59cd5
·
verified ·
1 Parent(s): d878cdb

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +20 -0
  2. README.md +3 -3
  3. app.py +74 -0
  4. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python image from the Docker Hub
2
+ FROM python:3.10-slim
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Copy the requirements.txt file into the container
8
+ COPY requirements.txt .
9
+
10
+ # Install the required Python packages
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # Copy the rest of the application code into the container
14
+ COPY app.py .
15
+
16
+ # Expose the port that Gradio will run on
17
+ EXPOSE 7860
18
+
19
+ # Run the Gradio app
20
+ CMD ["python", "app.py"]
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: Text To Image SDXL
3
- emoji: 😻
4
- colorFrom: pink
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 4.36.1
8
  app_file: app.py
 
1
  ---
2
  title: Text To Image SDXL
3
+ emoji: 📊
4
+ colorFrom: red
5
+ colorTo: blue
6
  sdk: gradio
7
  sdk_version: 4.36.1
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import CLIPTextModel, CLIPTokenizer
4
+ from diffusers import StableDiffusionPipeline
5
+
6
+ # Load the model and tokenizer
7
+ model_id = "stabilityai/stable-diffusion-xl-base-1.0"
8
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
9
+ pipe = pipe.to("cpu")
10
+
11
+ def generate_image(prompt, negative_prompt, size):
12
+ if not prompt:
13
+ prompt = "a beautiful landscape"
14
+ if not negative_prompt:
15
+ negative_prompt = ""
16
+
17
+ width, height = map(int, size.split('x'))
18
+ generator = torch.Generator("cpu").manual_seed(42)
19
+
20
+ # Generate the image
21
+ result = pipe(prompt, height=height, width=width, negative_prompt=negative_prompt, generator=generator)
22
+
23
+ if result is not None and 'images' in result:
24
+ return result.images[0]
25
+ else:
26
+ return None
27
+
28
+ with gr.Blocks() as demo:
29
+ gr.Markdown("## Text to Image SDXL")
30
+
31
+ with gr.Row():
32
+ with gr.Column():
33
+ prompt = gr.Textbox(label="Prompt", placeholder="Enter the prompt here...")
34
+ negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Enter the negative prompt here...")
35
+ size = gr.Dropdown(choices=["512x512", "768x768", "1024x1024"], value="1024x1024", label="Size")
36
+ submit = gr.Button("Submit")
37
+ with gr.Column():
38
+ output = gr.Image(label="Output")
39
+
40
+ submit.click(generate_image, inputs=[prompt, negative_prompt, size], outputs=output)
41
+
42
+ demo.launch()
43
+
44
+ # import gradio as gr
45
+ # import torch
46
+ # from transformers import CLIPTextModel, CLIPTokenizer
47
+ # from diffusers import StableDiffusionPipeline
48
+
49
+ # # Load the model and tokenizer
50
+ # model_id = "stabilityai/stable-diffusion-xl-base-1.0"
51
+ # pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
52
+ # pipe = pipe.to("cpu")
53
+
54
+ # def generate_image(prompt, negative_prompt, size):
55
+ # width, height = map(int, size.split('x'))
56
+ # generator = torch.Generator("cpu").manual_seed(42)
57
+ # image = pipe(prompt, height=height, width=width, negative_prompt=negative_prompt, generator=generator).images[0]
58
+ # return image
59
+
60
+ # with gr.Blocks() as demo:
61
+ # gr.Markdown("## Text to Image SDXL")
62
+
63
+ # with gr.Row():
64
+ # with gr.Column():
65
+ # prompt = gr.Textbox(label="Prompt")
66
+ # negative_prompt = gr.Textbox(label="Negative Prompt")
67
+ # size = gr.Dropdown(choices=["512x512", "768x768", "1024x1024"], value="1024x1024", label="Size")
68
+ # submit = gr.Button("Submit")
69
+ # with gr.Column():
70
+ # output = gr.Image(label="Output")
71
+
72
+ # submit.click(generate_image, inputs=[prompt, negative_prompt, size], outputs=output)
73
+
74
+ # demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ torch
3
+ transformers
4
+ diffusers
5
+ accelerate