userIdc2024 commited on
Commit
e28bea9
·
verified ·
1 Parent(s): 0ddf12f

Delete utils

Browse files
utils/.DS_Store DELETED
Binary file (6.15 kB)
 
utils/__pycache__/auth.cpython-311.pyc DELETED
Binary file (1.91 kB)
 
utils/__pycache__/dataframe.cpython-311.pyc DELETED
Binary file (5.34 kB)
 
utils/__pycache__/video.cpython-311.pyc DELETED
Binary file (1.38 kB)
 
utils/auth.py DELETED
@@ -1,33 +0,0 @@
1
- import os
2
- import logging
3
- import streamlit as st
4
-
5
- logger = logging.getLogger(__name__)
6
-
7
- def check_token(user_token: str):
8
- ACCESS_TOKEN = os.getenv("ACCESS_TOKEN")
9
- if not ACCESS_TOKEN:
10
- logger.critical("ACCESS_TOKEN not set in environment.")
11
- return False, "Server error: Access token not configured."
12
- if user_token == ACCESS_TOKEN:
13
- logger.info("Access token validated successfully.")
14
- return True, ""
15
- logger.warning("Invalid access token attempt.")
16
- return False, "Invalid token."
17
-
18
- def gated_access() -> bool:
19
- if "authenticated" not in st.session_state:
20
- st.session_state["authenticated"] = False
21
-
22
- if not st.session_state["authenticated"]:
23
- st.markdown("## Access Required")
24
- token_input = st.text_input("Enter Access Token", type="password")
25
- if st.button("Unlock App"):
26
- ok, error_msg = check_token(token_input)
27
- if ok:
28
- st.session_state["authenticated"] = True
29
- st.rerun()
30
- else:
31
- st.error(error_msg)
32
- return False
33
- return True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
utils/dataframe.py DELETED
@@ -1,59 +0,0 @@
1
- import json
2
- import pandas as pd
3
- from typing import Any, Dict, List
4
-
5
- def safe_dataframe(df: pd.DataFrame) -> pd.DataFrame:
6
- for col in df.columns:
7
- df[col] = df[col].astype(str)
8
- return df
9
-
10
- def analysis_to_csv(analysis: Dict[str, Any]) -> str:
11
- rows = []
12
- for sb in analysis.get("storyboard", []):
13
- rows.append({"Section": "Storyboard", **sb})
14
- for sc in analysis.get("script", []):
15
- rows.append({"Section": "Script", **sc})
16
- for met in analysis.get("video_analysis", {}).get("video_metrics", []):
17
- rows.append({"Section": "Metrics", **met})
18
- for imp in analysis.get("timestamp_improvements", []):
19
- rows.append({"Section": "Improvements", **imp})
20
- if not rows:
21
- return ""
22
- df = pd.DataFrame(rows)
23
- return df.to_csv(index=False)
24
-
25
- def _normalize_list(value: Any) -> List[str]:
26
- if value is None:
27
- return []
28
- if isinstance(value, list):
29
- return [str(v) for v in value]
30
- return [s for s in str(value).splitlines() if s.strip()]
31
-
32
- def _to_dataframe(items: Any, columns_map: Dict[str, str]) -> pd.DataFrame:
33
- if not isinstance(items, list) or not items:
34
- return pd.DataFrame(columns=list(columns_map.values()))
35
- df = pd.DataFrame(items)
36
- df = df.rename(columns=columns_map)
37
- ordered_cols = [columns_map[k] for k in columns_map.keys() if columns_map[k] in df.columns]
38
- df = df.reindex(columns=ordered_cols)
39
- return df
40
-
41
- def _mean_effectiveness(metrics: List[Dict[str, Any]]) -> float:
42
- if not metrics:
43
- return 0.0
44
- scores = []
45
- for m in metrics:
46
- s = str(m.get("effectiveness_score", "0/10")).split("/")[0]
47
- try:
48
- scores.append(int(s))
49
- except Exception:
50
- pass
51
- return round(sum(scores) / len(scores), 2) if scores else 0.0
52
-
53
- def _search_dataframe(df: pd.DataFrame, query: str) -> pd.DataFrame:
54
- if not query or df.empty:
55
- return df
56
- mask = pd.Series([False]*len(df))
57
- for col in df.columns:
58
- mask = mask | df[col].astype(str).str.contains(query, case=False, na=False)
59
- return df[mask]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
utils/video.py DELETED
@@ -1,19 +0,0 @@
1
- import cv2
2
- import base64
3
- import logging
4
-
5
- logger = logging.getLogger(__name__)
6
-
7
- def get_video_thumbnail_base64(video_path: str, time_sec: int = 1) -> str:
8
- try:
9
- cap = cv2.VideoCapture(video_path)
10
- cap.set(cv2.CAP_PROP_POS_MSEC, time_sec * 1000)
11
- success, frame = cap.read()
12
- cap.release()
13
- if not success:
14
- return ""
15
- _, buffer = cv2.imencode(".jpg", frame)
16
- return base64.b64encode(buffer).decode("utf-8")
17
- except Exception:
18
- logger.exception("Thumbnail extraction failed")
19
- return ""