concauu commited on
Commit
fe7e07a
·
verified ·
1 Parent(s): cb42408

update app.py v2

Browse files
Files changed (1) hide show
  1. app.py +15 -24
app.py CHANGED
@@ -1,13 +1,11 @@
1
- import requests
2
- import io
3
  from PIL import Image
4
  import gradio as gr
5
- from together import Together
 
6
  from groq import Groq # Import the Groq library
7
 
8
- # Initialize the Together and Groq clients with your API keys
9
- client = Together(api_key="d43d9d8b78242356408329a19a9cdce9290a8c3a254db6293fa6293d207e7e38")
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
- response = client.images.generate(
50
- prompt=prompt,
51
- model="black-forest-labs/FLUX.1-dev-lora",
52
- width=1024,
53
- height=768,
54
- steps=28,
55
- n=1,
56
- response_format="url",
57
- image_loras=[
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
- img = None
68
- return img
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: