IanRonk commited on
Commit
bce23e4
1 Parent(s): e7ccdc6
.gitattributes ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.keras filter=lfs diff=lfs merge=lfs -text
37
+ functions/*.keras filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ *.ipynb
2
+ */*.ipynb
3
+ .DS_Store
4
+ */.DS_Store
5
+ test/
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Sponsoredbye
3
+ emoji: 🦀
4
+ colorFrom: pink
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 4.31.4
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
RNN_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:642ec9499996ca6dcd3c8f2874ae3c5d9ca0095064d2f8faae1f12b2fea1e020
3
+ size 3974964
__init__.py ADDED
File without changes
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from os import pipe
2
+ import re
3
+ import gradio as gr
4
+ from functions.punctuation import punctuate
5
+ from functions.model_infer import predict_from_document
6
+
7
+
8
+ title = "sponsoredBye - never listen to sponsors again"
9
+ description = "Sponsored sections in videos are annoying and take up a lot of time. Improve your YouTube watching experience, by filling in the youtube url and figure out what segments to skip."
10
+ article = "Check out [the original Rick and Morty Bot](https://huggingface.co/spaces/kingabzpro/Rick_and_Morty_Bot) that this demo is based off of."
11
+
12
+
13
+ def pipeline(video_url):
14
+ video_id = video_url.split("?v=")[-1]
15
+ punctuated_text = punctuate(video_id)
16
+ sentences = re.split(r"[\.\!\?]\s", punctuated_text)
17
+ classification = predict_from_document(sentences)
18
+ # return punctuated_text
19
+ return [{"start": "12:05", "end": "12:52", "classification": str(classification)}]
20
+
21
+
22
+ # print(pipeline("VL5M5ZihJK4"))
23
+ demo = gr.Interface(
24
+ fn=pipeline,
25
+ title=title,
26
+ description=description,
27
+ inputs="text",
28
+ # outputs=gr.Label(num_top_classes=3),
29
+ outputs="json",
30
+ examples=[
31
+ "https://www.youtube.com/watch?v=VL5M5ZihJK4",
32
+ "https://www.youtube.com/watch?v=VL5M5ZihJK4",
33
+ ],
34
+ )
35
+ demo.launch(share=True)
functions/model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5af590bbc6d50b5ca00d2f7cdca06d2e6c8ef94dd6e09019c69b75e816ca5d05
3
+ size 3977504
functions/model_infer.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from keras.preprocessing.sequence import pad_sequences
2
+ import re
3
+
4
+ # import tensorflow as tf
5
+ import os
6
+ import requests
7
+ from keras.models import load_model
8
+
9
+ headers = {"Authorization": f"Bearer {os.environ['HF_Token']}"}
10
+
11
+ model = load_model("./RNN_model.keras")
12
+
13
+
14
+ def query_embeddings(texts):
15
+ payload = {"inputs": texts, "options": {"wait_for_model": True}}
16
+
17
+ model_id = "sentence-transformers/sentence-t5-base"
18
+ API_URL = (
19
+ f"https://api-inference.huggingface.co/pipeline/feature-extraction/{model_id}"
20
+ )
21
+ response = requests.post(API_URL, headers=headers, json=payload)
22
+ return response.json()
23
+
24
+
25
+ def preprocess(sentences):
26
+ max_len = 1682
27
+ embeddings = query_embeddings(sentences)
28
+
29
+ if len(sentences) > max_len:
30
+ X = embeddings[:max_len]
31
+ else:
32
+ X = embeddings
33
+ X_padded = pad_sequences([X], maxlen=max_len, dtype="float32", padding="post")
34
+ return X_padded
35
+
36
+
37
+ def predict_from_document(sentences):
38
+ preprop = preprocess(sentences)
39
+ prediction = model.predict(preprop)
40
+ output = (prediction.flatten()[: len(sentences)] >= 0.5).astype(int)
41
+ return output
functions/punctuation.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from youtube_transcript_api import YouTubeTranscriptApi
3
+ import json
4
+ import os
5
+
6
+ headers = {
7
+ "Authorization": f"Bearer {os.environ['HF_Token']}"
8
+ } # NOTE: put this somewhere else
9
+
10
+
11
+ def retrieve_transcript(vid_id):
12
+ try:
13
+ transcript = YouTubeTranscriptApi.get_transcript(vid_id)
14
+ return transcript
15
+ except Exception as e:
16
+ return None
17
+
18
+
19
+ def split_transcript(transcript, chunk_size=40):
20
+ sentences = []
21
+ for i in range(0, len(transcript), chunk_size):
22
+ to_add = [x["text"] for x in transcript[i : i + chunk_size]]
23
+ sentences.append(" ".join(to_add))
24
+ return sentences
25
+
26
+
27
+ def query_punctuation(splits):
28
+ payload = {"inputs": splits}
29
+ API_URL = "https://api-inference.huggingface.co/models/oliverguhr/fullstop-punctuation-multilang-large"
30
+ response = requests.post(API_URL, headers=headers, json=payload)
31
+ return response.json()
32
+
33
+
34
+ def parse_output(output, comb):
35
+ total = []
36
+
37
+ # loop over the response from the huggingface api
38
+ for i, o in enumerate(output):
39
+ added = 0
40
+ tt = comb[i]
41
+ for elem in o:
42
+ # Loop over the output chunks and add the . and ?
43
+ if elem["entity_group"] not in ["0", ",", ""]:
44
+ split = elem["end"] + added
45
+ tt = tt[:split] + elem["entity_group"] + tt[split:]
46
+ added += 1
47
+ total.append(tt)
48
+ return " ".join(total)
49
+
50
+
51
+ def punctuate(video_id):
52
+ transcript = retrieve_transcript(video_id)
53
+ splits = split_transcript(
54
+ transcript
55
+ ) # Get the transcript from the YoutubeTranscriptApi
56
+ resp = query_punctuation(splits) # Get the response from the Inference API
57
+ punctuated_transcript = parse_output(resp, splits)
58
+ return punctuated_transcript
model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5af590bbc6d50b5ca00d2f7cdca06d2e6c8ef94dd6e09019c69b75e816ca5d05
3
+ size 3977504
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ youtube_transcript_api
2
+ tensorflow==2.15
3
+ keras
4
+ keras-nlp