Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
revision="fp16",
|
| 9 |
-
torch_dtype=torch.float16
|
| 10 |
-
).to("cuda")
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
# Define
|
| 16 |
-
def generate_image(
|
| 17 |
-
|
|
|
|
| 18 |
return image
|
| 19 |
|
| 20 |
-
# Gradio interface
|
| 21 |
-
|
| 22 |
-
fn=generate_image,
|
| 23 |
-
inputs="
|
| 24 |
-
outputs="
|
| 25 |
-
title="
|
| 26 |
-
description="
|
| 27 |
)
|
| 28 |
|
| 29 |
# Launch the Gradio app
|
| 30 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import io
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import os
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
load_dotenv()
|
| 8 |
|
| 9 |
+
# Define the API URL and headers
|
| 10 |
+
API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
|
| 11 |
+
headers = {"Authorization": f"Bearer {os.getenv('HF_API_TOKEN')}"}
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Define the query function
|
| 14 |
+
def query(payload):
|
| 15 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 16 |
+
return response.content
|
| 17 |
|
| 18 |
+
# Define the function to generate the image
|
| 19 |
+
def generate_image(input_text):
|
| 20 |
+
image_bytes = query({"inputs": input_text})
|
| 21 |
+
image = Image.open(io.BytesIO(image_bytes))
|
| 22 |
return image
|
| 23 |
|
| 24 |
+
# Create Gradio interface
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=generate_image,
|
| 27 |
+
inputs=gr.inputs.Textbox(label="Input Text", placeholder="Enter your description here..."),
|
| 28 |
+
outputs=gr.outputs.Image(type="pil", label="Generated Image"),
|
| 29 |
+
title="Image Generation with FLUX",
|
| 30 |
+
description="Enter a description to generate an image."
|
| 31 |
)
|
| 32 |
|
| 33 |
# Launch the Gradio app
|
| 34 |
+
iface.launch()
|