Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
import torch
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxx"}
|
| 9 |
-
|
| 10 |
-
def query(payload):
|
| 11 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
| 12 |
-
return response.content
|
| 13 |
-
|
| 14 |
-
# Load the FLUX.1-dev model from Hugging Face
|
| 15 |
-
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.float16)
|
| 16 |
-
pipe = pipe.to("cuda")
|
| 17 |
-
|
| 18 |
-
# Define a function to generate an image based on the prompt
|
| 19 |
def generate_image(prompt: str):
|
| 20 |
-
# Generate the image
|
| 21 |
-
image =
|
| 22 |
return image
|
| 23 |
|
| 24 |
# Create the Gradio interface
|
| 25 |
-
iface = gr.Interface(
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
# Launch the app
|
| 32 |
-
iface.launch()
|
| 33 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
+
# Load Stable Diffusion model from Hugging Face
|
| 5 |
+
generator = pipeline("text-to-image", model="stabilityai/stable-diffusion-3-medium-diffusers")
|
| 6 |
|
| 7 |
+
# Define the chatbot function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def generate_image(prompt: str):
|
| 9 |
+
# Generate the image from the prompt
|
| 10 |
+
image = generator(prompt)[0]["image"]
|
| 11 |
return image
|
| 12 |
|
| 13 |
# Create the Gradio interface
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=generate_image,
|
| 16 |
+
inputs=gr.Textbox(label="Enter a description of the image"),
|
| 17 |
+
outputs=gr.Image(label="Generated Image"),
|
| 18 |
+
live=True
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Launch the Gradio interface
|
| 22 |
+
iface.launch(share=True)
|
| 23 |
|
|
|
|
|
|
|
| 24 |
|