Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ from sklearn.feature_extraction.text import TfidfVectorizer
|
|
| 9 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 10 |
|
| 11 |
# App Title and Config
|
| 12 |
-
st.set_page_config(page_title="Subtitle Search Engine"
|
| 13 |
st.title("🎬 Subtitle Search Engine")
|
| 14 |
st.markdown("Upload an audio file to generate subtitles and search within subtitles using AI.")
|
| 15 |
|
|
@@ -60,7 +60,7 @@ def search_word_with_tfidf(word):
|
|
| 60 |
tfidf_matrix = vectorizer.fit_transform([word] + data_texts)
|
| 61 |
cosine_sim = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:])
|
| 62 |
top_indices = np.argsort(cosine_sim[0])[::-1][:5]
|
| 63 |
-
top_results = [subtitle_data[i].get('text', 'No Match Found')
|
| 64 |
return top_results
|
| 65 |
|
| 66 |
# UI Layout with Tabs
|
|
@@ -96,7 +96,7 @@ with tab2:
|
|
| 96 |
top_results = search_word_with_tfidf(search_word)
|
| 97 |
st.write("### Top 5 Search Results")
|
| 98 |
for result in top_results:
|
| 99 |
-
st.info(
|
| 100 |
|
| 101 |
os.remove(temp_audio_path)
|
| 102 |
st.success("Process completed successfully!")
|
|
|
|
| 9 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 10 |
|
| 11 |
# App Title and Config
|
| 12 |
+
st.set_page_config(page_title="Subtitle Search Engine")
|
| 13 |
st.title("🎬 Subtitle Search Engine")
|
| 14 |
st.markdown("Upload an audio file to generate subtitles and search within subtitles using AI.")
|
| 15 |
|
|
|
|
| 60 |
tfidf_matrix = vectorizer.fit_transform([word] + data_texts)
|
| 61 |
cosine_sim = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:])
|
| 62 |
top_indices = np.argsort(cosine_sim[0])[::-1][:5]
|
| 63 |
+
top_results = [subtitle_data[i].get('text', 'No Match Found') if isinstance(subtitle_data[i], dict) else str(subtitle_data[i]) for i in top_indices]
|
| 64 |
return top_results
|
| 65 |
|
| 66 |
# UI Layout with Tabs
|
|
|
|
| 96 |
top_results = search_word_with_tfidf(search_word)
|
| 97 |
st.write("### Top 5 Search Results")
|
| 98 |
for result in top_results:
|
| 99 |
+
st.info(result)
|
| 100 |
|
| 101 |
os.remove(temp_audio_path)
|
| 102 |
st.success("Process completed successfully!")
|