Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
import torch
|
| 3 |
from diffusers import DiffusionPipeline
|
| 4 |
-
import gradio as gr
|
| 5 |
-
from PIL import Image
|
| 6 |
|
| 7 |
-
# Load
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
| 10 |
def generate_image(prompt):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
return image
|
| 14 |
|
| 15 |
# Gradio interface
|
| 16 |
with gr.Blocks() as demo:
|
| 17 |
gr.Markdown("# FLUX Image Generator")
|
| 18 |
-
prompt = gr.Textbox(label="Enter your prompt", placeholder="
|
| 19 |
-
|
| 20 |
output_image = gr.Image(label="Generated Image")
|
| 21 |
|
| 22 |
-
|
| 23 |
|
| 24 |
# Launch the app
|
| 25 |
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import os
|
| 3 |
import torch
|
| 4 |
from diffusers import DiffusionPipeline
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# Load Hugging Face access token from secrets
|
| 7 |
+
hf_token = os.getenv("secret") # Ensure your secret is named "secret"
|
| 8 |
+
|
| 9 |
+
# Set up the pipeline with the access token
|
| 10 |
+
pipeline = DiffusionPipeline.from_pretrained(
|
| 11 |
+
"black-forest-labs/FLUX.1-dev",
|
| 12 |
+
use_auth_token=hf_token
|
| 13 |
+
).to("cuda" if torch.cuda.is_available() else "cpu")
|
| 14 |
|
| 15 |
+
# Inference function
|
| 16 |
def generate_image(prompt):
|
| 17 |
+
with torch.no_grad():
|
| 18 |
+
image = pipeline(prompt).images[0]
|
| 19 |
return image
|
| 20 |
|
| 21 |
# Gradio interface
|
| 22 |
with gr.Blocks() as demo:
|
| 23 |
gr.Markdown("# FLUX Image Generator")
|
| 24 |
+
prompt = gr.Textbox(label="Enter your prompt", placeholder="e.g. Astronaut riding a horse")
|
| 25 |
+
generate_btn = gr.Button("Generate Image")
|
| 26 |
output_image = gr.Image(label="Generated Image")
|
| 27 |
|
| 28 |
+
generate_btn.click(fn=generate_image, inputs=prompt, outputs=output_image)
|
| 29 |
|
| 30 |
# Launch the app
|
| 31 |
demo.launch()
|