Spaces:
Sleeping
Sleeping
Commit
Β·
4fb50a9
1
Parent(s):
f7d2a44
Login + File organization
Browse files- .gitignore +3 -1
- .idea/vcs.xml +1 -1
- captions.jsonl β Resources/captions.jsonl +0 -0
- Resources/captions2.jsonl +5 -0
- Resources/css.py +14 -0
- db_upload.py β Resources/db_upload.py +7 -3
- Resources/users.json +3 -0
- videos.json β Resources/videos.json +0 -0
- main.py β app.py +10 -63
- auth_functions.py +17 -0
- caption_editor_functions.py +25 -0
- captions2.jsonl +0 -2
- video_player_functions.py +15 -0
.gitignore
CHANGED
|
@@ -83,5 +83,7 @@ http-client.private.env.json
|
|
| 83 |
.idea/ApifoxUploaderProjectSetting.xml
|
| 84 |
|
| 85 |
# Project specific
|
| 86 |
-
key.json
|
|
|
|
| 87 |
venv
|
|
|
|
|
|
| 83 |
.idea/ApifoxUploaderProjectSetting.xml
|
| 84 |
|
| 85 |
# Project specific
|
| 86 |
+
Resources/key.json
|
| 87 |
+
Resources/salt.py
|
| 88 |
venv
|
| 89 |
+
**/__pycache__
|
.idea/vcs.xml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
<project version="4">
|
| 3 |
<component name="VcsDirectoryMappings">
|
| 4 |
-
<mapping directory="$PROJECT_DIR$" vcs="" />
|
| 5 |
</component>
|
| 6 |
</project>
|
|
|
|
| 1 |
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
<project version="4">
|
| 3 |
<component name="VcsDirectoryMappings">
|
| 4 |
+
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
| 5 |
</component>
|
| 6 |
</project>
|
captions.jsonl β Resources/captions.jsonl
RENAMED
|
File without changes
|
Resources/captions2.jsonl
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"clean_text":"measure","start_time":0.0,"user_id":11,"signer":39,"file":"Aj9SDSAOXf4","end_time":1.435,"url":"www.youtube.com\/watch?v=Aj9SDSAOXf4","text":"test"}
|
| 2 |
+
{"clean_text":"apple","start_time":1.5,"user_id":11,"signer":39,"file":"Aj9SDSAOXf4","end_time":1.6,"url":"www.youtube.com\/watch?v=Aj9SDSAOXf4","text":"hhhh"}
|
| 3 |
+
{"clean_text":"test","start_time":null,"user_id":11,"signer":39,"file":"c2ORbHSQ5pw","end_time":null,"url":"www.youtube.com\/watch?v=c2ORbHSQ5pw","text":null}
|
| 4 |
+
{"clean_text":"aaaaaaaaaa","start_time":null,"user_id":11,"signer":39,"file":"c2ORbHSQ5pw","end_time":null,"url":"www.youtube.com\/watch?v=c2ORbHSQ5pw","text":null}
|
| 5 |
+
{"clean_text":"bbbbbbbb","start_time":null,"user_id":11,"signer":39,"file":"c2ORbHSQ5pw","end_time":null,"url":"www.youtube.com\/watch?v=c2ORbHSQ5pw","text":null}
|
Resources/css.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
css = """
|
| 2 |
+
.container {
|
| 3 |
+
position: relative;
|
| 4 |
+
width: 100%;
|
| 5 |
+
height: 0;
|
| 6 |
+
padding-bottom: 56.25%;
|
| 7 |
+
}
|
| 8 |
+
.video {
|
| 9 |
+
position: absolute;
|
| 10 |
+
top: 0;
|
| 11 |
+
left: 0;
|
| 12 |
+
width: 100%;
|
| 13 |
+
height: 100%;
|
| 14 |
+
}"""
|
db_upload.py β Resources/db_upload.py
RENAMED
|
@@ -6,7 +6,11 @@ cred_obj = firebase_admin.credentials.Certificate('key.json')
|
|
| 6 |
default_app = firebase_admin.initialize_app(cred_obj, {
|
| 7 |
'databaseURL': "https://video-link-db-default-rtdb.europe-west1.firebasedatabase.app/"
|
| 8 |
})
|
| 9 |
-
videos_ref = db.reference("/Videos")
|
| 10 |
-
with open("videos.json", "r") as f:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
file_contents = json.load(f)
|
| 12 |
-
|
|
|
|
| 6 |
default_app = firebase_admin.initialize_app(cred_obj, {
|
| 7 |
'databaseURL': "https://video-link-db-default-rtdb.europe-west1.firebasedatabase.app/"
|
| 8 |
})
|
| 9 |
+
# videos_ref = db.reference("/Videos")
|
| 10 |
+
# with open("videos.json", "r") as f:
|
| 11 |
+
# file_contents = json.load(f)
|
| 12 |
+
# videos_ref.set(file_contents)
|
| 13 |
+
users_ref = db.reference("/Users")
|
| 14 |
+
with open("users.json", "r") as f:
|
| 15 |
file_contents = json.load(f)
|
| 16 |
+
users_ref.set(file_contents)
|
Resources/users.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"sample_user": "f8f81086d3347f78c14e822641b1475da6f6921d5cb032acd400468aaca20f4d"
|
| 3 |
+
}
|
videos.json β Resources/videos.json
RENAMED
|
File without changes
|
main.py β app.py
RENAMED
|
@@ -1,58 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import re
|
| 4 |
import firebase_admin
|
| 5 |
from firebase_admin import db
|
| 6 |
-
import
|
| 7 |
-
import
|
| 8 |
-
import
|
|
|
|
| 9 |
|
| 10 |
-
cred_obj = firebase_admin.credentials.Certificate('key.json')
|
| 11 |
default_app = firebase_admin.initialize_app(cred_obj, {
|
| 12 |
'databaseURL': "https://video-link-db-default-rtdb.europe-west1.firebasedatabase.app/"
|
| 13 |
})
|
| 14 |
videos_ref = db.reference("/Videos")
|
|
|
|
| 15 |
|
| 16 |
-
with open("captions.jsonl") as file:
|
| 17 |
-
captions = pd.read_json(file, lines=True)
|
| 18 |
-
|
| 19 |
-
# videos = ["Aj9SDSAOXf4", "c2ORbHSQ5pw"]
|
| 20 |
-
current_video = 0
|
| 21 |
video_links = videos_ref.get()[1:]
|
| 22 |
-
|
| 23 |
-
css = """
|
| 24 |
-
.container {
|
| 25 |
-
position: relative;
|
| 26 |
-
width: 100%;
|
| 27 |
-
height: 0;
|
| 28 |
-
padding-bottom: 56.25%;
|
| 29 |
-
}
|
| 30 |
-
.video {
|
| 31 |
-
position: absolute;
|
| 32 |
-
top: 0;
|
| 33 |
-
left: 0;
|
| 34 |
-
width: 100%;
|
| 35 |
-
height: 100%;
|
| 36 |
-
}"""
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
def auth_function(username, password):
|
| 40 |
-
return True
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
def youtube_link_to_id(link):
|
| 44 |
-
video_id = re.findall("=(.*?)&", link)
|
| 45 |
-
if len(video_id) == 0:
|
| 46 |
-
video_id = re.findall("=(.*)", link)
|
| 47 |
-
return video_id[0]
|
| 48 |
|
| 49 |
|
| 50 |
-
def
|
| 51 |
-
|
| 52 |
-
captions_edit = captions[captions['file'] == video_id]
|
| 53 |
-
captions_edit = captions_edit[['start_time', 'text', 'end_time']]
|
| 54 |
-
captions_edit.columns = ["Start", "Text", "End"]
|
| 55 |
-
return captions_edit
|
| 56 |
|
| 57 |
|
| 58 |
def get_next_captions():
|
|
@@ -62,13 +28,6 @@ def get_next_captions():
|
|
| 62 |
# return get_captions(videos[current_video])
|
| 63 |
|
| 64 |
|
| 65 |
-
def get_youtube_video(video_id):
|
| 66 |
-
return f"""
|
| 67 |
-
<div class="container">
|
| 68 |
-
<iframe src="https://www.youtube.com/embed/{video_id}" frameborder="0" allowfullscreen class="video"></iframe>
|
| 69 |
-
</div>"""
|
| 70 |
-
|
| 71 |
-
|
| 72 |
def get_next_youtube_video():
|
| 73 |
global current_video, video_links
|
| 74 |
current_video += 1
|
|
@@ -88,18 +47,6 @@ def refresh_components():
|
|
| 88 |
return next_video, next_captions
|
| 89 |
|
| 90 |
|
| 91 |
-
def save(df):
|
| 92 |
-
try:
|
| 93 |
-
global captions
|
| 94 |
-
captions['start_time'] = df['Start'].apply(lambda x: float(x))
|
| 95 |
-
captions['text'] = df['Text']
|
| 96 |
-
captions['end_time'] = df['End'].apply(lambda x: float(x))
|
| 97 |
-
captions.to_json('captions2.jsonl', orient='records', lines=True)
|
| 98 |
-
return "Save successful!"
|
| 99 |
-
except ValueError:
|
| 100 |
-
return "Save failed: Incorrect input format"
|
| 101 |
-
|
| 102 |
-
|
| 103 |
with gr.Blocks(css=css) as app:
|
| 104 |
gr.Markdown("## Caption Editor")
|
| 105 |
with gr.Row():
|
|
@@ -118,4 +65,4 @@ with gr.Blocks(css=css) as app:
|
|
| 118 |
next_video_button.click(fn=refresh_components, outputs=[video_embed, caption_editor])
|
| 119 |
save_button.click(fn=save, inputs=caption_editor, outputs=save_result)
|
| 120 |
|
| 121 |
-
app.launch(auth=
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import firebase_admin
|
| 3 |
from firebase_admin import db
|
| 4 |
+
from auth_functions import auth_function
|
| 5 |
+
from video_player_functions import youtube_link_to_id, get_youtube_video
|
| 6 |
+
from caption_editor_functions import get_captions, save, captions
|
| 7 |
+
from Resources.css import css
|
| 8 |
|
| 9 |
+
cred_obj = firebase_admin.credentials.Certificate('Resources/key.json')
|
| 10 |
default_app = firebase_admin.initialize_app(cred_obj, {
|
| 11 |
'databaseURL': "https://video-link-db-default-rtdb.europe-west1.firebasedatabase.app/"
|
| 12 |
})
|
| 13 |
videos_ref = db.reference("/Videos")
|
| 14 |
+
users_ref = db.reference("/Users")
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
video_links = videos_ref.get()[1:]
|
| 17 |
+
current_video = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
+
def auth(username, password):
|
| 21 |
+
return auth_function(username, password, users_ref)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
def get_next_captions():
|
|
|
|
| 28 |
# return get_captions(videos[current_video])
|
| 29 |
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
def get_next_youtube_video():
|
| 32 |
global current_video, video_links
|
| 33 |
current_video += 1
|
|
|
|
| 47 |
return next_video, next_captions
|
| 48 |
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
with gr.Blocks(css=css) as app:
|
| 51 |
gr.Markdown("## Caption Editor")
|
| 52 |
with gr.Row():
|
|
|
|
| 65 |
next_video_button.click(fn=refresh_components, outputs=[video_embed, caption_editor])
|
| 66 |
save_button.click(fn=save, inputs=caption_editor, outputs=save_result)
|
| 67 |
|
| 68 |
+
app.launch(auth=auth)
|
auth_functions.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from Resources.salt import salt
|
| 2 |
+
import hashlib
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def encrypt(password):
|
| 6 |
+
result = hashlib.pbkdf2_hmac('sha256', bytes(password, "utf-8"), salt, 100000)
|
| 7 |
+
return result.hex()
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def auth_function(username, password, db_ref):
|
| 11 |
+
user_password = db_ref.child(username).get()
|
| 12 |
+
if user_password is None:
|
| 13 |
+
return False
|
| 14 |
+
pass_input = encrypt(password)
|
| 15 |
+
if user_password == pass_input:
|
| 16 |
+
return True
|
| 17 |
+
return False
|
caption_editor_functions.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def get_captions(video_id):
|
| 5 |
+
global captions
|
| 6 |
+
captions_edit = captions[captions['file'] == video_id]
|
| 7 |
+
captions_edit = captions_edit[['start_time', 'text', 'end_time']]
|
| 8 |
+
captions_edit.columns = ["Start", "Text", "End"]
|
| 9 |
+
return captions_edit
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def save(df):
|
| 13 |
+
try:
|
| 14 |
+
global captions
|
| 15 |
+
captions['start_time'] = df['Start'].apply(lambda x: float(x))
|
| 16 |
+
captions['text'] = df['Text']
|
| 17 |
+
captions['end_time'] = df['End'].apply(lambda x: float(x))
|
| 18 |
+
captions.to_json('Resources/captions2.jsonl', orient='records', lines=True)
|
| 19 |
+
return "Save successful!"
|
| 20 |
+
except ValueError:
|
| 21 |
+
return "Save failed: Incorrect input format"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
with open("Resources/captions.jsonl") as file:
|
| 25 |
+
captions = pd.read_json(file, lines=True)
|
captions2.jsonl
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
{"clean_text":"measure","start_time":0.0,"user_id":11,"signer":39,"file":"a1NeXe8bhuo","end_time":1.435,"url":"www.youtube.com\/watch?v=a1NeXe8bhuo","text":"measure"}
|
| 2 |
-
{"clean_text":"apple","start_time":1.5,"user_id":11,"signer":39,"file":"a1NeXe8bhuo","end_time":1.6,"url":"www.youtube.com\/watch?v=a1NeXe8bhuo","text":"apple"}
|
|
|
|
|
|
|
|
|
video_player_functions.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def youtube_link_to_id(link):
|
| 5 |
+
video_id = re.findall("=(.*?)&", link)
|
| 6 |
+
if len(video_id) == 0:
|
| 7 |
+
video_id = re.findall("=(.*)", link)
|
| 8 |
+
return video_id[0]
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def get_youtube_video(video_id):
|
| 12 |
+
return f"""
|
| 13 |
+
<div class="container">
|
| 14 |
+
<iframe src="https://www.youtube.com/embed/{video_id}" frameborder="0" allowfullscreen class="video"></iframe>
|
| 15 |
+
</div>"""
|