Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
26 |
-
|
27 |
-
|
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 =
|
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:
|