gokilashree commited on
Commit
9d1c96b
·
verified ·
1 Parent(s): 86c20bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -1,10 +1,9 @@
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
7
  import os
 
8
 
9
  # Load the Hugging Face API key from environment variables
10
  hf_api_key = os.getenv("multimodel_token")
@@ -22,15 +21,15 @@ 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 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
 
 
1
  from transformers import MBartForConditionalGeneration, MBart50Tokenizer, AutoModelForCausalLM, AutoTokenizer, pipeline
2
+ from diffusers import StableDiffusionPipeline
3
+ import torch
4
  import gradio as gr
 
 
5
  import os
6
+ from PIL import Image
7
 
8
  # Load the Hugging Face API key from environment variables
9
  hf_api_key = os.getenv("multimodel_token")
 
21
  text_model = AutoModelForCausalLM.from_pretrained(text_generation_model_name)
22
  text_generator = pipeline("text-generation", model=text_model, tokenizer=text_tokenizer)
23
 
24
+ # Load the alvdansen/flux-koda image generation model using Diffusers
25
+ pipe = StableDiffusionPipeline.from_pretrained("alvdansen/flux-koda", use_auth_token=hf_api_key)
26
+ pipe.to("cuda") # Use GPU for faster generation, if available
27
 
28
+ # Function to generate an image using alvdansen/flux-koda model
29
  def generate_image_from_text(translated_text):
30
  try:
31
  print(f"Generating image from translated text: {translated_text}")
32
+ # Generate the image using the alvdansen/flux-koda model
33
  image = pipe(translated_text).images[0]
34
  print("Image generation completed.")
35
  return image, None