Eurovoc / app.py
scampion's picture
update
9d09431
raw
history blame
1.77 kB
import streamlit as st
import requests
st.title('πŸ‡ͺπŸ‡Ί 🏷️ Eurovoc Tagger')
st.write("This page in a demonstration interface of the Eurovoc Tagger API. It allows you to test how tag a text with Eurovoc concepts.")
q = st.text_area('Enter a text:', 'The Union condemns the continuing grave human rights violations by the Myanmar armed forces, including torture, sexual and gender-based violence, the persecution of civil society actors, human rights defenders and journalists, and attacks on the civilian population, including ethnic and religious minorities.',
height=200, max_chars=5000)
API_URL_EN = "https://lcs3f8pwcn03ri5q.eu-west-1.aws.endpoints.huggingface.cloud"
API_URL_EU = "https://a933b0hcdb86onmt.eu-west-1.aws.endpoints.huggingface.cloud"
apis = {"Multilingual πŸ‡ͺπŸ‡Ί": API_URL_EU,
"English πŸ‡¬πŸ‡§ (Deprecated) ": API_URL_EU
}
k = st.slider('How many tags', 1, 20, 5)
t = st.slider("Threshold", 0.0, 1.0, 0.1)
lang = st.selectbox("Language", apis.keys())
hf_token = st.secrets["HF_TOKEN"]
headers = {
"Authorization": f"Bearer {hf_token}",
"Content-Type": "application/json"
}
def query(payload):
response = requests.post(apis[lang], headers=headers, json=payload)
assert response.status_code == 200, response.text
return response.json()
payload = {
"inputs": q,
"topk": k,
"threshold": t
}
st.markdown("---")
with st.spinner("Request in progress, please wait..."):
try:
print(payload)
r = query(payload)
except Exception as e:
st.error(e)
st.write("The server is probably waking up, so please wait a minute and reload the page.")
st.stop()
st.subheader("Results")
st.dataframe(r['results'], width=1000, height=600)