Spaces:
Sleeping
Sleeping
File size: 4,872 Bytes
f32d176 7d76a49 f32d176 958c599 f32d176 958c599 1f5c279 8ad5dc2 958c599 f32d176 0614214 f32d176 6840d94 f32d176 7d76a49 958c599 8ad5dc2 958c599 7d76a49 c116608 7d76a49 958c599 b5509c2 958c599 7d76a49 4b5a22f 958c599 9504de3 958c599 7d76a49 4b5a22f 958c599 7d76a49 c116608 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
import os
import random
from functools import partial
import json
import base64
import gradio as gr
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
from utils import get_youtube
from model import summarize_video
# η°ε’ε€ζ°γγη§ε―ι΅γεεΎ
encoded_key = os.environ["FIREBASE_CREDENTIALS_BASE64"]
# Base64γ¨γ³γ³γΌγγγγη§ε―ι΅γγγ³γΌγ
decoded_key = base64.b64decode(encoded_key)
# γγ³γΌγγγγη§ε―ι΅γδ½Ώγ£γ¦CredentialγͺγγΈγ§γ―γγδ½ζ
cred = credentials.Certificate(json.loads(decoded_key))
# cred = credentials.Certificate('/home/kazuki/casp/fastperson-538e9-firebase-adminsdk-285dh-fa3faea9d0.json')
# Firebase Admin SDKγεζε
firebase_admin.initialize_app(cred)
db = firestore.client()
def log_firestore(db, local_id="000000", action="test", user_id=""):
data = {
"local_id": local_id,
"timestamp": firestore.SERVER_TIMESTAMP,
"action": action,
"user_id": user_id
}
doc_ref = db.collection("exp.1").document()
doc_ref.set(data)
local_id = random.randint(0, 10000000)
def store_local_id(user_id, local_id, db):
log_firestore(db, local_id=str(local_id), action='ID', user_id=str(user_id))
# ---- Gradio Layout -----
youtube_url_in = gr.Textbox(label="Youtube url", lines=1, interactive=True)
video_in = gr.Video(label="Input Video", mirror_webcam=False, interactive=True)
video_out = gr.Video(label="Output Video")
summary_text = gr.Textbox(label="Video Transcription Summary")
transcription_text = gr.HTML(label="Full Transcription")
demo = gr.Blocks()
demo.encrypt = False
with demo:
with gr.Column():
gr.Markdown('''
<div style="text-align: center">
<h1 style='text-align: center'>Video Summarization</h1>
</div>
''')
with gr.Row():
gr.Markdown('''
### Summarize video
<ul>
<li>Step 1. download a video from youtube (select one of the examples and press the Download button)</li>
<li>Step 2: Select the summary rate and playback speed (select with slider)</li>
<li>Step 3: Generate a summarized video (press the Summarize button)</li>
</ul>
''')
with gr.Row():
gr.Markdown('''
#### Output
<ul>
<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>
<li>A text summary of the video is displayed below it.</li>
<li>A transcription of the original video is displayed further down (the part extracted from the summarized video is highlighted).</li>
</ul>
''')
with gr.Row():
gr.Markdown('''
### User ID
Fill in the user ID if the author of this system has instructed you to do so.
''')
with gr.Column():
user_id_input = gr.Textbox(placeholder="Enter your user ID", label="User ID")
store_local_id_wrapped = partial(store_local_id, local_id=local_id, db=db)
user_id_btn = gr.Button("Submit User ID")
user_id_btn.click(store_local_id_wrapped, inputs=[user_id_input])
with gr.Row():
gr.Markdown('''
### You can test by following examples:
''')
examples = gr.Examples(examples=
[ "https://www.youtube.com/watch?v=QghjaS0WQQU",
"https://www.youtube.com/watch?v=k_04qb_65l0",
"https://www.youtube.com/watch?v=yArB4rgA1hM",
"https://www.youtube.com/watch?v=SzAuB2FG79A",
"https://www.youtube.com/watch?v=f60dheI4ARg"
],
label="Examples", inputs=[youtube_url_in])
with gr.Column():
youtube_url_in.render()
download_youtube_btn = gr.Button("Download Youtube video")
get_youtube_wrapped = partial(get_youtube, local_id=local_id, db=db)
download_youtube_btn.click(get_youtube_wrapped, [youtube_url_in], [video_in])
with gr.Row():
sum_ratio = gr.Slider(label="Summarize Ratio", minimum=0.3, maximum=0.8, step=0.05, value=0.6)
playback_speed = gr.Slider(label="Playback Speed", minimum=0.5, maximum=2.0, step=0.25, value=1.0)
with gr.Row():
upload_output_video_btn = gr.Button("Summarize Video")
summarize_video_wrapped = partial(summarize_video, local_id=local_id, db=db)
upload_output_video_btn.click(summarize_video_wrapped, [video_in, sum_ratio, playback_speed], [video_out, summary_text, transcription_text])
with gr.Row():
video_in.render()
video_out.render()
with gr.Row():
summary_text.render()
with gr.Row():
transcription_text.render()
# demo.launch(debug=True, share=True)
demo.launch(debug=True) |