Spaces:
Sleeping
Sleeping
upload
Browse files- .gitignore +2 -1
- __pycache__/model.cpython-39.pyc +0 -0
- __pycache__/utils.cpython-39.pyc +0 -0
- app.py +46 -26
- model.py +13 -10
- utils.py +11 -9
.gitignore
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
*.mp4
|
2 |
-
notebooks/*
|
|
|
|
1 |
*.mp4
|
2 |
+
notebooks/*
|
3 |
+
download_db.py
|
__pycache__/model.cpython-39.pyc
CHANGED
Binary files a/__pycache__/model.cpython-39.pyc and b/__pycache__/model.cpython-39.pyc differ
|
|
__pycache__/utils.cpython-39.pyc
CHANGED
Binary files a/__pycache__/utils.cpython-39.pyc and b/__pycache__/utils.cpython-39.pyc differ
|
|
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import os
|
|
|
|
|
2 |
import json
|
3 |
import base64
|
4 |
-
from functools import partial
|
5 |
|
6 |
import gradio as gr
|
7 |
import firebase_admin
|
@@ -11,19 +12,32 @@ from firebase_admin import firestore
|
|
11 |
from utils import get_youtube
|
12 |
from model import summarize_video
|
13 |
|
14 |
-
root_dir = '/home/user/app/video'
|
15 |
-
|
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 |
db = firestore.client()
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# ---- Gradio Layout -----
|
28 |
youtube_url_in = gr.Textbox(label="Youtube url", lines=1, interactive=True)
|
29 |
video_in = gr.Video(label="Input Video", mirror_webcam=False, interactive=True)
|
@@ -41,26 +55,33 @@ with demo:
|
|
41 |
</div>
|
42 |
''')
|
43 |
with gr.Row():
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
<ul>
|
53 |
-
<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>
|
54 |
-
<li>A text summary of the video is displayed below it.</li>
|
55 |
-
<li>A transcription of the original video is displayed further down (the part extracted from the summarized video is highlighted).</li>
|
56 |
-
</ul>
|
57 |
-
''')
|
58 |
with gr.Row():
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
with gr.Row():
|
65 |
gr.Markdown('''
|
66 |
### You can test by following examples:
|
@@ -73,15 +94,14 @@ with demo:
|
|
73 |
with gr.Column():
|
74 |
youtube_url_in.render()
|
75 |
download_youtube_btn = gr.Button("Download Youtube video")
|
76 |
-
get_youtube_wrapped = partial(get_youtube,
|
77 |
download_youtube_btn.click(get_youtube_wrapped, [youtube_url_in], [video_in])
|
78 |
-
print(video_in)
|
79 |
with gr.Row():
|
80 |
sum_ratio = gr.Slider(label="Summarize Ratio", minimum=0.3, maximum=0.8, step=0.05, value=0.6)
|
81 |
playback_speed = gr.Slider(label="Playback Speed", minimum=0.5, maximum=2.0, step=0.25, value=1.0)
|
82 |
with gr.Row():
|
83 |
upload_output_video_btn = gr.Button("Summarize Video")
|
84 |
-
summarize_video_wrapped = partial(summarize_video,
|
85 |
upload_output_video_btn.click(summarize_video_wrapped, [video_in, sum_ratio, playback_speed], [video_out, summary_text, transcription_text])
|
86 |
with gr.Row():
|
87 |
video_in.render()
|
@@ -91,5 +111,5 @@ with demo:
|
|
91 |
with gr.Row():
|
92 |
transcription_text.render()
|
93 |
|
94 |
-
# demo.launch(debug=True, share)
|
95 |
demo.launch(debug=True)
|
|
|
1 |
import os
|
2 |
+
import random
|
3 |
+
from functools import partial
|
4 |
import json
|
5 |
import base64
|
|
|
6 |
|
7 |
import gradio as gr
|
8 |
import firebase_admin
|
|
|
12 |
from utils import get_youtube
|
13 |
from model import summarize_video
|
14 |
|
|
|
|
|
15 |
# 環境変数から秘密鍵を取得
|
16 |
encoded_key = os.environ["FIREBASE_CREDENTIALS_BASE64"]
|
17 |
# Base64エンコードされた秘密鍵をデコード
|
18 |
decoded_key = base64.b64decode(encoded_key)
|
19 |
# デコードされた秘密鍵を使ってCredentialオブジェクトを作成
|
20 |
cred = credentials.Certificate(json.loads(decoded_key))
|
21 |
+
# cred = credentials.Certificate('/home/kazuki/casp/fastperson-538e9-firebase-adminsdk-285dh-fa3faea9d0.json')
|
22 |
# Firebase Admin SDKを初期化
|
23 |
firebase_admin.initialize_app(cred)
|
24 |
|
25 |
db = firestore.client()
|
26 |
|
27 |
+
def log_firestore(db, local_id="000000", action="test", user_id=""):
|
28 |
+
data = {
|
29 |
+
"local_id": local_id,
|
30 |
+
"timestamp": firestore.SERVER_TIMESTAMP,
|
31 |
+
"action": action,
|
32 |
+
"user_id": user_id
|
33 |
+
}
|
34 |
+
doc_ref = db.collection("exp.1").document()
|
35 |
+
doc_ref.set(data)
|
36 |
+
|
37 |
+
local_id = random.randint(0, 10000000)
|
38 |
+
def store_local_id(user_id, local_id, db):
|
39 |
+
log_firestore(db, local_id=str(local_id), action='ID', user_id=str(user_id))
|
40 |
+
|
41 |
# ---- Gradio Layout -----
|
42 |
youtube_url_in = gr.Textbox(label="Youtube url", lines=1, interactive=True)
|
43 |
video_in = gr.Video(label="Input Video", mirror_webcam=False, interactive=True)
|
|
|
55 |
</div>
|
56 |
''')
|
57 |
with gr.Row():
|
58 |
+
gr.Markdown('''
|
59 |
+
### Summarize video
|
60 |
+
<ul>
|
61 |
+
<li>Step 1. download a video from youtube (select one of the examples and press the Download button)</li>
|
62 |
+
<li>Step 2: Select the summary rate and playback speed (select with slider)</li>
|
63 |
+
<li>Step 3: Generate a summarized video (press the Summarize button)</li>
|
64 |
+
</ul>
|
65 |
+
''')
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
with gr.Row():
|
67 |
+
gr.Markdown('''
|
68 |
+
#### Output
|
69 |
+
<ul>
|
70 |
+
<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>
|
71 |
+
<li>A text summary of the video is displayed below it.</li>
|
72 |
+
<li>A transcription of the original video is displayed further down (the part extracted from the summarized video is highlighted).</li>
|
73 |
+
</ul>
|
74 |
+
''')
|
75 |
+
with gr.Row():
|
76 |
+
gr.Markdown('''
|
77 |
+
### User ID
|
78 |
+
Fill in the user ID if the author of this system has instructed you to do so.
|
79 |
+
''')
|
80 |
+
with gr.Column():
|
81 |
+
user_id_input = gr.Textbox(placeholder="Enter your user ID", label="User ID")
|
82 |
+
store_local_id_wrapped = partial(store_local_id, local_id=local_id, db=db)
|
83 |
+
user_id_btn = gr.Button("Submit User ID")
|
84 |
+
user_id_btn.click(store_local_id_wrapped, inputs=[user_id_input])
|
85 |
with gr.Row():
|
86 |
gr.Markdown('''
|
87 |
### You can test by following examples:
|
|
|
94 |
with gr.Column():
|
95 |
youtube_url_in.render()
|
96 |
download_youtube_btn = gr.Button("Download Youtube video")
|
97 |
+
get_youtube_wrapped = partial(get_youtube, local_id=local_id, db=db)
|
98 |
download_youtube_btn.click(get_youtube_wrapped, [youtube_url_in], [video_in])
|
|
|
99 |
with gr.Row():
|
100 |
sum_ratio = gr.Slider(label="Summarize Ratio", minimum=0.3, maximum=0.8, step=0.05, value=0.6)
|
101 |
playback_speed = gr.Slider(label="Playback Speed", minimum=0.5, maximum=2.0, step=0.25, value=1.0)
|
102 |
with gr.Row():
|
103 |
upload_output_video_btn = gr.Button("Summarize Video")
|
104 |
+
summarize_video_wrapped = partial(summarize_video, local_id=local_id, db=db)
|
105 |
upload_output_video_btn.click(summarize_video_wrapped, [video_in, sum_ratio, playback_speed], [video_out, summary_text, transcription_text])
|
106 |
with gr.Row():
|
107 |
video_in.render()
|
|
|
111 |
with gr.Row():
|
112 |
transcription_text.render()
|
113 |
|
114 |
+
# demo.launch(debug=True, share=True)
|
115 |
demo.launch(debug=True)
|
model.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import copy
|
2 |
import subprocess
|
3 |
|
4 |
import numpy as np
|
@@ -29,15 +28,19 @@ next_sentence_predict = BertForNextSentencePrediction.from_pretrained("bert-base
|
|
29 |
# 文章の要約モデル
|
30 |
summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
|
31 |
|
32 |
-
def log_firestore(db,
|
33 |
-
|
34 |
-
|
35 |
-
"
|
36 |
-
"
|
37 |
-
"
|
38 |
-
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
def summarize_video(video_path, sim_thr, playback_speed,
|
41 |
"""
|
42 |
動画要約
|
43 |
|
@@ -213,5 +216,5 @@ def summarize_video(video_path, sim_thr, playback_speed, user_id, db):
|
|
213 |
final_video.write_videofile(output_path)
|
214 |
print(output_path)
|
215 |
print("Success summarize video")
|
216 |
-
log_firestore(db,
|
217 |
return output_path, summary_text, full_textt
|
|
|
|
|
1 |
import subprocess
|
2 |
|
3 |
import numpy as np
|
|
|
28 |
# 文章の要約モデル
|
29 |
summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
|
30 |
|
31 |
+
def log_firestore(db, local_id="000000", action="test", sim_thr="", playback_speed=""):
|
32 |
+
data = {
|
33 |
+
"local_id": local_id,
|
34 |
+
"timestamp": firestore.SERVER_TIMESTAMP,
|
35 |
+
"action": action,
|
36 |
+
"sim_thr": sim_thr,
|
37 |
+
"playback_speed": playback_speed
|
38 |
+
}
|
39 |
+
doc_ref = db.collection("exp.1").document()
|
40 |
+
doc_ref.set(data)
|
41 |
+
print(f"Download Video: {doc_ref.id}")
|
42 |
|
43 |
+
def summarize_video(video_path, sim_thr, playback_speed, local_id, db):
|
44 |
"""
|
45 |
動画要約
|
46 |
|
|
|
216 |
final_video.write_videofile(output_path)
|
217 |
print(output_path)
|
218 |
print("Success summarize video")
|
219 |
+
log_firestore(db, local_id=str(local_id), action='SV', sim_thr=str(sim_thr), playback_speed=str(playback_speed))
|
220 |
return output_path, summary_text, full_textt
|
utils.py
CHANGED
@@ -3,17 +3,19 @@ from scipy.signal import resample
|
|
3 |
from firebase_admin import firestore
|
4 |
|
5 |
|
6 |
-
def log_firestore(db,
|
7 |
-
|
8 |
-
|
9 |
-
"
|
10 |
-
"
|
11 |
-
"
|
12 |
-
}
|
|
|
|
|
13 |
|
14 |
-
def get_youtube(video_url,
|
15 |
# YouTubeの動画をダウンロード
|
16 |
-
log_firestore(db,
|
17 |
print("Start download video")
|
18 |
yt = YouTube(video_url)
|
19 |
abs_video_path = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download(filename='download.mp4', output_path='movies/')
|
|
|
3 |
from firebase_admin import firestore
|
4 |
|
5 |
|
6 |
+
def log_firestore(db, local_id="000000", action="test", url=""):
|
7 |
+
data = {
|
8 |
+
"local_id": local_id,
|
9 |
+
"timestamp": firestore.SERVER_TIMESTAMP,
|
10 |
+
"action": action,
|
11 |
+
"url": url
|
12 |
+
}
|
13 |
+
doc_ref = db.collection("exp.1").document()
|
14 |
+
doc_ref.set(data)
|
15 |
|
16 |
+
def get_youtube(video_url, local_id, db):
|
17 |
# YouTubeの動画をダウンロード
|
18 |
+
log_firestore(db, local_id=str(local_id), action='DV', url=str(video_url))
|
19 |
print("Start download video")
|
20 |
yt = YouTube(video_url)
|
21 |
abs_video_path = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download(filename='download.mp4', output_path='movies/')
|