Spaces:
Runtime error
Runtime error
changed smth
Browse files- .gitattributes +0 -37
- README.md +0 -12
- RNN_model.keras +0 -3
- __init__.py +0 -0
- app.py +0 -34
- functions/model.keras +0 -3
- functions/model_infer.py +0 -40
- functions/punctuation.py +0 -58
- functions/tf_format.keras +0 -3
- model.keras +0 -3
- requirements.txt +0 -4
- tf_format.keras +0 -3
.gitattributes
DELETED
@@ -1,37 +0,0 @@
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
DELETED
@@ -1,12 +0,0 @@
|
|
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
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:642ec9499996ca6dcd3c8f2874ae3c5d9ca0095064d2f8faae1f12b2fea1e020
|
3 |
-
size 3974964
|
|
|
|
|
|
|
|
__init__.py
DELETED
File without changes
|
app.py
DELETED
@@ -1,34 +0,0 @@
|
|
1 |
-
from os import pipe
|
2 |
-
import gradio as gr
|
3 |
-
from functions.punctuation import punctuate
|
4 |
-
from functions.model_infer import predict_from_document
|
5 |
-
|
6 |
-
|
7 |
-
title = "sponsoredBye - never listen to sponsors again"
|
8 |
-
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."
|
9 |
-
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."
|
10 |
-
|
11 |
-
|
12 |
-
def pipeline(video_url):
|
13 |
-
video_id = video_url.split("?v=")[-1]
|
14 |
-
punctuated_text = punctuate(video_id)
|
15 |
-
sentences = re.split(r"[\.\!\?]\s", punctuated_text)
|
16 |
-
classification = predict_from_document(sentences)
|
17 |
-
# return punctuated_text
|
18 |
-
return [{"start": "12:05", "end": "12:52", "classification": str(classification)}]
|
19 |
-
|
20 |
-
|
21 |
-
# print(pipeline("VL5M5ZihJK4"))
|
22 |
-
demo = gr.Interface(
|
23 |
-
fn=pipeline,
|
24 |
-
title=title,
|
25 |
-
description=description,
|
26 |
-
inputs="text",
|
27 |
-
# outputs=gr.Label(num_top_classes=3),
|
28 |
-
outputs="json",
|
29 |
-
examples=[
|
30 |
-
"https://www.youtube.com/watch?v=VL5M5ZihJK4",
|
31 |
-
"https://www.youtube.com/watch?v=VL5M5ZihJK4",
|
32 |
-
],
|
33 |
-
)
|
34 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
functions/model.keras
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:5af590bbc6d50b5ca00d2f7cdca06d2e6c8ef94dd6e09019c69b75e816ca5d05
|
3 |
-
size 3977504
|
|
|
|
|
|
|
|
functions/model_infer.py
DELETED
@@ -1,40 +0,0 @@
|
|
1 |
-
from keras.preprocessing.sequence import pad_sequences
|
2 |
-
|
3 |
-
# import tensorflow as tf
|
4 |
-
import os
|
5 |
-
import requests
|
6 |
-
from keras.models import load_model
|
7 |
-
|
8 |
-
headers = {"Authorization": f"Bearer {os.environ['HF_Token']}"}
|
9 |
-
|
10 |
-
model = load_model("./RNN_model.keras")
|
11 |
-
|
12 |
-
|
13 |
-
def query_embeddings(texts):
|
14 |
-
payload = {"inputs": texts, "options": {"wait_for_model": True}}
|
15 |
-
|
16 |
-
model_id = "sentence-transformers/sentence-t5-base"
|
17 |
-
API_URL = (
|
18 |
-
f"https://api-inference.huggingface.co/pipeline/feature-extraction/{model_id}"
|
19 |
-
)
|
20 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
21 |
-
return response.json()
|
22 |
-
|
23 |
-
|
24 |
-
def preprocess(sentences):
|
25 |
-
max_len = 1682
|
26 |
-
embeddings = query_embeddings(sentences)
|
27 |
-
|
28 |
-
if len(sentences) > max_len:
|
29 |
-
X = embeddings[:max_len]
|
30 |
-
else:
|
31 |
-
X = embeddings
|
32 |
-
X_padded = pad_sequences([X], maxlen=max_len, dtype="float32", padding="post")
|
33 |
-
return X_padded
|
34 |
-
|
35 |
-
|
36 |
-
def predict_from_document(sentences):
|
37 |
-
preprop = preprocess(sentences)
|
38 |
-
prediction = model.predict(preprop)
|
39 |
-
output = (prediction.flatten()[: len(sentences)] >= 0.5).astype(int)
|
40 |
-
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
functions/punctuation.py
DELETED
@@ -1,58 +0,0 @@
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
functions/tf_format.keras
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:5af590bbc6d50b5ca00d2f7cdca06d2e6c8ef94dd6e09019c69b75e816ca5d05
|
3 |
-
size 3977504
|
|
|
|
|
|
|
|
model.keras
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:5af590bbc6d50b5ca00d2f7cdca06d2e6c8ef94dd6e09019c69b75e816ca5d05
|
3 |
-
size 3977504
|
|
|
|
|
|
|
|
requirements.txt
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
youtube_transcript_api
|
2 |
-
tensorflow==2.15
|
3 |
-
keras
|
4 |
-
keras-nlp
|
|
|
|
|
|
|
|
|
|
tf_format.keras
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:5af590bbc6d50b5ca00d2f7cdca06d2e6c8ef94dd6e09019c69b75e816ca5d05
|
3 |
-
size 3977504
|
|
|
|
|
|
|
|