Spaces:
Running
Running
| import streamlit as st | |
| from meta_ai_api import MetaAI | |
| # 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("INSPECT THE REPORT - SOURCES"): | |
| for source in sources: | |
| st.markdown(f"[{source['title']}]({source['link']})", unsafe_allow_html=True) | |
| else: | |
| st.write("No sources available.") | |
| # ---------------------------------------------------------------------------- # | |
| # Main Function | |
| # ---------------------------------------------------------------------------- # | |
| def main(): | |
| 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 Full Response"): | |
| display_sources(response.get('sources', [])) | |
| if __name__ == "__main__": | |
| main() | |