Phaneendrabayi commited on
Commit
3992b94
·
verified ·
1 Parent(s): bef8569

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -31,16 +31,21 @@ def load_embedder():
31
 
32
  embedder = load_embedder()
33
 
34
- # Load Pickle Data
35
  @st.cache_resource()
36
- def load_pickle_data():
37
  with open('subtitle_embeddings.pkl', 'rb') as f:
38
  data = pickle.load(f)
39
  if isinstance(data, np.ndarray):
40
  data = data.tolist()
41
- return data
 
 
 
 
 
42
 
43
- subtitle_data = load_pickle_data()
44
 
45
  # Format Time for SRT
46
  def format_time(seconds):
@@ -65,11 +70,6 @@ def transcribe_audio(audio_file):
65
  return "\n".join(subtitles), " ".join(plain_subtitles)
66
 
67
  # Perform Fast Search Using ChromaDB
68
- @st.cache_resource()
69
- def add_to_chromadb(subtitles):
70
- for i, text in enumerate(subtitles):
71
- collection.add(documents=[text], ids=[str(i)])
72
-
73
  def search_with_chromadb(query):
74
  results = collection.query(query_texts=[query], n_results=5)
75
  return results['documents'][0] if results['documents'] else []
@@ -101,7 +101,7 @@ with tab1:
101
  st.text_area("Subtitles (SRT Format)", transcribed_text, height=300)
102
  st.download_button("Download Subtitles (SRT)", transcribed_text, file_name="subtitles.srt", mime="text/plain")
103
  st.download_button("Download Subtitles (Plain Text)", plain_text, file_name="subtitles.txt", mime="text/plain")
104
- add_to_chromadb(transcribed_text.split('\n'))
105
 
106
  with tab2:
107
  st.subheader("Search Subtitles")
 
31
 
32
  embedder = load_embedder()
33
 
34
+ # Load Pickle Data and Add to ChromaDB
35
  @st.cache_resource()
36
+ def load_and_store_pickle_data():
37
  with open('subtitle_embeddings.pkl', 'rb') as f:
38
  data = pickle.load(f)
39
  if isinstance(data, np.ndarray):
40
  data = data.tolist()
41
+
42
+ # Store data into ChromaDB
43
+ for i, item in enumerate(data):
44
+ if isinstance(item, dict) and 'text' in item:
45
+ collection.add(documents=[item['text']], ids=[str(i)])
46
+ return data
47
 
48
+ subtitle_data = load_and_store_pickle_data()
49
 
50
  # Format Time for SRT
51
  def format_time(seconds):
 
70
  return "\n".join(subtitles), " ".join(plain_subtitles)
71
 
72
  # Perform Fast Search Using ChromaDB
 
 
 
 
 
73
  def search_with_chromadb(query):
74
  results = collection.query(query_texts=[query], n_results=5)
75
  return results['documents'][0] if results['documents'] else []
 
101
  st.text_area("Subtitles (SRT Format)", transcribed_text, height=300)
102
  st.download_button("Download Subtitles (SRT)", transcribed_text, file_name="subtitles.srt", mime="text/plain")
103
  st.download_button("Download Subtitles (Plain Text)", plain_text, file_name="subtitles.txt", mime="text/plain")
104
+ collection.add(documents=[plain_text], ids=["audio_transcript"])
105
 
106
  with tab2:
107
  st.subheader("Search Subtitles")