Phaneendrabayi commited on
Commit
cc7a7ee
·
verified ·
1 Parent(s): 44c78e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -68,12 +68,19 @@ def transcribe_audio(audio_file):
68
  plain_subtitles.append(text)
69
  return "\n".join(subtitles), " ".join(plain_subtitles)
70
 
71
- # Perform Search Using ChromaDB
72
  def search_with_chromadb(query):
73
- results = collection.query(query_texts=[query], n_results=5)
 
74
  results_from_chroma = results['documents'][0] if results['documents'] else []
75
- results_from_pickle = [item['text'] for item in subtitle_data if isinstance(item, dict) and 'text' in item and query.lower() in item['text'].lower()]
76
- return results_from_chroma[:5], results_from_pickle[:5]
 
 
 
 
 
 
77
 
78
  # UI Layout with Tabs
79
  tab1, tab2 = st.tabs(["Upload & Generate Subtitles", "Search Subtitles"])
@@ -108,11 +115,11 @@ with tab2:
108
  st.subheader("Search Subtitles")
109
  search_word = st.text_input("Search for a word using ChromaDB")
110
  if search_word.strip():
111
- top_results_chroma, top_results_pickle = search_with_chromadb(search_word)
112
-
113
  st.write("### Top 5 Search Results from Transcribed Text & Pickle Data")
114
- if not top_results_chroma and not top_results_pickle:
115
  st.warning("No results found.")
116
  else:
117
- for result in top_results_chroma + top_results_pickle:
118
  st.info(result) if isinstance(result, str) else st.info(str(result))
 
68
  plain_subtitles.append(text)
69
  return "\n".join(subtitles), " ".join(plain_subtitles)
70
 
71
+ # Perform Search Using ChromaDB and Pickle Data
72
  def search_with_chromadb(query):
73
+ query_embedding = embedder.encode([query]).tolist()
74
+ results = collection.query(query_embeddings=query_embedding, n_results=5)
75
  results_from_chroma = results['documents'][0] if results['documents'] else []
76
+
77
+ results_from_pickle = []
78
+ for item in subtitle_data:
79
+ if isinstance(item, dict) and 'text' in item and query.lower() in item['text'].lower():
80
+ results_from_pickle.append(item['text'])
81
+
82
+ combined_results = results_from_chroma[:5] + results_from_pickle[:5]
83
+ return combined_results[:5]
84
 
85
  # UI Layout with Tabs
86
  tab1, tab2 = st.tabs(["Upload & Generate Subtitles", "Search Subtitles"])
 
115
  st.subheader("Search Subtitles")
116
  search_word = st.text_input("Search for a word using ChromaDB")
117
  if search_word.strip():
118
+ top_results = search_with_chromadb(search_word)
119
+
120
  st.write("### Top 5 Search Results from Transcribed Text & Pickle Data")
121
+ if not top_results:
122
  st.warning("No results found.")
123
  else:
124
+ for result in top_results:
125
  st.info(result) if isinstance(result, str) else st.info(str(result))