Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -2,15 +2,6 @@ import os
|
|
2 |
import multiprocessing
|
3 |
import subprocess
|
4 |
import nltk
|
5 |
-
import torch
|
6 |
-
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
7 |
-
from moviepy.editor import VideoFileClip
|
8 |
-
import moviepy.editor as mpy
|
9 |
-
from PIL import Image, ImageDraw, ImageFont
|
10 |
-
from mutagen.mp3 import MP3
|
11 |
-
from gtts import gTTS
|
12 |
-
from pydub import AudioSegment
|
13 |
-
import textwrap
|
14 |
import gradio as gr
|
15 |
import matplotlib.pyplot as plt
|
16 |
import gc
|
@@ -19,31 +10,50 @@ from typing import List
|
|
19 |
import shutil
|
20 |
import numpy as np
|
21 |
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
from diffusers import DiffusionPipeline
|
23 |
-
import
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
dtype = torch.bfloat16
|
26 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
MAX_SEED = np.iinfo(np.int32).max
|
30 |
MAX_IMAGE_SIZE = 2048
|
31 |
|
32 |
nltk.download('punkt')
|
|
|
33 |
# Ensure proper multiprocessing start method
|
34 |
multiprocessing.set_start_method("spawn", force=True)
|
35 |
|
36 |
-
# GPU Fallback Setup
|
37 |
-
#if os.environ.get("SPACES_ZERO_GPU") is not None:
|
38 |
-
# import spaces
|
39 |
-
#else:
|
40 |
-
# class spaces:
|
41 |
-
# @staticmethod
|
42 |
-
# def GPU(func=None, duration=None):
|
43 |
-
## def wrapper(fn):
|
44 |
-
# return fn
|
45 |
-
# return wrapper if func is None else wrapper(func)
|
46 |
-
|
47 |
# Download necessary NLTK data
|
48 |
def setup_nltk():
|
49 |
"""Ensure required NLTK data is available."""
|
@@ -52,8 +62,6 @@ def setup_nltk():
|
|
52 |
except LookupError:
|
53 |
nltk.download('punkt')
|
54 |
|
55 |
-
setup_nltk()
|
56 |
-
|
57 |
# Constants
|
58 |
DESCRIPTION = (
|
59 |
"Video Story Generator with Audio\n"
|
|
|
2 |
import multiprocessing
|
3 |
import subprocess
|
4 |
import nltk
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import gradio as gr
|
6 |
import matplotlib.pyplot as plt
|
7 |
import gc
|
|
|
10 |
import shutil
|
11 |
import numpy as np
|
12 |
import random
|
13 |
+
|
14 |
+
# Ensure `spaces` is imported first
|
15 |
+
try:
|
16 |
+
import spaces
|
17 |
+
except ImportError:
|
18 |
+
class spaces:
|
19 |
+
@staticmethod
|
20 |
+
def GPU(func=None, duration=None):
|
21 |
+
def wrapper(fn):
|
22 |
+
return fn
|
23 |
+
return wrapper if func is None else wrapper(func)
|
24 |
+
|
25 |
+
# Now import CUDA-related libraries
|
26 |
+
import torch
|
27 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
28 |
from diffusers import DiffusionPipeline
|
29 |
+
from moviepy.editor import VideoFileClip
|
30 |
+
import moviepy.editor as mpy
|
31 |
+
from PIL import Image, ImageDraw, ImageFont
|
32 |
+
from mutagen.mp3 import MP3
|
33 |
+
from gtts import gTTS
|
34 |
+
from pydub import AudioSegment
|
35 |
+
import textwrap
|
36 |
+
|
37 |
+
# Initialize FLUX pipeline only if CUDA is available
|
38 |
dtype = torch.bfloat16
|
39 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
40 |
+
|
41 |
+
if device == "cuda":
|
42 |
+
flux_pipe = DiffusionPipeline.from_pretrained(
|
43 |
+
"black-forest-labs/FLUX.1-schnell",
|
44 |
+
torch_dtype=dtype
|
45 |
+
).to(device)
|
46 |
+
else:
|
47 |
+
flux_pipe = None # Avoid initializing the model when CUDA is unavailable
|
48 |
|
49 |
MAX_SEED = np.iinfo(np.int32).max
|
50 |
MAX_IMAGE_SIZE = 2048
|
51 |
|
52 |
nltk.download('punkt')
|
53 |
+
|
54 |
# Ensure proper multiprocessing start method
|
55 |
multiprocessing.set_start_method("spawn", force=True)
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
# Download necessary NLTK data
|
58 |
def setup_nltk():
|
59 |
"""Ensure required NLTK data is available."""
|
|
|
62 |
except LookupError:
|
63 |
nltk.download('punkt')
|
64 |
|
|
|
|
|
65 |
# Constants
|
66 |
DESCRIPTION = (
|
67 |
"Video Story Generator with Audio\n"
|