File size: 1,373 Bytes
2fbb982
db4e125
2fbb982
 
 
db4e125
0661099
 
 
 
db4e125
2fbb982
db4e125
2fbb982
 
db4e125
0661099
 
 
 
 
 
2fbb982
4149ef5
db4e125
 
 
 
c0f0641
db4e125
2fbb982
 
 
 
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
import pandas as pd
from Functions.db_connection import default_app


def get_captions_by_video_id(video_id):
    response = default_app.database().child("Captions").child(video_id).get().val()
    if response is None:
        captions = pd.DataFrame(columns=["clean_text", "end_time", "signer", "start_time", "text", "user_id"])
    else:
        captions = pd.DataFrame(response)
    captions_edit = captions[['start_time', 'text', 'end_time']]
    captions_edit.columns = ["Start", "Text", "End"]
    return captions_edit, captions


def save_dataframe(df, df_full, video_id, user):
    if len(df.index) > len(df_full.index):
        new_rows = len(df_full.index) - len(df.index)
        empty_data = {col: [None for _ in range(new_rows)] for col in df_full.columns}
        empty_df = pd.DataFrame(empty_data)

        df_full = pd.concat([df_full, empty_df], ignore_index=True)
    try:
        df_full["user_id"] = user
        df_full["start_time"] = df["Start"].apply(lambda x: float(x))
        df_full["text"] = df["Text"]
        df_full["end_time"] = df["End"].apply(lambda x: float(x))

        df_json = df_full.to_dict(orient="index")
        default_app.database().child("Captions").child(video_id).set(df_json)

        return "Save successful!"
    except ValueError:
        return "Save failed: Incorrect input format"