Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,29 @@ from youtube_transcript_api import YouTubeTranscriptApi
|
|
| 3 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 4 |
import gradio as gr
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# Load the Hugging Face model and tokenizer
|
| 7 |
model_name = "sshleifer/distilbart-cnn-12-6"
|
| 8 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
|
@@ -26,6 +49,17 @@ def get_transcript(youtube_url):
|
|
| 26 |
summary_ids = model.generate(inputs["input_ids"], num_beams=4, max_length=100, early_stopping=True)
|
| 27 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
return summary
|
| 30 |
|
| 31 |
# Create a Gradio interface
|
|
@@ -44,5 +78,7 @@ iface = gr.Interface(
|
|
| 44 |
concurrency_limit=8
|
| 45 |
)
|
| 46 |
|
|
|
|
|
|
|
| 47 |
# Launch the Gradio interface
|
| 48 |
iface.launch(share=False)
|
|
|
|
| 3 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
import os
|
| 7 |
+
import uuid
|
| 8 |
+
import joblib
|
| 9 |
+
import json
|
| 10 |
+
|
| 11 |
+
from huggingface_hub import CommitScheduler
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
Prepare the logging functionality
|
| 16 |
+
|
| 17 |
+
log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
|
| 18 |
+
log_folder = log_file.parent
|
| 19 |
+
|
| 20 |
+
scheduler = CommitScheduler(
|
| 21 |
+
repo_id="YouTubeSummarizer-log",
|
| 22 |
+
repo_type="dataset",
|
| 23 |
+
folder_path=log_folder,
|
| 24 |
+
path_in_repo="data",
|
| 25 |
+
every=2
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
# Load the Hugging Face model and tokenizer
|
| 30 |
model_name = "sshleifer/distilbart-cnn-12-6"
|
| 31 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
|
|
|
| 49 |
summary_ids = model.generate(inputs["input_ids"], num_beams=4, max_length=100, early_stopping=True)
|
| 50 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 51 |
|
| 52 |
+
|
| 53 |
+
with scheduler.lock:
|
| 54 |
+
with log_file.open("a") as f:
|
| 55 |
+
f.write(json.dumps(
|
| 56 |
+
{
|
| 57 |
+
'YouTube URL': youtube_url,
|
| 58 |
+
'Summary': summary
|
| 59 |
+
}
|
| 60 |
+
))
|
| 61 |
+
f.write("\n")
|
| 62 |
+
|
| 63 |
return summary
|
| 64 |
|
| 65 |
# Create a Gradio interface
|
|
|
|
| 78 |
concurrency_limit=8
|
| 79 |
)
|
| 80 |
|
| 81 |
+
|
| 82 |
+
|
| 83 |
# Launch the Gradio interface
|
| 84 |
iface.launch(share=False)
|