Spaces:
Sleeping
Sleeping
upload
Browse files
app.py
CHANGED
@@ -1,10 +1,35 @@
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
from utils import get_youtube
|
4 |
from model import summarize_video
|
5 |
|
6 |
root_dir = '/home/user/app/video'
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
# ---- Gradio Layout -----
|
9 |
youtube_url_in = gr.Textbox(label="Youtube url", lines=1, interactive=True)
|
10 |
video_in = gr.Video(label="Input Video", mirror_webcam=False, interactive=True)
|
@@ -26,10 +51,15 @@ with demo:
|
|
26 |
### Summarize video
|
27 |
<ul>
|
28 |
<li>Step 1. download a video from youtube (select one of the examples and press the Download button)</li>
|
29 |
-
<li>Step 2: Select the summary rate and playback speed</li>
|
30 |
<li>Step 3: Generate a summarized video (press the Summarize button)</li>
|
31 |
</ul>
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
33 |
''')
|
34 |
with gr.Row():
|
35 |
gr.Markdown('''
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import base64
|
4 |
+
|
5 |
import gradio as gr
|
6 |
+
import firebase_admin
|
7 |
+
from firebase_admin import credentials
|
8 |
+
from firebase_admin import firestore
|
9 |
|
10 |
from utils import get_youtube
|
11 |
from model import summarize_video
|
12 |
|
13 |
root_dir = '/home/user/app/video'
|
14 |
|
15 |
+
db = firestore.client()
|
16 |
+
# 環境変数から秘密鍵を取得
|
17 |
+
encoded_key = os.environ["FIREBASE_CREDENTIALS_BASE64"]
|
18 |
+
# Base64エンコードされた秘密鍵をデコード
|
19 |
+
decoded_key = base64.b64decode(encoded_key)
|
20 |
+
# デコードされた秘密鍵を使ってCredentialオブジェクトを作成
|
21 |
+
cred = credentials.Certificate(json.loads(decoded_key))
|
22 |
+
# Firebase Admin SDKを初期化
|
23 |
+
firebase_admin.initialize_app(cred)
|
24 |
+
|
25 |
+
def log_firestore(user_id="000000", message="test"):
|
26 |
+
doc_ref = db.collection("button_clicks").document()
|
27 |
+
doc_ref.set({
|
28 |
+
"user_id": user_id,
|
29 |
+
"message": message,
|
30 |
+
"timestamp": firestore.SERVER_TIMESTAMP
|
31 |
+
})
|
32 |
+
|
33 |
# ---- Gradio Layout -----
|
34 |
youtube_url_in = gr.Textbox(label="Youtube url", lines=1, interactive=True)
|
35 |
video_in = gr.Video(label="Input Video", mirror_webcam=False, interactive=True)
|
|
|
51 |
### Summarize video
|
52 |
<ul>
|
53 |
<li>Step 1. download a video from youtube (select one of the examples and press the Download button)</li>
|
54 |
+
<li>Step 2: Select the summary rate and playback speed (select with slider)</li>
|
55 |
<li>Step 3: Generate a summarized video (press the Summarize button)</li>
|
56 |
</ul>
|
57 |
+
#### Output
|
58 |
+
<ul>
|
59 |
+
<li>An original downloaded video is displayed on the left side of the screen, and a summarized video is displayed on the right side of the screen.</li>
|
60 |
+
<li>A text summary of the video is displayed below it.</li>
|
61 |
+
<li>A transcription of the original video is displayed further down (the part extracted from the summarized video is highlighted).</li>
|
62 |
+
</ul>
|
63 |
''')
|
64 |
with gr.Row():
|
65 |
gr.Markdown('''
|
model.py
CHANGED
@@ -13,7 +13,8 @@ from transformers import pipeline, BertTokenizer, BertForNextSentencePrediction
|
|
13 |
import torch
|
14 |
import whisper
|
15 |
|
16 |
-
from utils import two_chnnel_to_one_channel, convert_sample_rate
|
|
|
17 |
|
18 |
subprocess.run(['apt-get', '-y', 'install', 'imagemagick'])
|
19 |
|
|
|
13 |
import torch
|
14 |
import whisper
|
15 |
|
16 |
+
from utils import two_chnnel_to_one_channel, convert_sample_rate
|
17 |
+
from app import log_firestore
|
18 |
|
19 |
subprocess.run(['apt-get', '-y', 'install', 'imagemagick'])
|
20 |
|
utils.py
CHANGED
@@ -1,30 +1,7 @@
|
|
1 |
-
import os
|
2 |
-
import json
|
3 |
-
import base64
|
4 |
-
|
5 |
-
import firebase_admin
|
6 |
-
from firebase_admin import credentials
|
7 |
-
from firebase_admin import firestore
|
8 |
from pytube import YouTube
|
9 |
from scipy.signal import resample
|
10 |
|
11 |
-
|
12 |
-
# 環境変数から秘密鍵を取得
|
13 |
-
encoded_key = os.environ["FIREBASE_CREDENTIALS_BASE64"]
|
14 |
-
# Base64エンコードされた秘密鍵をデコード
|
15 |
-
decoded_key = base64.b64decode(encoded_key)
|
16 |
-
# デコードされた秘密鍵を使ってCredentialオブジェクトを作成
|
17 |
-
cred = credentials.Certificate(json.loads(decoded_key))
|
18 |
-
# Firebase Admin SDKを初期化
|
19 |
-
firebase_admin.initialize_app(cred)
|
20 |
-
|
21 |
-
def log_firestore(user_id="000000", message="test"):
|
22 |
-
doc_ref = db.collection("button_clicks").document()
|
23 |
-
doc_ref.set({
|
24 |
-
"user_id": user_id,
|
25 |
-
"message": message,
|
26 |
-
"timestamp": firestore.SERVER_TIMESTAMP
|
27 |
-
})
|
28 |
|
29 |
def get_youtube(user_id, video_url):
|
30 |
# YouTubeの動画をダウンロード
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from pytube import YouTube
|
2 |
from scipy.signal import resample
|
3 |
|
4 |
+
from app import log_firestore
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def get_youtube(user_id, video_url):
|
7 |
# YouTubeの動画をダウンロード
|