Update app.py
Browse files
app.py
CHANGED
|
@@ -63,11 +63,16 @@ def search_with_tfidf(query, subtitles):
|
|
| 63 |
best_match_index = np.argmax(cosine_similarities)
|
| 64 |
return subtitles[best_match_index], cosine_similarities[best_match_index]
|
| 65 |
|
| 66 |
-
# Search for Word
|
| 67 |
@st.cache_resource()
|
| 68 |
-
def
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
return '\n'.join(results) if results else "No matching words found."
|
| 72 |
|
| 73 |
# Audio Upload and Processing
|
|
@@ -93,13 +98,13 @@ if uploaded_file:
|
|
| 93 |
# Columns for download options
|
| 94 |
col1, col2 = st.columns(2)
|
| 95 |
with col1:
|
| 96 |
-
st.download_button("Download Subtitles (SRT)", transcribed_text, file_name="subtitles.srt", mime="text/plain", key="srt_download"
|
| 97 |
with col2:
|
| 98 |
-
st.download_button("Download Subtitles (Plain Text)", plain_text, file_name="subtitles.txt", mime="text/plain", key="text_download"
|
| 99 |
|
| 100 |
-
search_word = st.text_input("Search for a word in subtitles (Optional)")
|
| 101 |
if search_word.strip():
|
| 102 |
-
search_result =
|
| 103 |
st.subheader("Word Search Results:")
|
| 104 |
st.write(search_result)
|
| 105 |
|
|
@@ -109,4 +114,4 @@ if uploaded_file:
|
|
| 109 |
st.write(best_match)
|
| 110 |
|
| 111 |
os.remove(temp_audio_path)
|
| 112 |
-
st.success("Process completed successfully!")
|
|
|
|
| 63 |
best_match_index = np.argmax(cosine_similarities)
|
| 64 |
return subtitles[best_match_index], cosine_similarities[best_match_index]
|
| 65 |
|
| 66 |
+
# Search for Word using TF-IDF
|
| 67 |
@st.cache_resource()
|
| 68 |
+
def search_word_with_tfidf(word, subtitles_text):
|
| 69 |
+
documents = subtitles_text.split('\n')
|
| 70 |
+
vectorizer = TfidfVectorizer()
|
| 71 |
+
tfidf_matrix = vectorizer.fit_transform(documents)
|
| 72 |
+
word_vector = vectorizer.transform([word])
|
| 73 |
+
cosine_similarities = cosine_similarity(word_vector, tfidf_matrix).flatten()
|
| 74 |
+
relevant_indices = np.where(cosine_similarities > 0.1)[0]
|
| 75 |
+
results = [documents[i] for i in relevant_indices]
|
| 76 |
return '\n'.join(results) if results else "No matching words found."
|
| 77 |
|
| 78 |
# Audio Upload and Processing
|
|
|
|
| 98 |
# Columns for download options
|
| 99 |
col1, col2 = st.columns(2)
|
| 100 |
with col1:
|
| 101 |
+
st.download_button("Download Subtitles (SRT)", transcribed_text, file_name="subtitles.srt", mime="text/plain", key="srt_download")
|
| 102 |
with col2:
|
| 103 |
+
st.download_button("Download Subtitles (Plain Text)", plain_text, file_name="subtitles.txt", mime="text/plain", key="text_download")
|
| 104 |
|
| 105 |
+
search_word = st.text_input("Search for a word in subtitles using TF-IDF (Optional)")
|
| 106 |
if search_word.strip():
|
| 107 |
+
search_result = search_word_with_tfidf(search_word, transcribed_text)
|
| 108 |
st.subheader("Word Search Results:")
|
| 109 |
st.write(search_result)
|
| 110 |
|
|
|
|
| 114 |
st.write(best_match)
|
| 115 |
|
| 116 |
os.remove(temp_audio_path)
|
| 117 |
+
st.success("Process completed successfully!")
|