LRU1 commited on
Commit
08eb9a4
Β·
1 Parent(s): 9c13b61

add replicate service

Browse files
app.py CHANGED
@@ -3,9 +3,9 @@ from pathlib import Path
3
  import tempfile, subprocess, threading, queue
4
  import textwrap
5
 
6
- st.set_page_config(page_title="Lec2Note2 – Lecture-to-Notes", layout="wide")
7
 
8
- st.title("πŸ“ Lec2Note2 – Automatic Lecture Notes Generator")
9
 
10
  st.markdown(
11
  textwrap.dedent(
 
3
  import tempfile, subprocess, threading, queue
4
  import textwrap
5
 
6
+ st.set_page_config(page_title="Lec2Note – Lecture-to-Notes", layout="wide")
7
 
8
+ st.title("πŸ“ Lec2Note – Automatic Lecture Notes Generator")
9
 
10
  st.markdown(
11
  textwrap.dedent(
lec2note/ingestion/__pycache__/whisper_runner.cpython-310.pyc CHANGED
Binary files a/lec2note/ingestion/__pycache__/whisper_runner.cpython-310.pyc and b/lec2note/ingestion/__pycache__/whisper_runner.cpython-310.pyc differ
 
lec2note/ingestion/whisper_runner.py CHANGED
@@ -10,8 +10,9 @@ from typing import List, Dict, Optional, Any
10
 
11
  import torch, json, os
12
  from whisper import load_model # type: ignore
13
- from openai import OpenAI
14
-
 
15
  __all__ = ["WhisperRunner"]
16
 
17
 
@@ -40,22 +41,43 @@ class WhisperRunner: # noqa: D101
40
 
41
  logger.info("[Whisper] transcribing %s (local)", audio_path.name)
42
  result = model.transcribe(str(audio_path), language=lang)
 
43
  else:
44
  # remote API mode
45
- api_base = os.getenv("AIHUB_API_BASE")
46
- api_key = os.getenv("AIHUB_API_KEY")
47
  if not api_key:
48
- raise EnvironmentError("AIHUB_API_KEY not set")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
- client = OpenAI(api_key=api_key, base_url=api_base)
51
- logger.info("[Whisper] uploading %s to API (whisper-large-v3)", audio_path.name)
52
- with audio_path.open("rb") as f:
53
- resp = client.audio.transcriptions.create(model="whisper-large-v3", file=f, language=lang)
54
- # resp.text contains full text, but we need segments; assume API returns segments list if 'json' format
55
- segments = resp.segments if hasattr(resp, "segments") else [{"start": 0.0, "end": 0.0, "text": resp.text}]
56
- result = {"segments": segments}
57
 
58
- # convert to our schema
59
  logger.info("[Whisper] got %d segments", len(segments))
60
  results = [
61
  {
 
10
 
11
  import torch, json, os
12
  from whisper import load_model # type: ignore
13
+ import replicate
14
+ import httpx
15
+ import time
16
  __all__ = ["WhisperRunner"]
17
 
18
 
 
41
 
42
  logger.info("[Whisper] transcribing %s (local)", audio_path.name)
43
  result = model.transcribe(str(audio_path), language=lang)
44
+ segments = result.get("segments", [])
45
  else:
46
  # remote API mode
47
+ api_key = os.getenv("REPLICATE_API_TOKEN")
 
48
  if not api_key:
49
+ raise EnvironmentError("REPLICATE_API_TOKEN not set")
50
+ logger.info("[Whisper] uploading %s to Replicate (whisper-large-v3)", audio_path.name)
51
+
52
+ client = replicate.Client(
53
+ api_token=api_key,
54
+ timeout=httpx.Timeout(60.0, connect=60.0, read=60.0),
55
+ )
56
+
57
+ version = "8099696689d249cf8b122d833c36ac3f75505c666a395ca40ef26f68e7d3d16e" # whisper-large-v3
58
+ prediction = client.predictions.create(
59
+ version=version,
60
+ input={
61
+ "audio": open(audio_path, "rb"),
62
+ "language": lang,
63
+ },
64
+ )
65
+
66
+ poll_interval = float(os.getenv("REPLICATE_POLL_INTERVAL", "5"))
67
+ while prediction.status not in ("succeeded", "failed", "canceled"):
68
+ time.sleep(poll_interval)
69
+ prediction.reload()
70
+ logger.info("[Whisper] Replicate prediction status: %s", prediction.status)
71
+
72
+ if prediction.status != "succeeded":
73
+ raise RuntimeError(f"Replicate failed: {prediction.error}")
74
 
75
+ resp = prediction.output
76
+ segments = resp["segments"] if isinstance(resp, dict) and "segments" in resp else [
77
+ {"start": 0.0, "end": 0.0, "text": resp.get("text", "")}
78
+ ]
 
 
 
79
 
80
+ # convert to our schema (works for both modes)
81
  logger.info("[Whisper] got %d segments", len(segments))
82
  results = [
83
  {
lec2note/segmentation/__pycache__/chunk_merger.cpython-310.pyc CHANGED
Binary files a/lec2note/segmentation/__pycache__/chunk_merger.cpython-310.pyc and b/lec2note/segmentation/__pycache__/chunk_merger.cpython-310.pyc differ
 
lec2note/segmentation/__pycache__/semantic_segmenter.cpython-310.pyc CHANGED
Binary files a/lec2note/segmentation/__pycache__/semantic_segmenter.cpython-310.pyc and b/lec2note/segmentation/__pycache__/semantic_segmenter.cpython-310.pyc differ
 
lec2note/segmentation/__pycache__/visual_merger.cpython-310.pyc CHANGED
Binary files a/lec2note/segmentation/__pycache__/visual_merger.cpython-310.pyc and b/lec2note/segmentation/__pycache__/visual_merger.cpython-310.pyc differ
 
lec2note/utils/logging_config.py CHANGED
@@ -1,4 +1,4 @@
1
- """Global logging configuration for Lec2Note2.
2
 
3
  Call ``setup_logging()`` once at program start to enable consistent log format.
4
  """
 
1
+ """Global logging configuration for Lec2Note.
2
 
3
  Call ``setup_logging()`` once at program start to enable consistent log format.
4
  """
requirements.txt CHANGED
@@ -19,4 +19,5 @@ scikit-image==0.25.1
19
  imagehash==4.3.1
20
  tenacity==8.2.3
21
  streamlit>=1.35
 
22
  tqdm
 
19
  imagehash==4.3.1
20
  tenacity==8.2.3
21
  streamlit>=1.35
22
+ replicate
23
  tqdm