Skip to content

Commit

Permalink
Merge pull request #75 from saschanaz/pyproject
Browse files Browse the repository at this point in the history
Migrate to pyproject to be a library
  • Loading branch information
LuisMayo authored May 23, 2022
2 parents 68c1fc9 + c59ee44 commit a64b2f5
Show file tree
Hide file tree
Showing 20 changed files with 1,508 additions and 54 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is a fork of a wonderful [Reddit bot](https://github.com/micah5/ace-attorne
#### Optional
- [Google Translation API Credentials](https://cloud.google.com/translate/docs/setup): These are needed for language support other than English. Other languages may work even without this credentials as the system will fallback to TextBlob's translation system.
- Libraqm: Improves text rendering on right-to-left languages. In windows refer to the faq.md

### Installing

Clone the repository
Expand All @@ -28,7 +28,7 @@ git clone https://github.com/LuisMayo/objection_engine
```
Install dependencies (in case any problems are encountered please check faq.md)
``` bash
python -m pip install -r requirements.txt
python -m pip install -r pyproject.toml
```

(optional) In case you want language support outside English install polyglot and its dependencies:
Expand All @@ -43,13 +43,11 @@ Check the exmaple
`python example.py`

### Using it as a library
- Add it as a library with
`git submodule add https://github.com/LuisMayo/objection_engine.git`
- Add this git repository as a library:
`git+https://github.com/LuisMayo/objection_engine.git`

- Import it into your python file
``` python
import sys
sys.path.append('objection_engine/')
import objection_engine
# You can also import the components like this
from objection_engine.renderer import render_comment_list
Expand Down
3 changes: 0 additions & 3 deletions __init__.py

This file was deleted.

7 changes: 3 additions & 4 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from renderer import render_comment_list
from beans.comment import Comment
from objection_engine.renderer import render_comment_list
from objection_engine.beans.comment import Comment
from time import time
import anim

comments = [
Comment(user_name = 'a', text_content='Hello as I am the most common I will be Phoenix'),
Expand All @@ -19,7 +18,7 @@
Comment(user_name = 'l', text_content='Hello OwO'),
Comment(user_name = 'm', text_content='Hello OwO'),
Comment(user_name = 'n', text_content='Hello OwO'),
Comment(user_name = 'o', text_content='《长征》第1集 The Long March 01震惊世界的二万五千里长征(唐国强/陈道明)【CCTV电视剧】Highlights:毛泽东针对奔袭湘江的作战命令会给数万红军带来的严重损失,连夜找“三人团”请示复议作战计划,李德不耐烦地指责毛泽东是在危言耸听。'),
Comment(user_name = 'o', text_content='《长征》第1集 The Long March 01震惊世界的二万五千里长征(唐国强/陈道明)【CCTV电视剧】Highlights:毛泽东针对奔袭湘江的作战命令会给数万红军带来的严重损失,连夜找“三人团”请示复议作战计划,李德不耐烦地指责毛泽东是在危言耸听。'),
Comment(user_name = 'o', text_content='Hello OwO')
] * 1
render_comment_list(comments, f'output-{str(int(time()))}.mp4')
3 changes: 3 additions & 0 deletions objection_engine/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .beans import comment
from .renderer import render_comment_list
from .utils import is_music_available, get_all_music_available
16 changes: 8 additions & 8 deletions anim.py → objection_engine/anim.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from math import ceil
from beans.comment_bridge import CommentBridge
from .beans.comment_bridge import CommentBridge
from PIL import Image, ImageDraw, ImageFont , ImageFile
# ImageFile.LOAD_TRUNCATED_IMAGES = True
from matplotlib.pyplot import imshow
Expand All @@ -18,14 +18,14 @@
import random
from textwrap import wrap
import spacy
from polarity_analysis import Analizer
from .polarity_analysis import Analizer
analizer = Analizer()
from beans.img import AnimImg
from beans.text import AnimText
from beans.scene import AnimScene
from beans.video import AnimVideo
from constants import Character, lag_frames, fps
import constants
from .beans.img import AnimImg
from .beans.text import AnimText
from .beans.scene import AnimScene
from .beans.video import AnimVideo
from .constants import Character, lag_frames, fps
from . import constants
import re

nlp = spacy.load("xx_ent_wiki_sm")
Expand Down
2 changes: 1 addition & 1 deletion beans/comment.py → objection_engine/beans/comment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from constants import Character
from ..constants import Character

"""
All arguments are optional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from beans.comment import Comment
from .comment import Comment
"""
Internal use only, do not use outside here
"""
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions beans/scene.py → objection_engine/beans/scene.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List
from beans.img import AnimImg
from beans.text import AnimText
from .img import AnimImg
from .text import AnimText

class AnimScene:
def __init__(self, arr: List, length: int, start_frame: int = 0):
Expand Down
4 changes: 2 additions & 2 deletions beans/text.py → objection_engine/beans/text.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict
from PIL import Image, ImageDraw, ImageFont
from fontTools.ttLib import TTFont
from fonttools.ttLib import TTFont


FONT_ARRAY = [
Expand Down Expand Up @@ -98,4 +98,4 @@ def is_renderable(text):
score = 0
for font in FONT_ARRAY:
score = max(score, score_font(font, text))
return score >= len(text)
return score >= len(text)
2 changes: 1 addition & 1 deletion beans/video.py → objection_engine/beans/video.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List
from beans import scene
from . import scene
import cv2
import os
import numpy as np
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions renderer.py → objection_engine/renderer.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import random
from typing import List
from utils import get_characters
from beans.comment_bridge import CommentBridge
from beans.comment import Comment
from .utils import get_characters
from .beans.comment_bridge import CommentBridge
from .beans.comment import Comment
from collections import Counter
import anim
from . import anim
import os
from utils import ensure_assets_are_available
from .utils import ensure_assets_are_available
import requests


def render_comment_list(comment_list: List[Comment], output_filename = 'hello.mp4', music_code = 'PWR', resolution_scale: int = 1):
ensure_assets_are_available()
try:
try:
collect_stats()
except:
pass
Expand Down
2 changes: 1 addition & 1 deletion utils.py → objection_engine/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from constants import Character
from .constants import Character
import random
from collections import Counter
import os
Expand Down
Loading

0 comments on commit a64b2f5

Please sign in to comment.