gokilashree commited on
Commit
3569994
·
verified ·
1 Parent(s): bfeb2db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -1,6 +1,6 @@
1
- from transformers import MBartForConditionalGeneration, MBart50Tokenizer, AutoModelForCausalLM, AutoTokenizer, pipeline
2
- from diffusers import StableDiffusionPipeline
3
  import torch
 
 
4
  import gradio as gr
5
  import io
6
  from PIL import Image
@@ -22,16 +22,16 @@ text_tokenizer = AutoTokenizer.from_pretrained(text_generation_model_name)
22
  text_model = AutoModelForCausalLM.from_pretrained(text_generation_model_name)
23
  text_generator = pipeline("text-generation", model=text_model, tokenizer=text_tokenizer)
24
 
25
- # Load the FLUX.1-dev image generation model from diffusers
26
- flux_model = StableDiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", use_auth_token=hf_api_key)
27
- flux_model.to("cuda") # Use GPU for faster generation, if available
28
 
29
  # Function to generate an image using FLUX.1-dev model
30
  def generate_image_from_text(translated_text):
31
  try:
32
  print(f"Generating image from translated text: {translated_text}")
33
  # Generate the image using the FLUX.1-dev model
34
- image = flux_model(translated_text).images[0]
35
  print("Image generation completed.")
36
  return image, None
37
  except Exception as e:
 
 
 
1
  import torch
2
+ from transformers import MBartForConditionalGeneration, MBart50Tokenizer, AutoModelForCausalLM, AutoTokenizer, pipeline
3
+ from diffusers import FluxPipeline
4
  import gradio as gr
5
  import io
6
  from PIL import Image
 
22
  text_model = AutoModelForCausalLM.from_pretrained(text_generation_model_name)
23
  text_generator = pipeline("text-generation", model=text_model, tokenizer=text_tokenizer)
24
 
25
+ # Load the FLUX.1-dev model using FluxPipeline
26
+ pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", use_auth_token=hf_api_key, torch_dtype=torch.bfloat16)
27
+ pipe.enable_model_cpu_offload() # Save VRAM by offloading the model to CPU
28
 
29
  # Function to generate an image using FLUX.1-dev model
30
  def generate_image_from_text(translated_text):
31
  try:
32
  print(f"Generating image from translated text: {translated_text}")
33
  # Generate the image using the FLUX.1-dev model
34
+ image = pipe(translated_text).images[0]
35
  print("Image generation completed.")
36
  return image, None
37
  except Exception as e: