MostafaAly commited on
Commit
a353928
·
verified ·
1 Parent(s): 876e9ba

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +34 -0
  2. requirements.txt +9 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import StableDiffusionPipeline
3
+ import torch
4
+
5
+ from transformers import logging
6
+ logging.set_verbosity_error() # This suppresses warnings, including cache migration
7
+ #GPU error
8
+ from diffusers import StableDiffusionPipeline
9
+
10
+ # Load the model
11
+ model_id = "MostafaAly/stable-diffusion-finetuned"
12
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
13
+
14
+ # Check if CUDA is available and move the model to GPU if it is, otherwise use CPU
15
+ device = "cuda" if torch.cuda.is_available() else "cpu"
16
+ pipe.to(device)
17
+
18
+ print(f"Using device: {device}")
19
+
20
+
21
+ # Define the function for text-to-image generation
22
+ def generate_image(prompt):
23
+ image = pipe(prompt).images[0]
24
+ return image
25
+
26
+ # Create a Gradio interface
27
+ interface = gr.Interface(
28
+ fn=generate_image,
29
+ inputs=gr.Textbox(label="Enter your prompt"),
30
+ outputs=gr.Image(label="Generated Image"),
31
+ )
32
+
33
+ # Launch the interface
34
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ torch
4
+ diffusers
5
+ transformers>=4.22.0
6
+ accelerate
7
+ Pillow # For handling images
8
+ ftfy # Fixes text issues, required for tokenization
9
+ scipy # For certain image processing operations