Skip to content

Commit

Permalink
Fixing & upgrading project. Openai gpt3.5 -> gpt4-o-mini. Moviepy v1 …
Browse files Browse the repository at this point in the history
…-> v2 . Fonts: Roboto -> Luckiest guy
  • Loading branch information
RayVentura committed Jan 13, 2025
1 parent e85f581 commit 38e776b
Show file tree
Hide file tree
Showing 60 changed files with 611 additions and 704 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ build
setup
test.ipynb
.venv/
MANIFEST.in
MANIFEST.in
schema.json
video.mp4
15 changes: 3 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# Use an official Python runtime as the parent image
FROM python:3.11-bullseye
RUN apt-get update && apt-get install -y \
ffmpeg \
imagemagick \
ghostscript \
fonts-roboto \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Update font cache
RUN fc-cache -f -v

RUN sed -i '/<policy domain="path" rights="none" pattern="@\*"/d' /etc/ImageMagick-6/policy.xml
FROM python:3.10-slim-bullseye
RUN apt-get update && apt-get install -y ffmpeg
# Clean up APT when done
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

Expand All @@ -35,4 +26,4 @@ EXPOSE 31415
RUN ["printenv"]

# Run Python script when the container launches
CMD ["python", "./runShortGPT.py"]
CMD ["python", "-u", "./runShortGPT.py"]
8 changes: 4 additions & 4 deletions docs/docs/api-key-manager.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ In the above example, we are retrieving the API keys for OPENAI and ELEVEN_LABS.
The `key` argument in both methods can either be a string or an instance of the `ApiProvider` enum. If it is an instance of `ApiProvider`, the `value` attribute of the enum instance will be used as the key.

```python
ApiKeyManager.set_api_key("OPENAI", "your_openai_key")
ApiKeyManager.set_api_key("ELEVEN LABS", "your_eleven_labs_key")
ApiKeyManager.set_api_key("OPENAI_API_KEY", "your_openai_key")
ApiKeyManager.set_api_key("ELEVENLABS_API_KEY", "your_eleven_labs_key")

openai_key = ApiKeyManager.get_api_key("OPENAI")
eleven_labs_key = ApiKeyManager.get_api_key("ELEVEN LABS")
openai_key = ApiKeyManager.get_api_key("OPENAI_API_KEY")
eleven_labs_key = ApiKeyManager.get_api_key("ELEVENLABS_API_KEY")
```
In the above example, we are setting and retrieving the API keys using string keys instead of `ApiProvider` instances.
2 changes: 1 addition & 1 deletion docs/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ USE_ELEVEN_LABS = False
# Configure the ElevenLabs Voice Module
if USE_ELEVEN_LABS:
eleven_labs_key = ApiKeyManager.get_api_key(ApiProvider.ELEVEN_LABS)
voice_module = ElevenLabsVoiceModule(api_key = eleven_labs_key, voiceName="Antoni")
voice_module = ElevenLabsVoiceModule(api_key = eleven_labs_key, voiceName="Chris")
else:
## You can also use the EdgeTTS for Free voice synthesis
voice_name = EDGE_TTS_VOICENAME_MAPPING[Language.GERMAN]['male']
Expand Down
Binary file added fonts/LuckiestGuy-Regular.ttf
Binary file not shown.
Binary file added fonts/ObelixProB-cyr.ttf
Binary file not shown.
Binary file added fonts/Roboto-Bold.ttf
Binary file not shown.
92 changes: 10 additions & 82 deletions gui/asset_components.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import platform
import random
import subprocess

import gradio as gr
Expand All @@ -11,69 +12,8 @@

class AssetComponentsUtils:
EDGE_TTS = "Free EdgeTTS (lower quality)"
COQUI_TTS = "Free CoquiTTS (needs a powerful GPU)"
ELEVEN_TTS = "ElevenLabs(Very High Quality)"

COQUI_TTS_VOICES = [
"Claribel Dervla",
"Daisy Studious",
"Gracie Wise",
"Tammie Ema",
"Alison Dietlinde",
"Ana Florence",
"Annmarie Nele",
"Asya Anara",
"Brenda Stern",
"Gitta Nikolina",
"Henriette Usha",
"Sofia Hellen",
"Tammy Grit",
"Tanja Adelina",
"Vjollca Johnnie",
"Andrew Chipper",
"Badr Odhiambo",
"Dionisio Schuyler",
"Royston Min",
"Viktor Eka",
"Abrahan Mack",
"Adde Michal",
"Baldur Sanjin",
"Craig Gutsy",
"Damien Black",
"Gilberto Mathias",
"Ilkin Urbano",
"Kazuhiko Atallah",
"Ludvig Milivoj",
"Suad Qasim",
"Torcull Diarmuid",
"Viktor Menelaos",
"Zacharie Aimilios",
"Nova Hogarth",
"Maja Ruoho",
"Uta Obando",
"Lidiya Szekeres",
"Chandra MacFarland",
"Szofi Granger",
"Camilla Holmström",
"Lilya Stainthorpe",
"Zofija Kendrick",
"Narelle Moon",
"Barbora MacLean",
"Alexandra Hisakawa",
"Alma María",
"Rosemary Okafor",
"Ige Behringer",
"Filip Traverse",
"Damjan Chapman",
"Wulf Carlevaro",
"Aaron Dreschner",
"Kumar Dahl",
"Eugenio Mataracı",
"Ferran Simen",
"Xavier Hayasaka",
"Luis Moray",
"Marcos Rudaski",
]

instance_background_video_checkbox = None
instance_background_music_checkbox = None
Expand All @@ -94,7 +34,7 @@ def getBackgroundMusicChoices(cls):

@classmethod
def getElevenlabsVoices(cls):
api_key = ApiKeyManager.get_api_key("ELEVEN LABS")
api_key = ApiKeyManager.get_api_key("ELEVENLABS_API_KEY")
voices = list(reversed(ElevenLabsAPI(api_key).get_voices().keys()))
return voices

Expand All @@ -110,20 +50,24 @@ def start_file(cls, path):
@classmethod
def background_video_checkbox(cls):
if cls.instance_background_video_checkbox is None:
choices = cls.getBackgroundVideoChoices()
cls.instance_background_video_checkbox = gr.CheckboxGroup(
choices=cls.getBackgroundVideoChoices(),
choices=choices,
interactive=True,
label="Choose background video",
value=random.choice(choices)
)
return cls.instance_background_video_checkbox

@classmethod
def background_music_checkbox(cls):
if cls.instance_background_music_checkbox is None:
choices = cls.getBackgroundMusicChoices()
cls.instance_background_music_checkbox = gr.CheckboxGroup(
choices=cls.getBackgroundMusicChoices(),
choices=choices,
interactive=True,
label="Choose background music",
value=random.choice(choices)
)
return cls.instance_background_music_checkbox

Expand All @@ -133,19 +77,10 @@ def voiceChoice(cls, provider: str = None):
provider = cls.ELEVEN_TTS
if cls.instance_voiceChoice.get(provider, None) is None:
if provider == cls.ELEVEN_TTS:
print("getting eleven voices")
cls.instance_voiceChoice[provider] = gr.Radio(
cls.getElevenlabsVoices(),
label="Elevenlabs voice",
value="Antoni",
interactive=True,
)
elif provider == cls.COQUI_TTS:
print("getting coqui voices")
cls.instance_voiceChoice[provider] = gr.Dropdown(
cls.COQUI_TTS_VOICES,
label="CoquiTTS voice",
value="Ana Florence",
value="Chris",
interactive=True,
)
return cls.instance_voiceChoice[provider]
Expand All @@ -159,14 +94,7 @@ def voiceChoiceTranslation(cls, provider: str = None):
cls.instance_voiceChoiceTranslation[provider] = gr.Radio(
cls.getElevenlabsVoices(),
label="Elevenlabs voice",
value="Antoni",
interactive=True,
)
elif provider == cls.COQUI_TTS:
cls.instance_voiceChoiceTranslation[provider] = gr.Radio(
cls.COQUI_TTS_VOICES,
label="CoquiTTS voice",
value="Ana Florence",
value="Chris",
interactive=True,
)
return cls.instance_voiceChoiceTranslation[provider]
26 changes: 13 additions & 13 deletions gui/asset_library_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def __add_youtube_asset(self, asset_name, yt_url, type):
'''Add a youtube asset'''
AssetDatabase.add_remote_asset(asset_name, type, yt_url)
latest_df = AssetDatabase.get_df()
return gr.DataFrame.update(value=latest_df), gr.HTML.update(value=self.__get_asset_embed(latest_df, 0)),\
return gr.DataFrame.update(value=latest_df), gr.update(value=self.__get_asset_embed(latest_df, 0)),\
gr.update(value=f"🗑️ Delete {latest_df.iloc[0]['name']}"),\
gr.Accordion.update(open=False),\
gr.CheckboxGroup.update(choices=getBackgroundVideoChoices(), interactive=True),\
gr.CheckboxGroup.update(choices=getBackgroundMusicChoices(), interactive=True)
gr.update(open=False),\
gr.update(choices=getBackgroundVideoChoices(), interactive=True),\
gr.update(choices=getBackgroundMusicChoices(), interactive=True)
def __get_first_preview(self):
'''Get the first preview'''
Expand All @@ -71,20 +71,20 @@ def __delete_clicked(self, button_name):
data = AssetDatabase.get_df()
if len(data) > 0:
return gr.update(value=data),\
gr.HTML.update(value=self.__get_asset_embed(data, 0)),\
gr.update(value=self.__get_asset_embed(data, 0)),\
gr.update(value=f"🗑️ Delete {data.iloc[0]['name']}"),\
gr.CheckboxGroup.update(choices=getBackgroundVideoChoices(), interactive=True),\
gr.CheckboxGroup.update(choices=getBackgroundMusicChoices(), interactive=True)
gr.update(choices=getBackgroundVideoChoices(), interactive=True),\
gr.update(choices=getBackgroundMusicChoices(), interactive=True)
return gr.Dataframe.update(value=data),\
gr.HTML.update(visible=True),\
gr.Button.update(value="🗑️ Delete"),\
gr.CheckboxGroup.update(choices=getBackgroundVideoChoices(), interactive=True),\
gr.CheckboxGroup.update(choices=getBackgroundMusicChoices(), interactive=True)
gr.update(visible=True),\
gr.update(value="🗑️ Delete"),\
gr.update(choices=getBackgroundVideoChoices(), interactive=True),\
gr.update(choices=getBackgroundMusicChoices(), interactive=True)
def __preview_asset(self, data, evt: gr.SelectData):
'''Preview an asset'''
html_embed = self.__get_asset_embed(data, evt.index[0])
return gr.HTML.update(value=html_embed), gr.update(value=f"🗑️ Delete {data.iloc[evt.index[0]]['name']}")
return gr.update(value=html_embed), gr.update(value=f"🗑️ Delete {data.iloc[evt.index[0]]['name']}")
def __get_asset_embed(self, data, row):
'''Get the asset embed'''
Expand All @@ -96,7 +96,7 @@ def __get_asset_embed(self, data, row):
asset_link = f"https://youtube.com/embed/{asset_link.split('?v=')[-1]}"
embed_html = f'<iframe width="{embed_width}" height="{embed_height}" src="{asset_link}"></iframe>'
elif 'public/' in asset_link:
asset_link = f"http://localhost:31415/file={asset_link}"
asset_link = f"http://localhost:31415/gradio_api/file={asset_link}"
file_ext = asset_link.split('.')[-1]
if file_ext in ['mp3', 'wav', 'ogg']:
Expand Down
9 changes: 7 additions & 2 deletions gui/content_automation_ui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
import gradio as gr

from gui.ui_tab_short_automation import ShortAutomationUI
Expand All @@ -19,6 +20,10 @@ def create_ui(self):
video_automation_ui = VideoAutomationUI(self.shortGPTUI).create_ui()
short_automation_ui = ShortAutomationUI(self.shortGPTUI).create_ui()
video_translation_ui = VideoTranslationUI(self.shortGPTUI).create_ui()
choice.change(lambda x: (gr.update(visible=x == choice.choices[1]), gr.update(visible=x == choice.choices[0]), gr.update(
visible=x == choice.choices[2])), [choice], [video_automation_ui, short_automation_ui, video_translation_ui])
def onChange(x):
showShorts= x == choice.choices[0][0]
showVideo = x == choice.choices[1][0]
showTranslation= x == choice.choices[2][0]
return gr.update(visible=showShorts), gr.update(visible=showVideo), gr.update(visible=showTranslation)
choice.change(onChange, [choice], [short_automation_ui,video_automation_ui, video_translation_ui])
return self.content_automation_ui
20 changes: 18 additions & 2 deletions gui/gui_gradio.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, colab=False):

def create_interface(self):
'''Create Gradio interface'''
with gr.Blocks(css="footer {visibility: hidden}", title="ShortGPT Demo") as shortGptUI:
with gr.Blocks(theme=gr.themes.Default(spacing_size=gr.themes.sizes.spacing_sm), css="footer {visibility: hidden}", title="ShortGPT Demo") as shortGptUI:
with gr.Row(variant='compact'):
gr.HTML(GradioComponentsHTML.get_html_header())

Expand All @@ -30,9 +30,25 @@ def create_interface(self):
def launch(self):
'''Launch the server'''
shortGptUI = self.create_interface()
shortGptUI.queue(concurrency_count=5, max_size=20).launch(server_port=31415, height=1000, share=self.colab, server_name="0.0.0.0")
if not getattr(self, 'colab', False):
print("\n\n********************* STARTING SHORGPT **********************")
print("\nShortGPT is running here 👉 http://localhost:31415\n")
print("********************* STARTING SHORGPT **********************\n\n")
shortGptUI.queue().launch(server_port=31415, height=1000, allowed_paths=["public/","videos/","fonts/"], share=self.colab, server_name="0.0.0.0")



if __name__ == "__main__":
app = ShortGptUI()
app.launch()


import signal

def signal_handler(sig, frame):
print("Closing Gradio server...")
import gradio as gr
gr.close_all()
exit(0)

signal.signal(signal.SIGINT, signal_handler)
2 changes: 1 addition & 1 deletion gui/ui_abstract_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AbstractBaseUI:
'''Base class for the GUI. This class is responsible for creating the UI and launching the server.'''
max_choices = 20
ui_asset_dataframe = gr.Dataframe(interactive=False)
LOGO_PATH = "http://localhost:31415/file=public/logo.png"
LOGO_PATH = "http://localhost:31415/gradio_api/file=public/logo.png"
LOGO_DIM = 64

def __init__(self, ui_name='default'):
Expand Down
12 changes: 6 additions & 6 deletions gui/ui_components_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def get_html_header() -> str:
<a href="https://discord.gg/bWreuAyRaj" target="_blank" style="text-decoration: none;">
<button style="margin-right: 10px; padding: 10px 20px; font-size: 16px; color: #fff; background-color: #7289DA; border: none; border-radius: 5px; cursor: pointer;">Join Discord</button>
</a>
<a href="https://shortx.ai/?ref=sgpt" target="_blank" style="text-decoration: none;">
<button style="padding: 10px 20px; font-size: 16px; color: #fff; background-color: #333; border: none; border-radius: 5px; cursor: pointer;">Join ShortX, the next upgrade of ShortGPT ⭐</button>
<a href="https://github.com/RayVentura/ShortGPT" target="_blank" style="text-decoration: none;">
<button style="padding: 10px 20px; font-size: 16px; color: #fff; background-color: #333; border: none; border-radius: 5px; cursor: pointer;">Like the concept? Add a Star on Github 👉 ⭐</button>
</a>
</div>
</div>
Expand All @@ -20,10 +20,10 @@ def get_html_header() -> str:
@staticmethod
def get_html_error_template() -> str:
return '''
<div style='text-align: center; background: #f2dede; color: #a94442; padding: 20px; border-radius: 5px; margin: 10px;'>
<h2 style='margin: 0;'>ERROR : {error_message}</h2>
<p style='margin: 10px 0;'>Traceback Info : {stack_trace}</p>
<p style='margin: 10px 0;'>If the problem persists, don't hesitate to contact our support. We're here to assist you.</p>
<div style='text-align: center; background: #ff7f7f; color: #a94442; padding: 20px; border-radius: 5px; margin: 10px;'>
<h2 style='margin: 0; color: black'>ERROR : {error_message}</h2>
<p style='margin: 10px 0; color: black'>Traceback Info : {stack_trace}</p>
<p style='margin: 10px 0; color: black'>If the problem persists, don't hesitate to contact our support. We're here to assist you.</p>
<a href='https://discord.gg/qn2WJaRH' target='_blank' style='background: #a94442; color: #fff; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; text-decoration: none;'>Get Help on Discord</a>
</div>
'''
Expand Down
Loading

0 comments on commit 38e776b

Please sign in to comment.