Oviya commited on
Commit
12a78dd
·
1 Parent(s): 77cd070

add listen

Browse files
Files changed (1) hide show
  1. listen.py +31 -17
listen.py CHANGED
@@ -23,21 +23,6 @@ except Exception:
23
  # ---------- Blueprint ----------
24
  listen_bp = Blueprint("listen", __name__)
25
 
26
- # Directories for video, audio, and transcripts (local working paths)
27
- VIDEO_FOLDER = 'static/videos'
28
- AUDIO_FOLDER = 'static/audio'
29
- TRANSCRIPT_FOLDER = 'static/transcripts'
30
-
31
- # Ensure local working dirs exist
32
- os.makedirs(VIDEO_FOLDER, exist_ok=True)
33
- os.makedirs(AUDIO_FOLDER, exist_ok=True)
34
- os.makedirs(TRANSCRIPT_FOLDER, exist_ok=True)
35
-
36
- # ---------------- Cohere configuration (migrated to v2 Chat) ----------------
37
- COHERE_API_KEY = os.getenv("COHERE_API_KEY", "")
38
- COHERE_API_URL = 'https://api.cohere.com/v2/chat'
39
- # ---------------------------------------------------------------------------
40
-
41
  # ---------------------- storage mode helpers ----------------------
42
  def _is_aws_video_mode() -> bool:
43
  """
@@ -70,7 +55,36 @@ def _video_s3_key(filename: str) -> str:
70
  prefix = prefix.strip().strip("/")
71
  return f"{prefix}/{filename}"
72
 
73
- # -------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  # Google Cloud Speech-to-Text Configuration
76
  speech_client = speech.SpeechClient()
@@ -181,7 +195,7 @@ def serve_video(filename):
181
  @listen_bp.route('/upload-video', methods=['POST'])
182
  def upload_video():
183
  """
184
- Local: save to static/videos.
185
  HF/AWS: upload to S3 (no local original).
186
  """
187
  print("Received upload request.")
 
23
  # ---------- Blueprint ----------
24
  listen_bp = Blueprint("listen", __name__)
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  # ---------------------- storage mode helpers ----------------------
27
  def _is_aws_video_mode() -> bool:
28
  """
 
55
  prefix = prefix.strip().strip("/")
56
  return f"{prefix}/{filename}"
57
 
58
+ # ---------- writable working directories ----------
59
+ # Base working dir: /tmp on HF/AWS; local stays under ./static (or override via LISTEN_WORKDIR)
60
+ _BASE_WORKDIR = os.getenv(
61
+ "LISTEN_WORKDIR",
62
+ "/tmp/listen" if _is_aws_video_mode() else os.path.abspath("static")
63
+ )
64
+
65
+ VIDEO_FOLDER = os.path.join(_BASE_WORKDIR, "videos")
66
+ AUDIO_FOLDER = os.path.join(_BASE_WORKDIR, "audio")
67
+ TRANSCRIPT_FOLDER = os.path.join(_BASE_WORKDIR, "transcripts")
68
+
69
+ # Ensure directories exist (with hard fallback to /tmp if needed)
70
+ for _pname in ("videos", "audio", "transcripts"):
71
+ _p = os.path.join(_BASE_WORKDIR, _pname)
72
+ try:
73
+ os.makedirs(_p, exist_ok=True)
74
+ except Exception:
75
+ _fallback_base = "/tmp/listen"
76
+ os.makedirs(os.path.join(_fallback_base, _pname), exist_ok=True)
77
+ if _pname == "videos":
78
+ VIDEO_FOLDER = os.path.join(_fallback_base, "videos")
79
+ elif _pname == "audio":
80
+ AUDIO_FOLDER = os.path.join(_fallback_base, "audio")
81
+ else:
82
+ TRANSCRIPT_FOLDER = os.path.join(_fallback_base, "transcripts")
83
+
84
+ # ---------------- Cohere configuration (migrated to v2 Chat) ----------------
85
+ COHERE_API_KEY = os.getenv("COHERE_API_KEY", "")
86
+ COHERE_API_URL = 'https://api.cohere.com/v2/chat'
87
+ # ---------------------------------------------------------------------------
88
 
89
  # Google Cloud Speech-to-Text Configuration
90
  speech_client = speech.SpeechClient()
 
195
  @listen_bp.route('/upload-video', methods=['POST'])
196
  def upload_video():
197
  """
198
+ Local: save to static/videos or /tmp/listen/videos (depending on mode).
199
  HF/AWS: upload to S3 (no local original).
200
  """
201
  print("Received upload request.")