File size: 2,279 Bytes
645bb63
 
ed5a50b
645bb63
 
 
 
8668335
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
645bb63
 
 
 
 
e958e6a
ed5a50b
 
 
 
 
 
e958e6a
 
645bb63
8668335
 
 
 
 
645bb63
bc304a6
 
 
 
ed5a50b
bc304a6
 
 
ed5a50b
bc304a6
 
 
 
645bb63
 
 
 
 
 
 
 
8668335
 
62435e7
e958e6a
ed5a50b
ebcd7c3
 
8668335
645bb63
62435e7
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
import streamlit as st
from meta_ai_api import MetaAI
from urllib.parse import urlparse

# Initialize Meta AI API
ai = MetaAI()

PAGE_CONFIG = {
    "page_title": "Meta AI Query Analysis - a Free SEO Tool by WordLift",
    "page_icon": "img/fav-ico.png",
    "layout": "centered"
}

def local_css(file_name):
    with open(file_name) as f:
        st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)


st.set_page_config(**PAGE_CONFIG)

local_css("style.css")


def fetch_response(query):
    response = ai.prompt(message=query)
    return response

def display_sources(sources):
    if sources:
        with st.expander("Show Sources"):
            for source in sources:
                # Parse the domain from the URL
                domain = urlparse(source['link']).netloc
                # Format and display the domain and title
                st.markdown(f"- **{domain}**: [{source['title']}]({source['link']})", unsafe_allow_html=True)
    else:
        st.write("No sources available.")

# ---------------------------------------------------------------------------- #
# Main Function
# ---------------------------------------------------------------------------- #


def main():
    # Path to the image
    image_path = 'img/meta-ai-logo.webp'  # Replace with your image's filename and extension

    # Create two columns
    col1, col2 = st.columns([1, 2])  # Adjust the ratio as needed for your layout

    # Use the first column to display the image
    with col1:
        st.image(image_path, width=60)

    # Use the second column to display the title and other content
    with col2:
        st.title("Meta AI SEO Tool")    

    # User input
    user_query = st.text_area("Enter your query:", height=150)
    submit_button = st.button("Analyze Query")

    if submit_button and user_query:
        # Fetching response from Meta AI
        response = fetch_response(user_query)

        st.write(response.get('message', 'No response message.'))
        
        # Display the AI response in a collapsible section
        with st.expander("Show Sources"):
            # Display sources with clickable links in a collapsible section
            display_sources(response.get('sources', []))
                    
if __name__ == "__main__":
    main()