Spaces:
Running
Running
app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
def call_api(url, keyword, wl_key, description_narrative, secret_key):
|
| 5 |
+
api_url = "https://wl-quality-rating.eastus2.inference.ml.azure.com/score"
|
| 6 |
+
|
| 7 |
+
payload = {
|
| 8 |
+
"url": url,
|
| 9 |
+
"keyword": keyword,
|
| 10 |
+
"wl_key": wl_key,
|
| 11 |
+
"description_narrative": description_narrative
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
headers = {
|
| 15 |
+
"Content-Type": "application/json",
|
| 16 |
+
"User-Agent": "insomnia/8.2.0",
|
| 17 |
+
"Authorization": "Bearer " + secret_key
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
response = requests.request("POST", api_url, json=payload, headers=headers)
|
| 21 |
+
return response.json() # assuming API responds with JSON
|
| 22 |
+
|
| 23 |
+
# User inputs
|
| 24 |
+
url = st.text_input("Enter the URL of the webpage:")
|
| 25 |
+
query = st.text_input("Enter the query the content aims at ranking for:")
|
| 26 |
+
narrative = st.text_area("Enter the descriptive narrative of the searcher:")
|
| 27 |
+
wordlift_key = st.text_input("Enter the WordLift Key:")
|
| 28 |
+
|
| 29 |
+
# Button to execute analysis
|
| 30 |
+
if st.button("Analyze"):
|
| 31 |
+
if url and query and narrative and wordlift_key and secret_key:
|
| 32 |
+
response = call_api(url, query, wordlift_key, narrative, secret_key)
|
| 33 |
+
|
| 34 |
+
# Display JSON response
|
| 35 |
+
st.json(response)
|
| 36 |
+
|
| 37 |
+
# Additional visual representation & analysis based on API response.
|
| 38 |
+
# You will need to adjust this part based on the actual structure of the API response.
|
| 39 |
+
try:
|
| 40 |
+
M = response["analyze"][0]["M"]
|
| 41 |
+
T = response["analyze"][0]["T"]
|
| 42 |
+
|
| 43 |
+
# Display traffic light system
|
| 44 |
+
if M == 2 and T == 2:
|
| 45 |
+
st.write("π’ Content is highly relevant and trustworthy")
|
| 46 |
+
elif M == 1 or T == 1:
|
| 47 |
+
st.write("π‘ Content is partly relevant/helpful")
|
| 48 |
+
else:
|
| 49 |
+
st.write("π΄ Content is not relevant")
|
| 50 |
+
except KeyError:
|
| 51 |
+
st.error("Invalid API response format. Unable to extract M and T values.")
|
| 52 |
+
else:
|
| 53 |
+
st.warning("Please provide all inputs!")
|
| 54 |
+
|