-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_app.py
61 lines (47 loc) · 2.06 KB
/
search_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import streamlit as st
from elasticsearch import Elasticsearch
import configparser
config = configparser.ConfigParser()
config.read('example.ini')
# Connect to Elasticsearch
es = Elasticsearch(cloud_id=config['DEFAULT']['cloud_id'],
api_key=(config['DEFAULT']['apikey_id'], config['DEFAULT']['apikey_key']))
def search_movies(query, index_name="movie_embeddings", size=5):
"""
Function to search for movies in Elasticsearch index.
"""
body = {
"query": {
"multi_match": {
"query": query,
"fields": ["Series_Title", "Overview", "Director", "Star1", "Star2", "Star3", "Star4", "Genre"]
}
}
}
response = es.search(index=index_name, body=body, size=size)
return response["hits"]["hits"]
def main():
st.title("Movie Search Engine")
# Input field for search query
query = st.text_input("Enter movie title, actor, genre, or any other keyword")
if st.button("Search"):
# Search for movies
results = search_movies(query)
if results:
st.subheader("Search Results:")
for hit in results:
st.markdown('---')
movie_title = hit["_source"]["Series_Title"]
st.write(f"**{movie_title}**")
# Display poster image as a small square box
st.image(hit['_source']['Poster_Link'], width=100)
fields = ['Released_Year', 'Runtime', 'Genre', 'IMDB_Rating', 'Director', 'Overview']
for field in fields:
if field in hit['_source'] and hit['_source'][field]:
st.write(f"**{field.replace('_', ' ')}:** {hit['_source'][field]}")
if 'Certificate' in hit['_source'] and hit['_source']['Certificate'] and hit['_source']['Certificate'] != 'NotApp':
st.write(f"**Certificate:** {hit['_source']['Certificate']}")
else:
st.write("No results found.")
if __name__ == "__main__":
main()