ofermend commited on
Commit
c150a4d
1 Parent(s): fc498dc

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +99 -14
  3. header-image-2.png +3 -0
  4. query.py +4 -5
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ header-image-2.png filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -6,6 +6,77 @@ import requests
6
  import streamlit as st
7
  from PIL import Image
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  def launch_bot():
10
 
11
  if 'cfg' not in st.session_state:
@@ -22,12 +93,18 @@ def launch_bot():
22
  cfg = st.session_state.cfg
23
  vq = st.session_state.vq
24
  st.set_page_config(page_title="Media Demo", layout="wide")
 
 
 
 
 
25
 
26
  # left side content
27
  with st.sidebar:
28
- image = Image.open('Vectara-logo.png')
29
  st.markdown("## Welcome to Media Demo\n\n"
30
- "This demo uses Vectara to find the movie where a quote is from\n\n")
 
31
 
32
  st.markdown("---")
33
  st.markdown(
@@ -37,18 +114,26 @@ def launch_bot():
37
  st.markdown("---")
38
  st.image(image, width=250)
39
 
40
- st.markdown("<center> <h2> Vectara Media Demo</h2> </center>", unsafe_allow_html=True)
41
-
42
- question = st.text_input("Enter your question:")
43
- if st.button("find the match"):
44
- movie_name, match_url = vq.submit_query(question)
45
- video_url, start_time = match_url.split('&t=')
46
- start_time = start_time[:-1] # remove the trailing 's'
47
-
48
- col1, col2, col3 = st.columns([1, 2, 1])
49
- with col2:
50
- st.write(f"Here's a useful video for you: {movie_name}")
51
- st.video(video_url, start_time=int(float(start_time)))
 
 
 
 
 
 
 
 
52
 
53
  if __name__ == "__main__":
54
  launch_bot()
 
6
  import streamlit as st
7
  from PIL import Image
8
 
9
+ def inject_custom_css():
10
+ st.markdown(
11
+ """
12
+ <style>
13
+ @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');
14
+ body {
15
+ font-family: 'Roboto', sans-serif;
16
+ background-color: #f5f5f5;
17
+ color: #333;
18
+ }
19
+ body {
20
+ padding-top: 0px;
21
+ }
22
+ .stApp {
23
+ padding-top: 10px;
24
+ }
25
+ .stButton>button {
26
+ background-color: #4CAF50;
27
+ color: white;
28
+ padding: 10px 24px;
29
+ border: none;
30
+ cursor: pointer;
31
+ border-radius: 4px;
32
+ }
33
+ .stButton>button:hover {
34
+ background-color: #45a049;
35
+ }
36
+ .stTextInput>div>input {
37
+ padding: 10px;
38
+ border-radius: 4px;
39
+ border: 1px solid #ccc;
40
+ font-size: 16px;
41
+ }
42
+ .stTextInput>div>input:focus {
43
+ border-color: #007BFF;
44
+ outline: none;
45
+ box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
46
+ }
47
+ .centered {
48
+ display: flex;
49
+ justify-content: center;
50
+ align-items: center;
51
+ }
52
+ .sidebar .stImage {
53
+ display: flex;
54
+ justify-content: center;
55
+ margin-bottom: 20px;
56
+ }
57
+ .css-1lcbmhc.e1fqkh3o3 { /* This targets the sidebar */
58
+ background-color: #ffffff !important;
59
+ color: #333 !important;
60
+ }
61
+ .css-1d391kg { /* This targets the sidebar headings */
62
+ color: #333 !important;
63
+ }
64
+ .form-container {
65
+ display: flex;
66
+ justify-content: space-between;
67
+ align-items: center;
68
+ }
69
+ .form-container .stTextInput {
70
+ flex: 1;
71
+ }
72
+ .form-container .stButton {
73
+ margin-left: 10px;
74
+ }
75
+ </style>
76
+ """,
77
+ unsafe_allow_html=True
78
+ )
79
+
80
  def launch_bot():
81
 
82
  if 'cfg' not in st.session_state:
 
93
  cfg = st.session_state.cfg
94
  vq = st.session_state.vq
95
  st.set_page_config(page_title="Media Demo", layout="wide")
96
+ inject_custom_css()
97
+
98
+ header_image = Image.open('header-image-2.png')
99
+ cropped_image = header_image.crop((0, 0, header_image.width, 200))
100
+ st.image(cropped_image, use_column_width=True)
101
 
102
  # left side content
103
  with st.sidebar:
104
+ image = Image.open('vectara-logo.png')
105
  st.markdown("## Welcome to Media Demo\n\n"
106
+ "This demo uses Vectara to find the movie where a quote is from\n\n"
107
+ "Covers movies from this [playlist](https://www.youtube.com/playlist?list=PLHPTxTxtC0ibVZrT2_WKWUl2SAxsKuKwx) of free movies")
108
 
109
  st.markdown("---")
110
  st.markdown(
 
114
  st.markdown("---")
115
  st.image(image, width=250)
116
 
117
+ st.markdown("<center> <h3>\"Find that movie\" demo</h3> </center>", unsafe_allow_html=True)
118
+
119
+ st.markdown('<div class="form-container">', unsafe_allow_html=True)
120
+ with st.form(key='my_form'):
121
+ question = st.text_input("Enter your movie quote:")
122
+ submit_button = st.form_submit_button(label='Find the Match')
123
+ st.markdown('</div>', unsafe_allow_html=True)
124
+
125
+ if submit_button:
126
+ movie_name, match_url, score = vq.submit_query(question)
127
+ if score < 0.7:
128
+ st.write("Sorry, I couldn't find a match for that quote. Please try another one.")
129
+ else:
130
+ video_url, start_time = match_url.split('&t=')
131
+ start_time = start_time[:-1] # remove the trailing 's'
132
+
133
+ col1, col2, col3 = st.columns([1, 2, 1])
134
+ with col2:
135
+ st.write(f"Here's a useful video for you: {movie_name}")
136
+ st.video(video_url, start_time=int(float(start_time)))
137
 
138
  if __name__ == "__main__":
139
  launch_bot()
header-image-2.png ADDED

Git LFS Details

  • SHA256: b5233cee2669882b9e39e3ac8514b3ba26b3bf5b5600f830f1d37212c8d0eda5
  • Pointer size: 132 Bytes
  • Size of remote file: 4 MB
query.py CHANGED
@@ -27,10 +27,7 @@ class VectaraQuery():
27
  'start_tag': "%START_SNIPPET%",
28
  'end_tag': "%END_SNIPPET%",
29
  },
30
- 'rerankingConfig':
31
- {
32
- 'rerankerId': 272725719,
33
- },
34
  }
35
  ]
36
  }
@@ -59,6 +56,7 @@ class VectaraQuery():
59
  responses = res['responseSet'][0]['response'][:top_k]
60
  documents = res['responseSet'][0]['document']
61
 
 
62
  metadatas = []
63
  for x in responses:
64
  md = {m["name"]: m["value"] for m in x["metadata"]}
@@ -69,6 +67,7 @@ class VectaraQuery():
69
 
70
  movie_title = metadatas[0].get("doc_title", None)
71
  snippet_url = metadatas[0].get("url", None)
 
72
 
73
- return movie_title, snippet_url
74
 
 
27
  'start_tag': "%START_SNIPPET%",
28
  'end_tag': "%END_SNIPPET%",
29
  },
30
+ 'rerankingConfig': { 'rerankerId': 272725719 }
 
 
 
31
  }
32
  ]
33
  }
 
56
  responses = res['responseSet'][0]['response'][:top_k]
57
  documents = res['responseSet'][0]['document']
58
 
59
+
60
  metadatas = []
61
  for x in responses:
62
  md = {m["name"]: m["value"] for m in x["metadata"]}
 
67
 
68
  movie_title = metadatas[0].get("doc_title", None)
69
  snippet_url = metadatas[0].get("url", None)
70
+ score = responses[0]["score"]
71
 
72
+ return movie_title, snippet_url, score
73