Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,7 @@ from mutagen.mp3 import MP3
|
|
| 21 |
from gtts import gTTS
|
| 22 |
from pydub import AudioSegment
|
| 23 |
import textwrap
|
| 24 |
-
|
| 25 |
# Log GPU Memory (optional, for debugging)
|
| 26 |
def log_gpu_memory():
|
| 27 |
"""Log GPU memory usage."""
|
|
@@ -84,49 +84,6 @@ def load_text_summarization_model():
|
|
| 84 |
tokenizer, model = load_text_summarization_model()
|
| 85 |
|
| 86 |
|
| 87 |
-
#@spaces.GPU()
|
| 88 |
-
def generate_image_with_flux_old(
|
| 89 |
-
text: str,
|
| 90 |
-
seed: int = 42,
|
| 91 |
-
width: int = 1024,
|
| 92 |
-
height: int = 1024,
|
| 93 |
-
num_inference_steps: int = 4,
|
| 94 |
-
randomize_seed: bool = True):
|
| 95 |
-
"""
|
| 96 |
-
Generates an image from text using FLUX.
|
| 97 |
-
Args:
|
| 98 |
-
text: The text prompt to generate the image from.
|
| 99 |
-
seed: The random seed for image generation. -1 for random.
|
| 100 |
-
width: Width of the generated image.
|
| 101 |
-
height: Height of the generated image.
|
| 102 |
-
num_inference_steps: Number of inference steps.
|
| 103 |
-
randomize_seed: Whether to randomize the seed.
|
| 104 |
-
Returns:
|
| 105 |
-
A PIL Image object.
|
| 106 |
-
"""
|
| 107 |
-
print(f"DEBUG: Generating image with FLUX for text: '{text}'")
|
| 108 |
-
|
| 109 |
-
# Initialize FLUX pipeline here
|
| 110 |
-
dtype = torch.bfloat16
|
| 111 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 112 |
-
torch.cuda.empty_cache() # Clear cache
|
| 113 |
-
gc.collect() # Run garbage collection
|
| 114 |
-
flux_pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype).to(device)
|
| 115 |
-
|
| 116 |
-
if randomize_seed:
|
| 117 |
-
seed = random.randint(0, MAX_SEED)
|
| 118 |
-
generator = torch.Generator(device=device).manual_seed(seed) # Specify device for generator
|
| 119 |
-
image = flux_pipe(
|
| 120 |
-
prompt=text,
|
| 121 |
-
width=width,
|
| 122 |
-
height=height,
|
| 123 |
-
num_inference_steps=num_inference_steps,
|
| 124 |
-
generator=generator,
|
| 125 |
-
guidance_scale=0.0
|
| 126 |
-
).images[0]
|
| 127 |
-
print("DEBUG: Image generated successfully.")
|
| 128 |
-
return image
|
| 129 |
-
|
| 130 |
@spaces.GPU()
|
| 131 |
def generate_image_with_flux(
|
| 132 |
text: str,
|
|
|
|
| 21 |
from gtts import gTTS
|
| 22 |
from pydub import AudioSegment
|
| 23 |
import textwrap
|
| 24 |
+
nltk.download('punkt_tab')
|
| 25 |
# Log GPU Memory (optional, for debugging)
|
| 26 |
def log_gpu_memory():
|
| 27 |
"""Log GPU memory usage."""
|
|
|
|
| 84 |
tokenizer, model = load_text_summarization_model()
|
| 85 |
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
@spaces.GPU()
|
| 88 |
def generate_image_with_flux(
|
| 89 |
text: str,
|