Spaces:
Running
Running
Commit
Β·
6cc88fe
1
Parent(s):
975e507
Mounted as Fastapi app: Added multipage support
Browse files- .gitignore +6 -6
- auth_functions.py β Pages/Functions/auth_functions.py +4 -3
- caption_editor_functions.py β Pages/Functions/caption_editor_functions.py +5 -4
- Pages/Functions/db_connection.py +11 -0
- video_player_functions.py β Pages/Functions/video_player_functions.py +3 -2
- {Resources β Pages/Resources}/captions.jsonl +2 -2
- {Resources β Pages/Resources}/css.py +0 -0
- Pages/main_page.py +58 -0
- Pages/registration_page.py +11 -0
- app.py +18 -67
.gitignore
CHANGED
|
@@ -83,11 +83,11 @@ http-client.private.env.json
|
|
| 83 |
.idea/ApifoxUploaderProjectSetting.xml
|
| 84 |
|
| 85 |
# Manually added
|
| 86 |
-
Resources/key.json
|
| 87 |
-
Resources/salt.py
|
| 88 |
-
Resources/upload.py
|
| 89 |
-
Resources/users.json
|
| 90 |
-
Resources/videos.json
|
| 91 |
-
Resources/captions_backup.jsonl
|
| 92 |
venv
|
| 93 |
**/__pycache__
|
|
|
|
| 83 |
.idea/ApifoxUploaderProjectSetting.xml
|
| 84 |
|
| 85 |
# Manually added
|
| 86 |
+
Pages/Resources/key.json
|
| 87 |
+
Pages/Resources/salt.py
|
| 88 |
+
Pages/Resources/upload.py
|
| 89 |
+
Pages/Resources/users.json
|
| 90 |
+
Pages/Resources/videos.json
|
| 91 |
+
Pages/Resources/captions_backup.jsonl
|
| 92 |
venv
|
| 93 |
**/__pycache__
|
auth_functions.py β Pages/Functions/auth_functions.py
RENAMED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
-
from Resources.salt import salt
|
| 2 |
import hashlib
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
def encrypt(password):
|
|
@@ -7,8 +8,8 @@ def encrypt(password):
|
|
| 7 |
return result.hex()
|
| 8 |
|
| 9 |
|
| 10 |
-
def auth_function(username, password
|
| 11 |
-
user_password =
|
| 12 |
if user_password is None:
|
| 13 |
return False
|
| 14 |
pass_input = encrypt(password)
|
|
|
|
| 1 |
+
from ..Resources.salt import salt
|
| 2 |
import hashlib
|
| 3 |
+
from db_connection import users_ref
|
| 4 |
|
| 5 |
|
| 6 |
def encrypt(password):
|
|
|
|
| 8 |
return result.hex()
|
| 9 |
|
| 10 |
|
| 11 |
+
def auth_function(username, password):
|
| 12 |
+
user_password = users_ref.child(username).get()
|
| 13 |
if user_password is None:
|
| 14 |
return False
|
| 15 |
pass_input = encrypt(password)
|
caption_editor_functions.py β Pages/Functions/caption_editor_functions.py
RENAMED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
import json
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def get_captions_by_video_id(video_id):
|
| 6 |
-
with open(
|
| 7 |
captions = pd.read_json(file, lines=True)
|
| 8 |
|
| 9 |
captions_edit = captions[captions['file'] == video_id]
|
|
@@ -16,9 +18,8 @@ def save_dataframe(df, video_id, user):
|
|
| 16 |
cols = ["clean_text", "start_time", "user_id", "signer", "file", "end_time", "url", "text"]
|
| 17 |
other_captions_data = []
|
| 18 |
new_captions_data = []
|
| 19 |
-
file_name = "Resources/captions.jsonl"
|
| 20 |
|
| 21 |
-
with open(
|
| 22 |
for line in f:
|
| 23 |
caption = json.loads(line)
|
| 24 |
if caption['file'] == video_id:
|
|
@@ -36,7 +37,7 @@ def save_dataframe(df, video_id, user):
|
|
| 36 |
|
| 37 |
all_captions = pd.concat([other_captions, new_captions], ignore_index=True)
|
| 38 |
|
| 39 |
-
all_captions.to_json(
|
| 40 |
return "Save successful!"
|
| 41 |
except ValueError:
|
| 42 |
return "Save failed: Incorrect input format"
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import json
|
| 3 |
|
| 4 |
+
FILE_PATH = "../Resources/captions.jsonl"
|
| 5 |
+
|
| 6 |
|
| 7 |
def get_captions_by_video_id(video_id):
|
| 8 |
+
with open(FILE_PATH) as file:
|
| 9 |
captions = pd.read_json(file, lines=True)
|
| 10 |
|
| 11 |
captions_edit = captions[captions['file'] == video_id]
|
|
|
|
| 18 |
cols = ["clean_text", "start_time", "user_id", "signer", "file", "end_time", "url", "text"]
|
| 19 |
other_captions_data = []
|
| 20 |
new_captions_data = []
|
|
|
|
| 21 |
|
| 22 |
+
with open(FILE_PATH) as f:
|
| 23 |
for line in f:
|
| 24 |
caption = json.loads(line)
|
| 25 |
if caption['file'] == video_id:
|
|
|
|
| 37 |
|
| 38 |
all_captions = pd.concat([other_captions, new_captions], ignore_index=True)
|
| 39 |
|
| 40 |
+
all_captions.to_json(FILE_PATH, orient='records', lines=True)
|
| 41 |
return "Save successful!"
|
| 42 |
except ValueError:
|
| 43 |
return "Save failed: Incorrect input format"
|
Pages/Functions/db_connection.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import firebase_admin
|
| 2 |
+
from firebase_admin import db
|
| 3 |
+
|
| 4 |
+
KEY_PATH = '../Resources/key.json'
|
| 5 |
+
|
| 6 |
+
cred_obj = firebase_admin.credentials.Certificate(KEY_PATH)
|
| 7 |
+
default_app = firebase_admin.initialize_app(cred_obj, {
|
| 8 |
+
'databaseURL': "https://video-link-db-default-rtdb.europe-west1.firebasedatabase.app/"
|
| 9 |
+
})
|
| 10 |
+
videos_ref = db.reference("/Videos")
|
| 11 |
+
users_ref = db.reference("/Users")
|
video_player_functions.py β Pages/Functions/video_player_functions.py
RENAMED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import re
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
def youtube_link_to_id(link):
|
|
@@ -15,6 +16,6 @@ def get_video_embed_by_id(video_id):
|
|
| 15 |
</div>"""
|
| 16 |
|
| 17 |
|
| 18 |
-
def get_video_link_by_pointer(pointer
|
| 19 |
-
video_link =
|
| 20 |
return video_link
|
|
|
|
| 1 |
import re
|
| 2 |
+
from db_connection import videos_ref
|
| 3 |
|
| 4 |
|
| 5 |
def youtube_link_to_id(link):
|
|
|
|
| 16 |
</div>"""
|
| 17 |
|
| 18 |
|
| 19 |
+
def get_video_link_by_pointer(pointer):
|
| 20 |
+
video_link = videos_ref.child(str(pointer)).get()
|
| 21 |
return video_link
|
{Resources β Pages/Resources}/captions.jsonl
RENAMED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
{"clean_text":"one","start_time":1.5,"user_id":"a","signer":40,"file":"Y4stD_ypaAI","end_time":1.6,"url":"www.youtube.com\/watch?v=Y4stD_ypaAI","text":"one"}
|
| 2 |
-
{"clean_text":"measure","start_time":0.0,"user_id":"admin","signer":20,"file":"tkMg8g8vVUo","end_time":1.435,"url":"www.youtube.com\/watch?v=tkMg8g8vVUo","text":"measure"}
|
| 3 |
-
{"clean_text":"apple","start_time":1.7,"user_id":"admin","signer":20,"file":"tkMg8g8vVUo","end_time":2.0,"url":"www.youtube.com\/watch?v=tkMg8g8vVUo","text":"apple"}
|
| 4 |
{"clean_text":"test","start_time":0.0,"user_id":"admin","signer":39,"file":"1pXUgdCnVec","end_time":1.435,"url":"www.youtube.com\/watch?v=1pXUgdCnVec","text":"test"}
|
| 5 |
{"clean_text":"test","start_time":1.5,"user_id":"admin","signer":39,"file":"1pXUgdCnVec","end_time":1.6,"url":"www.youtube.com\/watch?v=1pXUgdCnVec","text":"test 2"}
|
| 6 |
{"clean_text":"test","start_time":0.0,"user_id":"admin","signer":39,"file":"1pXUgdCnVec","end_time":1.435,"url":"www.youtube.com\/watch?v=1pXUgdCnVec","text":"test"}
|
|
@@ -13,3 +11,5 @@
|
|
| 13 |
{"clean_text":"test","start_time":0.0,"user_id":"admin","signer":39,"file":"1pXUgdCnVec","end_time":1.435,"url":"www.youtube.com\/watch?v=1pXUgdCnVec","text":"test"}
|
| 14 |
{"clean_text":"test","start_time":0.0,"user_id":"admin","signer":39,"file":"1pXUgdCnVec","end_time":1.435,"url":"www.youtube.com\/watch?v=1pXUgdCnVec","text":"test"}
|
| 15 |
{"clean_text":"test","start_time":0.0,"user_id":"admin","signer":39,"file":"1pXUgdCnVec","end_time":1.435,"url":"www.youtube.com\/watch?v=1pXUgdCnVec","text":"test"}
|
|
|
|
|
|
|
|
|
| 1 |
{"clean_text":"one","start_time":1.5,"user_id":"a","signer":40,"file":"Y4stD_ypaAI","end_time":1.6,"url":"www.youtube.com\/watch?v=Y4stD_ypaAI","text":"one"}
|
|
|
|
|
|
|
| 2 |
{"clean_text":"test","start_time":0.0,"user_id":"admin","signer":39,"file":"1pXUgdCnVec","end_time":1.435,"url":"www.youtube.com\/watch?v=1pXUgdCnVec","text":"test"}
|
| 3 |
{"clean_text":"test","start_time":1.5,"user_id":"admin","signer":39,"file":"1pXUgdCnVec","end_time":1.6,"url":"www.youtube.com\/watch?v=1pXUgdCnVec","text":"test 2"}
|
| 4 |
{"clean_text":"test","start_time":0.0,"user_id":"admin","signer":39,"file":"1pXUgdCnVec","end_time":1.435,"url":"www.youtube.com\/watch?v=1pXUgdCnVec","text":"test"}
|
|
|
|
| 11 |
{"clean_text":"test","start_time":0.0,"user_id":"admin","signer":39,"file":"1pXUgdCnVec","end_time":1.435,"url":"www.youtube.com\/watch?v=1pXUgdCnVec","text":"test"}
|
| 12 |
{"clean_text":"test","start_time":0.0,"user_id":"admin","signer":39,"file":"1pXUgdCnVec","end_time":1.435,"url":"www.youtube.com\/watch?v=1pXUgdCnVec","text":"test"}
|
| 13 |
{"clean_text":"test","start_time":0.0,"user_id":"admin","signer":39,"file":"1pXUgdCnVec","end_time":1.435,"url":"www.youtube.com\/watch?v=1pXUgdCnVec","text":"test"}
|
| 14 |
+
{"clean_text":"measure","start_time":0.0,"user_id":"admin","signer":20,"file":"tkMg8g8vVUo","end_time":1.435,"url":"www.youtube.com\/watch?v=tkMg8g8vVUo","text":"measure"}
|
| 15 |
+
{"clean_text":"apple","start_time":1.71,"user_id":"admin","signer":20,"file":"tkMg8g8vVUo","end_time":2.0,"url":"www.youtube.com\/watch?v=tkMg8g8vVUo","text":"apple"}
|
{Resources β Pages/Resources}/css.py
RENAMED
|
File without changes
|
Pages/main_page.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from Functions.video_player_functions import youtube_link_to_id, get_video_embed_by_id, get_video_link_by_pointer
|
| 3 |
+
from Functions.caption_editor_functions import get_captions_by_video_id, save_dataframe
|
| 4 |
+
from Resources.css import css
|
| 5 |
+
|
| 6 |
+
next_video_pointer = 0
|
| 7 |
+
user = ""
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def get_username(request: gr.Request):
|
| 11 |
+
global user
|
| 12 |
+
user = request.username
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def save(df, video_id):
|
| 16 |
+
return save_dataframe(df, video_id, user)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def get_next_components():
|
| 20 |
+
global next_video_pointer
|
| 21 |
+
next_video_link = get_video_link_by_pointer(next_video_pointer)
|
| 22 |
+
next_video_pointer += 1
|
| 23 |
+
if next_video_link is None:
|
| 24 |
+
next_video_link = get_video_link_by_pointer(0)
|
| 25 |
+
next_video_pointer = 1
|
| 26 |
+
|
| 27 |
+
next_video_id = youtube_link_to_id(next_video_link)
|
| 28 |
+
|
| 29 |
+
next_video = get_video_embed_by_id(next_video_id)
|
| 30 |
+
next_captions = get_captions_by_video_id(next_video_id)
|
| 31 |
+
|
| 32 |
+
return next_video, next_captions, next_video_id
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
(start_video, start_captions, start_video_id) = get_next_components()
|
| 36 |
+
|
| 37 |
+
with gr.Blocks(css=css) as main_page:
|
| 38 |
+
gr.Markdown("## Caption Editor")
|
| 39 |
+
current_video_id = gr.Textbox(value=start_video_id, visible=False, interactive=False)
|
| 40 |
+
with gr.Row():
|
| 41 |
+
with gr.Column():
|
| 42 |
+
caption_editor = gr.DataFrame(interactive=True,
|
| 43 |
+
value=start_captions,
|
| 44 |
+
datatype=["number", "str", "number"],
|
| 45 |
+
row_count=(start_captions.shape[0], "fixed"),
|
| 46 |
+
col_count=(3, "fixed"), column_widths=["20%", "60%", "20%"])
|
| 47 |
+
save_button = gr.Button(value="Save")
|
| 48 |
+
save_result = gr.Markdown()
|
| 49 |
+
with gr.Column():
|
| 50 |
+
video_embed = gr.HTML(value=start_video)
|
| 51 |
+
next_video_button = gr.Button("Next")
|
| 52 |
+
|
| 53 |
+
next_video_button.click(fn=get_next_components,
|
| 54 |
+
outputs=[video_embed, caption_editor, current_video_id])
|
| 55 |
+
save_button.click(fn=save,
|
| 56 |
+
inputs=[caption_editor, current_video_id],
|
| 57 |
+
outputs=save_result)
|
| 58 |
+
main_page.load(get_username)
|
Pages/registration_page.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
with gr.Blocks() as registration:
|
| 4 |
+
with gr.Column(variant="panel"):
|
| 5 |
+
gr.Markdown(value="# Create Account")
|
| 6 |
+
username = gr.Textbox(label="Username", show_label=True, lines=1)
|
| 7 |
+
password = gr.Textbox(label="Password", show_label=True, lines=1, type="password")
|
| 8 |
+
registration_button = gr.Button(value="Register")
|
| 9 |
+
registration_result = gr.Markdown()
|
| 10 |
+
|
| 11 |
+
# registration_button.click(fn=func, inputs=[username, password], outputs=registration_result)
|
app.py
CHANGED
|
@@ -1,74 +1,25 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
from
|
| 4 |
-
from
|
| 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 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
})
|
| 13 |
-
videos_ref = db.reference("/Videos")
|
| 14 |
-
users_ref = db.reference("/Users")
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 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)
|
| 36 |
-
next_video_pointer += 1
|
| 37 |
-
if next_video_link is None:
|
| 38 |
-
next_video_link = get_video_link_by_pointer(0, db_ref=videos_ref)
|
| 39 |
-
next_video_pointer = 1
|
| 40 |
-
|
| 41 |
-
next_video_id = youtube_link_to_id(next_video_link)
|
| 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,
|
| 57 |
-
value=start_captions,
|
| 58 |
-
datatype=["number", "str", "number"],
|
| 59 |
-
row_count=(start_captions.shape[0], "fixed"),
|
| 60 |
-
col_count=(3, "fixed"), column_widths=["20%", "60%", "20%"])
|
| 61 |
-
save_button = gr.Button(value="Save")
|
| 62 |
-
save_result = gr.Markdown()
|
| 63 |
-
with gr.Column():
|
| 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)
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fastapi.responses import HTMLResponse
|
| 3 |
import gradio as gr
|
| 4 |
+
from Pages.main_page import main_page
|
| 5 |
+
from Pages.Functions.auth_functions import auth_function
|
| 6 |
+
from Pages.registration_page import registration
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
app = FastAPI()
|
| 9 |
+
MAIN_PATH = "/caption_editor"
|
| 10 |
+
REGISTRATION_PATH = "/registration"
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
index_html = f'''
|
| 13 |
+
<div>
|
| 14 |
+
<iframe src={MAIN_PATH} width=100% height=100% frameBorder="0"></iframe>
|
| 15 |
+
</div>
|
| 16 |
+
'''
|
| 17 |
|
| 18 |
|
| 19 |
+
@app.get("/", response_class=HTMLResponse)
|
| 20 |
+
def index():
|
| 21 |
+
return index_html
|
| 22 |
|
| 23 |
|
| 24 |
+
app = gr.mount_gradio_app(app, main_page, path=MAIN_PATH, auth=auth_function)
|
| 25 |
+
app = gr.mount_gradio_app(app, registration, path=REGISTRATION_PATH)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|