Spaces:
Runtime error
Runtime error
update app.py v2
Browse files
app.py
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
-
import requests
|
| 2 |
-
import io
|
| 3 |
from PIL import Image
|
| 4 |
import gradio as gr
|
| 5 |
-
|
|
|
|
| 6 |
from groq import Groq # Import the Groq library
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
groq_client = Groq(api_key="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")
|
| 11 |
|
| 12 |
def enhance_prompt(user_prompt):
|
| 13 |
"""Enhances the given prompt using Groq and returns the refined prompt."""
|
|
@@ -46,26 +44,19 @@ def enhance_prompt(user_prompt):
|
|
| 46 |
def generate_image(prompt):
|
| 47 |
"""Generates an image using the refined prompt."""
|
| 48 |
try:
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
{"path": "https://huggingface.co/XLabs-AI/flux-RealismLora", "scale": 1},
|
| 59 |
-
],
|
| 60 |
-
)
|
| 61 |
-
image_url = response.data[0].url
|
| 62 |
-
image_response = requests.get(image_url)
|
| 63 |
-
image_bytes = image_response.content
|
| 64 |
-
img = Image.open(io.BytesIO(image_bytes))
|
| 65 |
except Exception as e:
|
| 66 |
# Optionally, handle errors (you can also return a default error image)
|
| 67 |
-
|
| 68 |
-
return
|
| 69 |
|
| 70 |
# Build the Gradio interface with a two-step process
|
| 71 |
with gr.Blocks(css=".gradio-container {background-color: #f9f9f9; padding: 20px;}") as demo:
|
|
|
|
|
|
|
|
|
|
| 1 |
from PIL import Image
|
| 2 |
import gradio as gr
|
| 3 |
+
import torch
|
| 4 |
+
from diffusers import FluxPipeline
|
| 5 |
from groq import Groq # Import the Groq library
|
| 6 |
|
| 7 |
+
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
|
| 8 |
+
pipe.enable_model_cpu_offload() #save some VRAM by offloading the model to CPU. Remove this if you have enough GPU power
|
|
|
|
| 9 |
|
| 10 |
def enhance_prompt(user_prompt):
|
| 11 |
"""Enhances the given prompt using Groq and returns the refined prompt."""
|
|
|
|
| 44 |
def generate_image(prompt):
|
| 45 |
"""Generates an image using the refined prompt."""
|
| 46 |
try:
|
| 47 |
+
image = pipe(
|
| 48 |
+
prompt,
|
| 49 |
+
height=1024,
|
| 50 |
+
width=1024,
|
| 51 |
+
guidance_scale=3.5,
|
| 52 |
+
num_inference_steps=50,
|
| 53 |
+
max_sequence_length=512,
|
| 54 |
+
generator=torch.Generator("cpu").manual_seed(0)
|
| 55 |
+
).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
except Exception as e:
|
| 57 |
# Optionally, handle errors (you can also return a default error image)
|
| 58 |
+
image = None
|
| 59 |
+
return image
|
| 60 |
|
| 61 |
# Build the Gradio interface with a two-step process
|
| 62 |
with gr.Blocks(css=".gradio-container {background-color: #f9f9f9; padding: 20px;}") as demo:
|