Last active
October 9, 2022 07:54
-
-
Save astoeckl/caf7cd6fa698800446bc5a5c1aa57827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pytube import YouTube | |
import whisper | |
import openai | |
openai.api_key = YOUROPENAIKEY | |
from diffusers import StableDiffusionPipeline | |
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN) | |
def createarticle_from_video(url): | |
output = '' | |
video = YouTube(url).streams.filter(only_audio=True).first() | |
video.download('',"audio.mp4") | |
pipe = pipe.to("gpu") | |
model = whisper.load_model("base") | |
result = model.transcribe("audio.mp4") | |
newstext = result["text"] | |
prompt = "Newstext:\n" + newstext + "\nTitle:\n *" | |
response = openai.Completion.create( | |
engine="text-davinci-002", | |
prompt=str(prompt), | |
temperature=0, | |
max_tokens=25, | |
top_p=1, | |
frequency_penalty=0, | |
presence_penalty=0 | |
) | |
titeltext = response["choices"][0]["text"] | |
prompt = "Newstext:\n" + newstext + "\nMain facts:\n *" | |
response = openai.Completion.create( | |
engine="text-davinci-002", | |
prompt=str(prompt), | |
temperature=0, | |
max_tokens=100, | |
top_p=1, | |
frequency_penalty=0, | |
presence_penalty=0 | |
) | |
resulttext = "*" + response["choices"][0]["text"] | |
resultlist = resulttext.strip().split('*') | |
image = pipe(titeltext).images[0] | |
image.save("news.jpg") | |
output = output + "#" + titeltext + "\n" | |
output = output + "![" + titeltext + "](news.jpg?modified=1234567)" | |
for i, res in enumerate(resultlist): | |
output = output + res.strip() + "\n\n" | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment