File size: 1,116 Bytes
948896c
 
 
 
c7a28d2
 
 
 
 
 
 
 
 
 
 
 
 
 
948896c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
from diffusers import DiffusionPipeline
import torch

import requests

API_URL = "https://router.huggingface.co/hf-inference/v1"
headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxx"}

def query(payload):
	response = requests.post(API_URL, headers=headers, json=payload)
	return response.content

# You can access the image with PIL.Image for example
import io
from PIL import Image
image = Image.open(io.BytesIO(image_bytes))

# Load the FLUX.1-dev model from Hugging Face
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.float16)
pipe = pipe.to("cuda")

# Define a function to generate an image based on the prompt
def generate_image(prompt: str):
    image = pipe(prompt).images[0]
    return image

# Create the Gradio interface
iface = gr.Interface(fn=generate_image, 
                     inputs="text", 
                     outputs="image", 
                     title="Text-to-Image with FLUX.1-dev",
                     description="Enter a prompt to generate an image using the FLUX.1-dev model.")

# Launch the app
iface.launch()