Ruslan Magana Vsevolodovna commited on
Commit
4b68d40
1 Parent(s): 2cc68f0

fixing gpu

Browse files
Files changed (2) hide show
  1. app.py +15 -17
  2. requirements.txt +5 -3
app.py CHANGED
@@ -3,15 +3,12 @@ from moviepy.editor import *
3
  from PIL import Image
4
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM,pipeline
5
  import gradio as gr
6
- import torch
7
- from huggingface_hub import snapshot_download
8
- from PIL import Image
9
  from min_dalle import MinDalle
10
- import torch
11
  from PIL import Image, ImageDraw, ImageFont
12
  import textwrap
13
  from mutagen.mp3 import MP3
14
- # to speech conversion
15
  from gtts import gTTS
16
  from pydub import AudioSegment
17
  from os import getcwd
@@ -23,13 +20,14 @@ title = "Video Story Generator with Audio by using dalle-mini and distilbart and
23
  tokenizer = AutoTokenizer.from_pretrained("sshleifer/distilbart-cnn-12-6")
24
  model = AutoModelForSeq2SeqLM.from_pretrained("sshleifer/distilbart-cnn-12-6")
25
 
26
- #device = "cuda:0" if torch.cuda.is_available() else "cpu"
27
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
28
  print(device)
29
 
30
- #device = torch.device('cuda')
31
- # transfer model
32
- #model.to(device)
 
 
33
 
34
  def get_output_video(text):
35
  inputs = tokenizer(text,
@@ -62,13 +60,12 @@ def get_output_video(text):
62
  model = MinDalle(
63
  is_mega=is_mega,
64
  models_root=models_root,
65
- is_reusable=False,
66
  is_verbose=True,
67
- #dtype=torch.float16 if fp16 else torch.float32
68
- dtype=torch.float32,
69
- #dtype=torch.float16,
70
- device='cpu' #'cuda'
71
  )
 
72
 
73
  image = model.generate_image(
74
  text,
@@ -86,11 +83,12 @@ def get_output_video(text):
86
  is_mega= True,
87
  text=senten,
88
  seed=1,
89
- grid_size=1,
90
- top_k=256,
 
91
  image_path='generated',
92
  models_root='pretrained',
93
- fp16=256,)
94
  generated_images.append(image)
95
 
96
  # Step 4- Creation of the subtitles
 
3
  from PIL import Image
4
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM,pipeline
5
  import gradio as gr
6
+ import torch, torch.backends.cudnn, torch.backends.cuda
 
 
7
  from min_dalle import MinDalle
8
+ from huggingface_hub import snapshot_download
9
  from PIL import Image, ImageDraw, ImageFont
10
  import textwrap
11
  from mutagen.mp3 import MP3
 
12
  from gtts import gTTS
13
  from pydub import AudioSegment
14
  from os import getcwd
 
20
  tokenizer = AutoTokenizer.from_pretrained("sshleifer/distilbart-cnn-12-6")
21
  model = AutoModelForSeq2SeqLM.from_pretrained("sshleifer/distilbart-cnn-12-6")
22
 
 
23
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
24
  print(device)
25
 
26
+ def log_gpu_memory():
27
+ print(subprocess.check_output('nvidia-smi').decode('utf-8'))
28
+
29
+ log_gpu_memory()
30
+
31
 
32
  def get_output_video(text):
33
  inputs = tokenizer(text,
 
60
  model = MinDalle(
61
  is_mega=is_mega,
62
  models_root=models_root,
63
+ is_reusable=True,
64
  is_verbose=True,
65
+ dtype=torch.float16 if fp16 else torch.float32 #param ["float32", "float16", "bfloat16"] #float32 is faster than float16 but uses more GPU memory.
66
+ device='cuda' #'cpu'
 
 
67
  )
68
+ log_gpu_memory()
69
 
70
  image = model.generate_image(
71
  text,
 
83
  is_mega= True,
84
  text=senten,
85
  seed=1,
86
+ grid_size=1, #param {type:"integer"}
87
+ top_k=128, #param {type:"integer"}
88
+
89
  image_path='generated',
90
  models_root='pretrained',
91
+ fp16=256,)
92
  generated_images.append(image)
93
 
94
  # Step 4- Creation of the subtitles
requirements.txt CHANGED
@@ -1,7 +1,7 @@
 
 
1
  gradio
2
- min-dalle
3
  transformers
4
- torch
5
  requests
6
  moviepy
7
  huggingface_hub
@@ -12,4 +12,6 @@ gTTS
12
  mutagen
13
  nltk
14
  accelerate
15
- nvidia-ml-py3
 
 
 
1
+ min-dalle==0.4.6
2
+ emoji==1.7.0
3
  gradio
 
4
  transformers
 
5
  requests
6
  moviepy
7
  huggingface_hub
 
12
  mutagen
13
  nltk
14
  accelerate
15
+ nvidia-ml-py3
16
+ --find-links https://download.pytorch.org/whl/torch_stable.html
17
+ torch==1.12.1+cu116