yousifalishah commited on
Commit
ba3afeb
·
verified ·
1 Parent(s): bdcf6e9

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -49
app.py DELETED
@@ -1,49 +0,0 @@
1
- import streamlit as st
2
- import torch
3
- import time
4
- from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
5
-
6
- # Set Streamlit page title and description
7
- st.set_page_config(page_title="AI Image Generator", page_icon="🎨")
8
- st.title("🎨 AI Image Generator with SDXL Turbo (CPU)")
9
-
10
- st.write("Enter a prompt below to generate an AI image using **Stable Diffusion XL Turbo** (optimized for CPU).")
11
-
12
- # Load Stable Diffusion XL Turbo model (optimized for CPU)
13
- @st.cache_resource
14
- def load_model():
15
- try:
16
- model_id = "stabilityai/sdxl-turbo"
17
- pipe = StableDiffusionPipeline.from_pretrained(
18
- model_id,
19
- torch_dtype=torch.float32 # Use float32 for CPU
20
- )
21
-
22
- pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
23
- pipe.to("cpu") # Force CPU usage
24
-
25
- return pipe
26
- except Exception as e:
27
- st.error(f"Error loading model: {str(e)}")
28
- return None # Return None if the model fails to load
29
-
30
- pipe = load_model()
31
-
32
- # User Input for Text Prompt
33
- prompt = st.text_input("Enter your text prompt:", "A futuristic city at sunset")
34
- num_steps = st.slider("Inference Steps:", min_value=1, max_value=10, value=4, step=1)
35
- guidance_scale = st.slider("Guidance Scale:", min_value=1.0, max_value=10.0, value=5.0, step=0.5)
36
-
37
- # Generate Image Button
38
- if st.button("Generate Image"):
39
- if pipe is None:
40
- st.error("Model failed to load. Please refresh and try again.")
41
- else:
42
- with st.spinner("Generating... Please wait (CPU processing takes time)"):
43
- start_time = time.time()
44
- try:
45
- image = pipe(prompt, num_inference_steps=num_steps, guidance_scale=guidance_scale).images[0]
46
- st.image(image, caption="Generated Image", use_column_width=True)
47
- st.success(f"✅ Image generated in {time.time() - start_time:.2f} seconds!")
48
- except Exception as e:
49
- st.error(f"An error occurred during generation: {str(e)}")