File size: 1,976 Bytes
b644746
 
 
eef03e6
 
 
b644746
 
 
 
 
 
 
 
 
 
 
 
eef03e6
b644746
 
 
 
 
 
 
 
 
 
 
 
 
eef03e6
 
b644746
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests

secret_key = st.secrets["secret_key"]

def call_api(url, keyword, wl_key, description_narrative):
    api_url = "https://wl-quality-rating.eastus2.inference.ml.azure.com/score"
    
    payload = {
        "url": url,
        "keyword": keyword,
        "wl_key": wl_key,
        "description_narrative": description_narrative
    }
    
    headers = {
        "Content-Type": "application/json",
        "User-Agent": "insomnia/8.2.0",
        "Authorization": "Bearer " + secret_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:")
wordlift_key = st.text_input("Enter the WordLift Key:")

# Button to execute analysis
if st.button("Analyze"):
    if url and query and narrative and wordlift_key:
        response = call_api(url, query, wordlift_key, narrative)
        
        # Display JSON response
        st.json(response)
        
        # Additional visual representation & analysis based on API response.
        # You will need to adjust this part based on the actual structure of the API response.
        try:
            M = response["analyze"][0]["M"]
            T = response["analyze"][0]["T"]

            # Display traffic light system
            if M == 2 and T == 2:
                st.write("🟒 Content is highly relevant and trustworthy")
            elif M == 1 or T == 1:
                st.write("🟑 Content is partly relevant/helpful")
            else:
                st.write("πŸ”΄ Content is not relevant")
        except KeyError:
            st.error("Invalid API response format. Unable to extract M and T values.")
    else:
        st.warning("Please provide all inputs!")