File size: 1,036 Bytes
948896c
 
 
 
c7a28d2
 
 
 
 
 
0e698b0
 
c7a28d2
948896c
 
 
 
 
 
0e698b0
948896c
 
 
 
 
 
 
 
 
 
 
 
0e698b0
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
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

# 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):
    # Generate the image using the pipeline
    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()