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
import markdown | |
from IPython.core.display import HTML | |
art = createarticle_from_video('https://www.youtube.com/watch?v=oaNwxtLKyk0') | |
HTML(markdown.markdown(art)) |
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 = '' |
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 diffusers import StableDiffusionPipeline | |
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN) | |
pipe = pipe.to("gpu") | |
image = pipe(titeltext).images[0] | |
image.save("news.jpg") |
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
import openai | |
openai.api_key = YOUROPENAIKEY | |
newstext = result["text"] | |
prompt = "Newstext:\n" + newstext + "\nTitle:\n *" | |
response = openai.Completion.create( | |
engine="text-davinci-002", | |
prompt=str(prompt), |
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
import whisper | |
model = whisper.load_model("base") | |
result = model.transcribe("bbc.mp4") | |
print(result["text"]) |
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 | |
stream = YouTube('https://www.youtube.com/watch?v=oaNwxtLKyk0').streams.filter(only_audio=True).first() | |
stream.download('',"bbc.mp4") |
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
import openai | |
openai.api_key = "XXX-YOURKEY" | |
doc_per_cluster = 3 | |
for i in range(no_clusters): | |
print(f"Cluster {i} Topic:", end=" ") | |
docs = "\n".join(df[df.Cluster == i].Text.map(lambda x: x[:1000]).sample(doc_per_cluster, random_state=42).values) | |
response = openai.Completion.create( |
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
import seaborn as sns | |
from sklearn.manifold import TSNE | |
import matplotlib | |
import matplotlib.pyplot as plt | |
plt.rcParams['figure.figsize'] = (15, 8) | |
tsne = TSNE(n_components=2, perplexity=15, random_state=42, init='random', learning_rate=200) | |
vis_dims2 = tsne.fit_transform(matrix) | |
x = [x for x,y in vis_dims2] |
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 sklearn.cluster import KMeans | |
from tqdm.notebook import tqdm | |
from sklearn.metrics import silhouette_score | |
X = matrix | |
cluster_results_km = pd.DataFrame({'K': range(6, 25), 'SIL': np.nan}) | |
cluster_results_km.set_index('K', inplace=True) | |
for k in tqdm(cluster_results_km.index): | |
km_model = KMeans(n_clusters = k, init ='k-means++', random_state = 42) | |
y = km_model.fit_predict(X) |
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
import openai | |
import numpy as np | |
openai.api_key = "XXX-YOUkey" | |
from tenacity import retry, wait_random_exponential, stop_after_attempt | |
@retry(wait=wait_random_exponential(min=1, max=20), stop=stop_after_attempt(6)) | |
def get_embedding(text, engine="davinci-similarity"): |
NewerOlder