File size: 2,849 Bytes
da9233c
 
 
 
e93ab3a
da9233c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e93ab3a
da9233c
 
e93ab3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da9233c
 
 
 
 
 
4c28da1
e93ab3a
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import streamlit as st
from sentence_transformers import SentenceTransformer
import weaviate
import base64
import requests

bg_color = "#343434"  # Set your desired background color
st.markdown(
    f"""
    <style>
        body {{
            background-color: {bg_color};
        }}
    </style>
    """,
    unsafe_allow_html=True,
)

st.sidebar.header("Try your query on the following: ")
topics = ["Character", "Compassion", "Culture", "Devotion", "Dharma", "Discipline", "Education", "Festivals",
          "Gayatri Devi", "God", "Gratitude", "Guru", "Human Values", "India", "Love", "Meditation", "Mind",
          "Money", "Namasmarana", "Parents", "Pleasure and Pain", "Practice", "Sacrifice", "Sadhana", "Senses",
          "Service", "Time"]
for topic in topics:
    st.sidebar.write(topic)

# Set up the layout using columns
col1, col2 = st.columns([2, 1])

# Left column: Title, Search Bar, and Search Button
with col1:
    st.header('Harmony Hub: Connecting with Spiritual Messages for Inner Peace')
    query_text = st.text_input('Enter your query:')
    search_button = st.button('Search')

    # Display the search results
    if search_button:
        try:
            # Encode the query text
            embedder = SentenceTransformer('all-MiniLM-L6-v2')
            query_embeddings = embedder.encode([query_text], convert_to_tensor=True)
            query_vector = query_embeddings.flatten().tolist()

            # Perform Weaviate search
            client = weaviate.connect_to_embedded(
                persistence_data_path='Transcript Data'
            )
            info = client.collections.get("Audio")
            query_vector = query_vector
            response = info.query.near_vector(
                near_vector=query_vector,
                limit=3,
                return_properties=["audio", "transcript"]
            )

            result = {'audio': '', 'transcript': ''}
            if response.objects:
                obj = response.objects[0]
                base64_audio = obj.properties.get("audio", "")
                transcript = obj.properties.get("transcript", "")

                if base64_audio:
                    decoded_audio = base64.b64decode(base64_audio.encode("utf-8"))
                    audio_data = base64.b64encode(decoded_audio).decode("utf-8")
                    result['audio'] = audio_data

                result['transcript'] = transcript

            # Display audio player and transcript
            st.audio(base64.b64decode(result['audio']), format='audio/mp3')
            st.write('Transcript:', result['transcript'])

        except Exception as e:
            st.write('Error:', str(e))

# Right column: Image
with col2:
    image_path = 'Swami1.jpeg'
    st.image(image_path, caption='Conscience is our real power, strength, and awareness.', use_column_width=True)