Kabilash10 commited on
Commit
73f13a5
·
verified ·
1 Parent(s): 6f4c579

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
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 the model
8
- pipeline = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev").to("cuda" if torch.cuda.is_available() else "cpu")
 
 
 
 
 
 
9
 
 
10
  def generate_image(prompt):
11
- # Generate the image using the pipeline
12
- image = pipeline(prompt).images[0]
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="Describe the image you want to generate...")
19
- generate_button = gr.Button("Generate Image")
20
  output_image = gr.Image(label="Generated Image")
21
 
22
- generate_button.click(fn=generate_image, inputs=prompt, outputs=output_image)
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()