Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,65 +1,37 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
import
|
| 4 |
-
import spaces
|
| 5 |
-
from diffusers import FluxPipeline
|
| 6 |
-
from huggingface_hub import login
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
login(token=token)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
image = pipe(
|
| 35 |
-
prompt=prompt,
|
| 36 |
-
width=1024,
|
| 37 |
-
height=1024,
|
| 38 |
-
num_inference_steps=4,
|
| 39 |
-
generator=generator,
|
| 40 |
-
guidance_scale=0.0
|
| 41 |
-
).images[0]
|
| 42 |
-
|
| 43 |
-
return image
|
| 44 |
-
except Exception as e:
|
| 45 |
-
# This will show the actual error message in the Gradio UI
|
| 46 |
-
raise gr.Error(f"Generation failed: {str(e)}")
|
| 47 |
|
| 48 |
-
|
| 49 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 50 |
-
gr.Markdown("# FLUX.1 Minimal")
|
| 51 |
-
|
| 52 |
-
with gr.Group():
|
| 53 |
-
prompt = gr.Textbox(
|
| 54 |
-
placeholder="Describe your image...",
|
| 55 |
-
show_label=False,
|
| 56 |
-
container=False
|
| 57 |
-
)
|
| 58 |
-
btn = gr.Button("Generate", variant="primary")
|
| 59 |
-
|
| 60 |
-
output_img = gr.Image(show_label=False, interactive=False)
|
| 61 |
-
|
| 62 |
-
btn.click(fn=generate_image, inputs=[prompt], outputs=output_img)
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
demo.launch(share=True)
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from optimum.intel import OVStableDiffusionPipeline
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# 1. Load the OpenVINO optimized model
|
| 5 |
+
# This model is specifically 'squeezed' to run on CPUs
|
| 6 |
+
model_id = "OpenVINO/stable-diffusion-v1-5-int8-ov"
|
|
|
|
| 7 |
|
| 8 |
+
print("Loading model to CPU... (This may take a minute)")
|
| 9 |
+
pipe = OVStableDiffusionPipeline.from_pretrained(model_id, compile=True)
|
| 10 |
|
| 11 |
+
# 2. Define the Generation Function
|
| 12 |
+
def generate_image(prompt, steps):
|
| 13 |
+
# On CPU, we keep steps low (1-4) for speed
|
| 14 |
+
image = pipe(
|
| 15 |
+
prompt=prompt,
|
| 16 |
+
num_inference_steps=steps,
|
| 17 |
+
guidance_scale=7.5
|
| 18 |
+
).images[0]
|
| 19 |
+
return image
|
| 20 |
|
| 21 |
+
# 3. Gradio UI
|
| 22 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 23 |
+
gr.Markdown("# ⚡ CPU-Fast Image Generator")
|
| 24 |
+
gr.Markdown("Using OpenVINO to run Stable Diffusion on a free CPU tier.")
|
| 25 |
|
| 26 |
+
with gr.Row():
|
| 27 |
+
with gr.Column():
|
| 28 |
+
prompt = gr.Textbox(label="Enter Prompt", value="A cozy cabin in the woods, digital art")
|
| 29 |
+
steps = gr.Slider(1, 10, value=4, step=1, label="Steps (Lower is faster)")
|
| 30 |
+
btn = gr.Button("Generate", variant="primary")
|
| 31 |
|
| 32 |
+
output_img = gr.Image(label="Result")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
btn.click(fn=generate_image, inputs=[prompt, steps], outputs=output_img)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|
| 37 |
demo.launch(share=True)
|