Spaces:
Paused
Paused
Commit ·
3a43614
1
Parent(s): 2635e47
Cleanup
Browse files- Functions/caption_editor_functions.py +3 -2
- app.py +2 -3
Functions/caption_editor_functions.py
CHANGED
|
@@ -4,8 +4,9 @@ from Functions.db_connection import default_app
|
|
| 4 |
|
| 5 |
def save_captions_to_db(df, video_id, user):
|
| 6 |
try:
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
default_app.database().child("video_captions").child(video_id).child("captions").set(df_json)
|
| 10 |
default_app.database().child("video_captions").child(video_id).child("username").set(user)
|
| 11 |
return "Save successful!"
|
|
|
|
| 4 |
|
| 5 |
def save_captions_to_db(df, video_id, user):
|
| 6 |
try:
|
| 7 |
+
data = df.copy()
|
| 8 |
+
data.columns = ['start_time', 'text', 'end_time']
|
| 9 |
+
df_json = data.to_dict(orient="index")
|
| 10 |
default_app.database().child("video_captions").child(video_id).child("captions").set(df_json)
|
| 11 |
default_app.database().child("video_captions").child(video_id).child("username").set(user)
|
| 12 |
return "Save successful!"
|
app.py
CHANGED
|
@@ -47,7 +47,7 @@ def show_add_entry_form():
|
|
| 47 |
def save_entry(df, start_time, text, end_time, selected_row_idx, video_id):
|
| 48 |
"""Save or update a caption entry"""
|
| 49 |
if user == "anonymous_user":
|
| 50 |
-
return df, gr.update(visible=True), gr.Warning("Please
|
| 51 |
try:
|
| 52 |
start_time = float(start_time)
|
| 53 |
end_time = float(end_time)
|
|
@@ -77,8 +77,7 @@ def save_entry(df, start_time, text, end_time, selected_row_idx, video_id):
|
|
| 77 |
|
| 78 |
# Update in database
|
| 79 |
save_result = save_captions_to_db(df_copy, video_id, user)
|
| 80 |
-
|
| 81 |
-
|
| 82 |
return (
|
| 83 |
df_copy,
|
| 84 |
gr.update(visible=False), # Hide panel on success
|
|
|
|
| 47 |
def save_entry(df, start_time, text, end_time, selected_row_idx, video_id):
|
| 48 |
"""Save or update a caption entry"""
|
| 49 |
if user == "anonymous_user":
|
| 50 |
+
return df, gr.update(visible=True), gr.Warning("Please sign in to save changes")
|
| 51 |
try:
|
| 52 |
start_time = float(start_time)
|
| 53 |
end_time = float(end_time)
|
|
|
|
| 77 |
|
| 78 |
# Update in database
|
| 79 |
save_result = save_captions_to_db(df_copy, video_id, user)
|
| 80 |
+
|
|
|
|
| 81 |
return (
|
| 82 |
df_copy,
|
| 83 |
gr.update(visible=False), # Hide panel on success
|