import streamlit as st import requests, json secret_key = st.secrets["secret_key"] wl_key = st.secrets["wl_key"] def call_api(url, keyword, wl_key, description_narrative): api_url = "https://api.wordlift.io/quality-rating/score" payload = { "url": url, "keyword": keyword, "wl_key": wl_key, "description_narrative": description_narrative, "text": text } headers = { "Content-Type": "application/json", "User-Agent": "insomnia/8.2.0", "Authorization": "Key " + wl_key } response = requests.request("POST", api_url, json=payload, headers=headers) return response.json() # assuming API responds with JSON # User inputs url = st.text_input("Enter the URL of the webpage:") query = st.text_input("Enter the query the content aims at ranking for:") narrative = st.text_area("Enter the descriptive narrative of the searcher:") text = st.text_input("Enter the text to be analyzed (as alternative to the URL):") # Button to execute analysis if st.button("Analyze"): if (url or text) and query and narrative and wl_key: response = call_api(url, query, wl_key, narrative) # Display JSON response st.json(response) try: # Check if `response["analyze"]` is a string and parse it if true analyze_data = response["analyze"] if isinstance(analyze_data, str): analyze_data = json.loads(analyze_data) # Extract M and T values M = analyze_data[0]["M"] T = analyze_data[0]["T"] # Display traffic light system if M == 2 and T == 2: st.markdown("