File size: 1,869 Bytes
893c5d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from omegaconf import OmegaConf
from query import VectaraQuery
import os
import requests

import streamlit as st
from PIL import Image

def launch_bot():
    
    if 'cfg' not in st.session_state:
        cfg = OmegaConf.create({
            'customer_id': str(os.environ['VECTARA_CUSTOMER_ID']),
            'corpus_id': str(os.environ['VECTARA_CORPUS_ID']),
            'api_key': str(os.environ['VECTARA_API_KEY']),
            'streaming': False
        })
        st.session_state.cfg = cfg
        st.session_state.vq = VectaraQuery(cfg.api_key, cfg.customer_id, [cfg.corpus_id], 
                                           "vectara-summary-ext-24-05-large")

    cfg = st.session_state.cfg
    vq = st.session_state.vq
    st.set_page_config(page_title="Media Demo", layout="wide")

    # left side content
    with st.sidebar:
        image = Image.open('Vectara-logo.png')
        st.markdown("## Welcome to Media Demo\n\n"
                    "This demo uses Vectara to find the movie where a quote is from\n\n")

        st.markdown("---")
        st.markdown(
            "## How this works?\n"
            "This app was built with [Vectara](https://vectara.com).\n"
        )
        st.markdown("---")
        st.image(image, width=250)

    st.markdown("<center> <h2> Vectara Media Demo</h2> </center>", unsafe_allow_html=True)
    
    question = st.text_input("Enter your question:")
    if st.button("find the match"):
        movie_name, match_url = vq.submit_query(question)
        video_url, start_time = match_url.split('&t=')
        start_time = start_time[:-1]   # remove the trailing 's'

        col1, col2, col3 = st.columns([1, 2, 1])
        with col2:
            st.write(f"Here's a useful video for you: {movie_name}")
            st.video(video_url, start_time=int(float(start_time)))

if __name__ == "__main__":
    launch_bot()