Kabilash10 commited on
Commit
0f33d77
·
verified ·
1 Parent(s): 211b07f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -1,23 +1,15 @@
1
  import os
2
- import requests
3
- import io
4
- from PIL import Image
5
  import gradio as gr
 
6
 
7
- # Define the API URL for the model
8
- API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
9
- headers = {
10
- "Authorization": f"Bearer {os.getenv('secret')}"
11
- }
12
-
13
- def query(prompt):
14
- response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
15
- response.raise_for_status() # Raise an error for bad responses
16
- return response.content
17
 
18
  def generate_image(prompt):
19
- image_bytes = query(prompt)
20
- image = Image.open(io.BytesIO(image_bytes))
21
  return image
22
 
23
  # Gradio interface
 
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