File size: 1,151 Bytes
99b9405
 
 
 
 
 
 
9f98d7f
 
99b9405
9f98d7f
 
 
99b9405
9f98d7f
99b9405
 
 
 
cdf9209
 
a758f6c
99b9405
a758f6c
99b9405
 
 
 
 
 
9f98d7f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import cv2
import numpy as np
import ffmpeg
from math import ceil
from segmindapi import SD2_1, Kadinsky
import gradio as gr
from .TextPreprocessor import TextPreprocessor
from .AVCombiner import AVCombiner
class Videobook:
  def __init__(self):
    self.preprocessor = TextPreprocessor()
    self.combiner = AVCombiner()
  def get_sentences(self, story):
    return self.preprocessor(story)

  def generate_imgs(self, sentences, steps):
    imgs = []
    for sentence in sentences:
      sentence['pos'] = self.style + ' of ' + str(sentence['pos']) + ', ' + self.tags
      imgs.append(self.pipe.generate(prompt = sentence['pos'], negative_prompt = str(sentence['neg']) + " ,nude, disfigured, blurry", num_inference_steps = steps))
    return imgs    

  def generate(self, story, api_key, style, tags, model, steps):
    self.style = style
    self.tags = tags
    if model == "Stable Diffusion v2.1":
      self.pipe = SD2_1(api_key)
    else:
      self.pipe = Kadinsky(api_key)
    processed_sentences, sentences = self.get_sentences(story)
    return AVCombiner()(self.generate_imgs(processed_sentences, steps), sentences, os.getcwd())