Spaces:
Running
Running
Commit
·
3f23678
1
Parent(s):
dab57e4
Fixed save
Browse files- Resources/captions.jsonl +5 -5
- Resources/captions2.jsonl +0 -5
- Resources/captions_backup.jsonl +5 -0
- app.py +21 -5
- caption_editor_functions.py +25 -10
Resources/captions.jsonl
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
{"clean_text":
|
| 2 |
-
{"clean_text":
|
| 3 |
-
{"clean_text":
|
| 4 |
-
{"clean_text":
|
| 5 |
-
{"clean_text":
|
|
|
|
| 1 |
+
{"clean_text":"measure","start_time":0.0,"user_id":"a","signer":39,"file":"Aj9SDSAOXf4","end_time":1.435,"url":"www.youtube.com\/watch?v=Aj9SDSAOXf4","text":"measure"}
|
| 2 |
+
{"clean_text":"apple","start_time":1.5,"user_id":"a","signer":39,"file":"Aj9SDSAOXf4","end_time":1.6,"url":"www.youtube.com\/watch?v=Aj9SDSAOXf4","text":"apple"}
|
| 3 |
+
{"clean_text":"test","start_time":0.0,"user_id":"sample_user","signer":39,"file":"c2ORbHSQ5pw","end_time":1.435,"url":"www.youtube.com\/watch?v=c2ORbHSQ5pw","text":"test"}
|
| 4 |
+
{"clean_text":"aaaaaaaaaa","start_time":1.5,"user_id":"sample_user","signer":39,"file":"c2ORbHSQ5pw","end_time":1.6,"url":"www.youtube.com\/watch?v=c2ORbHSQ5pw","text":"aaaaaaaaaa"}
|
| 5 |
+
{"clean_text":"bbbbbbbb","start_time":1.5,"user_id":"sample_user","signer":39,"file":"c2ORbHSQ5pw","end_time":1.6,"url":"www.youtube.com\/watch?v=c2ORbHSQ5pw","text":"lllllllll"}
|
Resources/captions2.jsonl
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 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/captions_backup.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": "measure"}
|
| 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": "apple"}
|
| 3 |
+
{"clean_text": "test", "start_time": 0.0, "user_id": 11, "signer": 39, "file": "c2ORbHSQ5pw", "end_time": 1.435, "url": "www.youtube.com/watch?v=c2ORbHSQ5pw", "text": "test"}
|
| 4 |
+
{"clean_text": "aaaaaaaaaa", "start_time": 1.5, "user_id": 11, "signer": 39, "file": "c2ORbHSQ5pw", "end_time": 1.6, "url": "www.youtube.com/watch?v=c2ORbHSQ5pw", "text": "aaaaaaaaaa"}
|
| 5 |
+
{"clean_text": "bbbbbbbb", "start_time": 1.5, "user_id": 11, "signer": 39, "file": "c2ORbHSQ5pw", "end_time": 1.6, "url": "www.youtube.com/watch?v=c2ORbHSQ5pw", "text": "bbbbbbbb"}
|
app.py
CHANGED
|
@@ -3,7 +3,7 @@ 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_video_embed_by_id, get_video_link_by_pointer
|
| 6 |
-
from caption_editor_functions import get_captions_by_video_id,
|
| 7 |
from Resources.css import css
|
| 8 |
|
| 9 |
cred_obj = firebase_admin.credentials.Certificate('Resources/key.json')
|
|
@@ -14,12 +14,22 @@ videos_ref = db.reference("/Videos")
|
|
| 14 |
users_ref = db.reference("/Users")
|
| 15 |
|
| 16 |
next_video_pointer = 0
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
def auth(username, password):
|
| 20 |
return auth_function(username, password, db_ref=users_ref)
|
| 21 |
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def get_next_components():
|
| 24 |
global next_video_pointer
|
| 25 |
next_video_link = get_video_link_by_pointer(next_video_pointer, db_ref=videos_ref)
|
|
@@ -32,13 +42,15 @@ def get_next_components():
|
|
| 32 |
|
| 33 |
next_video = get_video_embed_by_id(next_video_id)
|
| 34 |
next_captions = get_captions_by_video_id(next_video_id)
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
-
(start_video, start_captions) = get_next_components()
|
| 39 |
|
| 40 |
with gr.Blocks(css=css) as app:
|
| 41 |
gr.Markdown("## Caption Editor")
|
|
|
|
| 42 |
with gr.Row():
|
| 43 |
with gr.Column():
|
| 44 |
caption_editor = gr.DataFrame(interactive=True,
|
|
@@ -52,7 +64,11 @@ with gr.Blocks(css=css) as app:
|
|
| 52 |
video_embed = gr.HTML(value=start_video)
|
| 53 |
next_video_button = gr.Button("Next")
|
| 54 |
|
| 55 |
-
next_video_button.click(fn=get_next_components,
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
app.launch(auth=auth)
|
|
|
|
| 3 |
from firebase_admin import db
|
| 4 |
from auth_functions import auth_function
|
| 5 |
from video_player_functions import youtube_link_to_id, get_video_embed_by_id, get_video_link_by_pointer
|
| 6 |
+
from caption_editor_functions import get_captions_by_video_id, save_dataframe
|
| 7 |
from Resources.css import css
|
| 8 |
|
| 9 |
cred_obj = firebase_admin.credentials.Certificate('Resources/key.json')
|
|
|
|
| 14 |
users_ref = db.reference("/Users")
|
| 15 |
|
| 16 |
next_video_pointer = 0
|
| 17 |
+
user = ""
|
| 18 |
|
| 19 |
|
| 20 |
def auth(username, password):
|
| 21 |
return auth_function(username, password, db_ref=users_ref)
|
| 22 |
|
| 23 |
|
| 24 |
+
def get_username(request: gr.Request):
|
| 25 |
+
global user
|
| 26 |
+
user = request.username
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def save(df, video_id):
|
| 30 |
+
return save_dataframe(df, video_id, user)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
def get_next_components():
|
| 34 |
global next_video_pointer
|
| 35 |
next_video_link = get_video_link_by_pointer(next_video_pointer, db_ref=videos_ref)
|
|
|
|
| 42 |
|
| 43 |
next_video = get_video_embed_by_id(next_video_id)
|
| 44 |
next_captions = get_captions_by_video_id(next_video_id)
|
| 45 |
+
|
| 46 |
+
return next_video, next_captions, next_video_id
|
| 47 |
|
| 48 |
|
| 49 |
+
(start_video, start_captions, start_video_id) = get_next_components()
|
| 50 |
|
| 51 |
with gr.Blocks(css=css) as app:
|
| 52 |
gr.Markdown("## Caption Editor")
|
| 53 |
+
current_video_id = gr.Textbox(value=start_video_id, visible=False, interactive=False)
|
| 54 |
with gr.Row():
|
| 55 |
with gr.Column():
|
| 56 |
caption_editor = gr.DataFrame(interactive=True,
|
|
|
|
| 64 |
video_embed = gr.HTML(value=start_video)
|
| 65 |
next_video_button = gr.Button("Next")
|
| 66 |
|
| 67 |
+
next_video_button.click(fn=get_next_components,
|
| 68 |
+
outputs=[video_embed, caption_editor, current_video_id])
|
| 69 |
+
save_button.click(fn=save,
|
| 70 |
+
inputs=[caption_editor, current_video_id],
|
| 71 |
+
outputs=save_result)
|
| 72 |
+
app.load(get_username)
|
| 73 |
|
| 74 |
app.launch(auth=auth)
|
caption_editor_functions.py
CHANGED
|
@@ -1,24 +1,39 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
-
|
| 3 |
-
with open("Resources/captions.jsonl") as file:
|
| 4 |
-
captions = pd.read_json(file, lines=True)
|
| 5 |
|
| 6 |
|
| 7 |
def get_captions_by_video_id(video_id):
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
captions_edit = captions[captions['file'] == video_id]
|
| 10 |
captions_edit = captions_edit[['start_time', 'text', 'end_time']]
|
| 11 |
captions_edit.columns = ["Start", "Text", "End"]
|
| 12 |
return captions_edit
|
| 13 |
|
| 14 |
|
| 15 |
-
def
|
| 16 |
try:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
captions['
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
return "Save successful!"
|
| 23 |
except ValueError:
|
| 24 |
return "Save failed: Incorrect input format"
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
+
import numpy as np
|
|
|
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
def get_captions_by_video_id(video_id):
|
| 6 |
+
with open("Resources/captions.jsonl") as file:
|
| 7 |
+
captions = pd.read_json(file, lines=True)
|
| 8 |
+
|
| 9 |
captions_edit = captions[captions['file'] == video_id]
|
| 10 |
captions_edit = captions_edit[['start_time', 'text', 'end_time']]
|
| 11 |
captions_edit.columns = ["Start", "Text", "End"]
|
| 12 |
return captions_edit
|
| 13 |
|
| 14 |
|
| 15 |
+
def save_dataframe(df, video_id, user):
|
| 16 |
try:
|
| 17 |
+
with open("Resources/captions.jsonl") as file:
|
| 18 |
+
captions = pd.read_json(file, lines=True)
|
| 19 |
+
|
| 20 |
+
other_captions = captions[captions['file'] != video_id].copy()
|
| 21 |
+
new_captions = captions[captions['file'] == video_id].copy()
|
| 22 |
+
|
| 23 |
+
new_captions['start_time'] = np.where(df['Start'].isnull(),
|
| 24 |
+
new_captions['start_time'],
|
| 25 |
+
df['Start'].apply(lambda x: float(x)))
|
| 26 |
+
new_captions['text'] = np.where(df['Text'].isnull(),
|
| 27 |
+
new_captions['text'],
|
| 28 |
+
df['Text'])
|
| 29 |
+
new_captions['end_time'] = np.where(df['End'].isnull(),
|
| 30 |
+
new_captions['end_time'],
|
| 31 |
+
df['End'].apply(lambda x: float(x)))
|
| 32 |
+
new_captions['user_id'] = user
|
| 33 |
+
|
| 34 |
+
all_captions = pd.concat([other_captions, new_captions], ignore_index=True)
|
| 35 |
+
|
| 36 |
+
all_captions.to_json('Resources/captions.jsonl', orient='records', lines=True)
|
| 37 |
return "Save successful!"
|
| 38 |
except ValueError:
|
| 39 |
return "Save failed: Incorrect input format"
|